This is an application to see how to use Play 2/Scala, Slick and SecureSocial together. It uses Slick 2.0.0 and an in memory H2 database by default.
SecureSocial is an authentication plugin on Play that allows users to login through a variety of methods, including through OAuth providers.
The blog post is at blog.lunatech.com/2013/07/04/play-securesocial-slick
SecureSocial requires keys and secrets to authenticate with OAuth providers. We obviously can't commit those.
To add these secrets to your configuration, copy secrets.sample.conf
to secrets.conf
and fill in the blanks.
The secrets.conf
file is included from application.conf, and not from securesocial.conf
, since it also contains the Play application secret.
Configuration of SecureSocial is at http://securesocial.ws/guide/configuration.html
- Copy
conf/secrets.sample.conf
toconf/secrets.conf
- Generate an application secret in
application.secret
(easiest way is to create a new Play app, then copy it) - Set up your mail server or leave
smtp.mock=true
set in secrets.conf (you will have to look at console for output).
To run with Activator:
- Download Activator or
brew install typesafe-activator
or./activator
activator ui
To run natively:
- Make sure you have Play 2.2.1 installed.
play run
Running with OAuth providers:
Here, we need to use a callback, so we use ngrok to expose the internal service, and don't really need nginx (but it's a good habit to use it).
- Register for any external OAuth services you want to authenticate.
- Put the oauth credentials into
secrets.conf
. - Modify
play.plugins
to use the OAuth plugins you registered (a complete list is inplay.plugins.withoauth
). - Download and install nginx (
brew install nginx
if you're on a Mac). - Download and install ngrok from https://ngrok.com -- this allows OAuth callbacks to happen if need be.
- Start the play server (as above).
- Start ngrok with
ngrok 8080
. - Modify the server_name in
conf/nginx.conf
to point to your ngrok URL (i.e. ei3fawekemf.ngrok.com) - Copy
nginx.conf
to the nginx configuration directory with appropriate file name, i.e. /usr/local/etc/nginx/play.conf - Start nginx with
nginx -c /usr/local/etc/nginx/play.conf
(to stop, usenginx -s stop
). - Go to the public URL of your application, i.e. http://ei3fawekemf.ngrok.com
- Go to Twitter, enter the callback URL as http://ei3fawekemf.ngrok.com/authenticate/twitter
- Try to login with Twitter, etc.
Note that you can also use HTTPS with ngrok and it will be correctly set up with a valid SSL certificate (which makes SSL testing much easier). You can also examine HTTP requests in ngrok by going to http://localhost:4040/.