Home

Awesome

Play Silhouette Credentials Seed [Play 2.5 - Scala]

This project tries to be an example of how to implement an Authentication and Authorization layer using the Silhouette authentication library.

This template only show you how to implement a credential authentication, but it's easy to add the social authentication as well seeing the Silhouette documentation and other templates like these.

It implements the typical authentication and authorization functionality based on roles. You can:

And please, don't forget starring this project if you consider it has been useful for you.

Also check my other projects:

First of all: configure the Mail Plugin

I've used the Mailer plugin to send an email to the user for resetting passwords and email confirmation. For development it's configured to simply print the output to the console (with play.mailer.mock=true configuration). But to send real emails you need to set your smtp parameters in the configuration file.

For example, for a gmail email address:

play.mailer {
  host=smtp.gmail.com
  port=465
  user="your@gmail.com"
  password=yourpassword
  ssl=true
  from="your@gmail.com"
  mock=false
}

I've implemented MailService and Mailer to get it easier to use.

Silhouette

All the authentication and authorization functionalities are implemented using the Silhouette authentication library. Please check the documentation first.

The main ideas you have to know to understand the code are:

Let's see some interesting files:

Authentication

Please, check the Auth controller ( app/controllers/Auth.scala) to know how to:

Authorization

Each user has one or more services that indicate a specific area or hierarchical level. You can restrict sections to those users who match with a set of services (using logic OR or AND, you can choose). The master role has always full access to everywhere. For example:

The Authorization objects are implemented in app/utils/silhouette/Authorization.scala.

You also have some tags to customise your UI according to the services for the logged user. They are within the folder app/views/admin/tags/auth.

You will see a bit more information when you sign in and you will be able to try the authorization functionality by yourself.