documentation/manual/working/javaGuide/main/ws/JavaOAuth.md
OAuth is a simple way to publish and interact with protected data. It's also a safer and more secure way for people to give you access. For example, it can be used to access your users' data on Twitter.
There are two very different versions of OAuth: OAuth 1.0 and OAuth 2.0. Version 2 is simple enough to be implemented easily without library or helpers, so Play only provides support for OAuth 1.0.
To use OAuth, first add ws to your build.sbt file:
OAuth requires you to register your application to the service provider. Make sure to check the callback URL that you provide, because the service provider may reject your calls if they don't match. When working locally, you can use /etc/hosts to fake a domain on your local machine.
The service provider will give you:
Most of the flow will be done by the Play library.
Now the /access token/ can be passed to any call to access protected data.
More details on OAuth's process flow are available at The OAuth Bible.
conf/routes:
controller:
Note: OAuth does not provide any protection against MITM attacks. This example shows the OAuth token and secret stored in a session cookie -- for the best security, always use HTTPS with
play.http.session.secure=truedefined.