t2v / play2-auth

Play2.x Authentication and Authorization module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom login with json

anssirantanen opened this issue · comments

Hi i have playframework project and i need to implement authorization for it.
I have copied basic example structure and experimented with it, so far i havent found answer for my problem. I have predefined specs for handling requests and results.
Login controller takes in username and account in json format after that code will authenticate posted username and will return acount object if password matches (just like in basic example). After that problem arises. I have no idea how to offer authentication cookie as response. so far i have tried to use
gotoLoginSucceeded method but because my lack of knowledge i haven't configured StartNewSession and it will throw Assertionerror (as it should). Every example returns webpage in controller, but my specs forces frontend and back end to be separated so i cant redirect as response. How i should send the cookie in this case?

Default implementation use cookie.
However you can change this behavior by creating custom TokenAccessor.

There is an example of HTTP Basic authentication.
https://github.com/t2v/play2-auth/blob/09a08e2877df34b16afe032a0a05450bcf34ee03/sample/app/controllers/basic/BasicAuthTokenAccessor.scala
(It does not add auth token into response, your TokenAccessor can add auth token into response header)