spray / spray

A suite of scala libraries for building and consuming RESTful web services on top of Akka: lightweight, asynchronous, non-blocking, actor-based, testable
http://spray.io
Other
2.51k stars 566 forks source link

Authorization in httpRequest #55

Closed jmolina4 closed 13 years ago

jmolina4 commented 13 years ago

Hello!

I'm trying to do a test in my project that uses a Rest Interface with authentication. To do the test, I define some interfaces and then I try to connect and it fails because I don't introduce user and password in httpRequest() . My code is the next:

val mediaType =text/javascript

val expected = """ { "message":"It contains the collection of identifiers of the corpus in the system" } """

  testService(HttpRequest(GET, "/corpus", headers = List(`Accept`(mediaType),`Authorization`(httpCredentials)))) {
    mapService
  }.response.content.as[String] must be(Right(pretty(render(parse(expected)))))

So, I know that I have to specify httpCredentials but I don't know how. If anyone can explain me how can I do it, I would be so grateful.

Thank you!

sirthias commented 13 years ago

Just use the header

`Authorization`(BasicHttpCredentials(username = "bob", password = "123xyz"))

Please use the mailing list for any follow-up and all other questions regarding spray that you might have..

Cheers and happy spraying, Mathias


mathias@spray.cc http://www.spray.cc

On 04.11.2011, at 19:35, jamosa wrote:

Hello!

I'm trying to do a test in my project that uses a Rest Interface with authentication. To do the test, I define some interfaces and then I try to connect and it fails because I don't introduce user and password in httpRequest() . My code is the next:

val mediaType =text/javascript

val expected = """ { "message":"It contains the collection of identifiers of the corpus in the system" } """

 testService(HttpRequest(GET, "/corpus", headers = List(`Accept`(mediaType),`Authorization`(httpCredentials)))) {
   mapService
 }.response.content.as[String] must be(Right(pretty(render(parse(expected)))))

So, I know that I have to specify httpCredentials but I don't know how. If anyone can explain me how can I do it, I would be so grateful.

Thank you!


Reply to this email directly or view it on GitHub: https://github.com/spray/spray/issues/55

jmolina4 commented 13 years ago

Thank you!