spring - Token based authentication for user and separate module -
i have 2 scenarios want implement token based authentication:
i want implement token based authentication when user logs in. i.e.. based on username , password , user should token , token should used every request.
i have separate independent module has id , secret key. has communicate server in specific interval. want implement token based authentication module also.
in both cases token should have these properties:
- it should in payload.
- it should have timeout period
- when token expires server should provide new token,if session not expired else should logout.
is oauth 2.0 right choice? if other approach better, please tell me. should solve problem? best place put token in request -payload or header? , why?
oauth 2.0 choice requirements mentioned: timeout period , refresh-ability.
stormpath has excellent oauth2.0 implementation gives looking out of box.
stormpath has both remote , local oauth2 implementations , both freely available. remote case can rely on our backend using rest client (http://docs.stormpath.com/guides/token-management/) , of our sdks. local case can use our servlet plugin run web-app out of box oauth2 support. using docs link above, can find documentation these resources.
using stormpath spring boot integration, instance, this:
http -v --form post http://localhost:8080/oauth/token \ > 'origin:http://localhost:8080' \ > grant_type=password username=micah+demo.jsmith@stormpath.com password=<actual password>
(this example uses httpie interact locally running spring boot instance). line i've bolded above conforms oauth2.0 spec authenticating usernames , passwords. response like:
http/1.1 200 ok cache-control: no-store content-length: 325 content-type: application/json;charset=utf-8 date: tue, 04 aug 2015 16:02:08 gmt pragma: no-cache server: apache-coyote/1.1 set-cookie: account=eyjhbgcioijiuzi1nij9.eyjqdgkioiixndqynmqxmy1mnthiltrhndetymvkzs0wyjm0m2zjzdfhyzailcjpyxqioje0mzg3mdqxmjgsinn1yii6imh0dhbzoi8vyxbplnn0b3jtcgf0ac5jb20vdjevywnjb3vudhmvnw9nnfdjm1a0eel3cdrxauriumo4mcisimv4cci6mtqzodk2mzmyoh0.wcxrs5ygtuoewakqoql5jhiq109s1fmnopl_50hr_t4; expires=wed, 05-aug-2015 16:02:08 gmt; path=/; httponly { "access_token": "eyjhbgcioijiuzi1nij9.eyjqdgkioiixndqynmqxmy1mnthiltrhndetymvkzs0wyjm0m2zjzdfhyzailcjpyxqioje0mzg3mdqxmjgsinn1yii6imh0dhbzoi8vyxbplnn0b3jtcgf0ac5jb20vdjevywnjb3vudhmvnw9nnfdjm1a0eel3cdrxauriumo4mcisimv4cci6mtqzodk2mzmyoh0.wcxrs5ygtuoewakqoql5jhiq109s1fmnopl_50hr_t4", "expires_in": 259200, "token_type": "bearer" }
this provides bearer token can used on subsequent requests expiration. plus, has advantage of being jwt - json web token. jwt cryptographically signed ensure hasn't been tampered , can decoded provide additional meta-information client, including user information, access controls , expiration.
you similar using grant_type=authorization_code
interacting using id , secret, such independent module mentioned.
this article goes more detail on token authentication java.
full disclosure: stormpath employee , wrote article referenced above.
Comments
Post a Comment