Skip to content

Latest commit

 

History

History
75 lines (52 loc) · 2.48 KB

README.md

File metadata and controls

75 lines (52 loc) · 2.48 KB

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.