Setting cookie with spray

How would I save the "secret token" as a cookie before redirecting so that I can retrieve it later?


@Mustafa Simav's answer is correct. Everything strangely started working when I cleaned my project (deleted sbt generated files)

Answers


First of all, I don't now details of OAuth so I am not sure whether it is good idea to store token on cookie or not. However if you want to store and retrieve cookie with spray, you can do it like this:

val routes =
  path("redirect") {
    setCookies(HttpCookie("random_token", random_token)) {
      redirect("twitter.com/authorize", Found)
    }
  } ~
  path("get-cookie") {
    parameters('token) { token =>
      optionalCookie("random_token") {
        case Some(random_token) if random_token == token => complete("OK")
        case _ => complete("Error", BadRequest)
      }
    }
  }

PS: Don't forget to concatenate routes with ~


Need Your Help

Same delegates with different params in TPL Dataflow blocks

vb.net delegates task-parallel-library tpl-dataflow addressof

My TPL Dataflow pipeline uses multiple same blocks, the only difference is each of them uses it's personal proxy to send http requests. So WebProxy here is a parameter. I act like this to create them

how to remove symbol and do math

objective-c uitextfield

I have a simple app which insert data and should do the math, but here is the problem. I USE UITextFiled to insert data (prices) into UILabels, but my data includes dollar sign, and when I use this...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.