Skip to content

Seed project for Play Framework 2.6 with Silhouette 5.0, exposing a REST API for sign-up and signin. ReactiveMongo + MongoDB used as a backing store.

Notifications You must be signed in to change notification settings

adamzareba/play-silhouette-rest-mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Silhouette REST MongoDB Seed Build Status Codacy Badge

Example project for Play Framework that uses Silhouette for authentication and authorization, exposed REST API for sign-up, sign-in.

Basic usage

Sign-up

curl -X POST http://localhost:9000/api/auth/signup  -H 'Content-Type: application/json' -d '{"identifier": "adam.zareba", "password": "this!Password!Is!Very!Very!Strong!", "email": "[email protected]", "firstName": "Adam", "lastName": "Zaręba"}' -v
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< X-Auth-Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...

{
  "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
  "expiresOn": "2017-10-06T07:49:27.238+02:00"
}

Sign-in

Not necessary just after the sign-up because you already have a valid token.

curl -X POST http://localhost:9000/api/auth/signin/credentials -H 'Content-Type: application/json' -d '{"identifier": "adam.zareba", "password": "this!Password!Is!Very!Very!Strong!"}' -v
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< X-Auth-Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...

{
  "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
  "expiresOn": "2017-10-06T07:49:27.238+02:00"
}

Secured Action with autorization

The token must belong to a user with Admin role

curl http://localhost:9000/badPassword -H 'X-Auth-Token:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...' -v
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8

{"result":"qwerty1234"}

Built-in users

username password
test1 test1Password
test2 test2Password

Database reload

It is possible to reload database with based data with scripts: recreate.bat or recreate.sh

API documentation

Documentation is available under address: REST API

License

The code is licensed under Apache License v2.0.

About

Seed project for Play Framework 2.6 with Silhouette 5.0, exposing a REST API for sign-up and signin. ReactiveMongo + MongoDB used as a backing store.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published