Code Monkey home page Code Monkey logo

silhouette-rest-seed's Introduction

Silhouette REST Seed

Example project for Play Framework that use Silhouette for authentication and authorization, expose rest api for signup, signin and social authentication.

Basic usage

Sign-up

curl -X POST http://localhost:9000/auth/signup -H 'Content-Type: application/json' -d '{"firstName": "Alessandro", "lastName": "Random", "identifier": "[email protected]", "password": "ohmygodthispasswordisverystrong!"}' -v
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< X-Auth-Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVC...

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVC...",
  "expiresOn": "2015-02-20T10:35:42.813+01:00"
}

Sign-in

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

curl -X POST http://localhost:9000/auth/signin/credentials -H 'Content-Type: application/json' -d '{"identifier": "[email protected]", "password": "ohmygodthispasswordisverystrong!"}' -v
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< X-Auth-Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVC...

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVC...",
  "expiresOn": "2015-02-20T10:35:42.813+01:00"
}

Check if a request is authenticated

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

{
	"id":"0711b0ea-0935-4697-9b0d-6a1fa7233166",
	"loginInfo":{
		"providerID":"credentials",
		"providerKey":"[email protected]"
	},
	"email":"[email protected]",
	"info":{
		"firstName":"Alessandro",
		"lastName":"Random",
		"fullName":"Alessandro Random"
	},
	"roles":["user"]
}

Secured Acton with autorization

The token must belong to a user with Admin role

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

{"result":"Oh yess GOD"}

Features

  • Sign Up
  • Sign In (Credentials)
  • Authorization
  • Dependency Injection with Cake Pattern
  • Publishing Events
  • Avatar service
  • Mail service

Documentation

Consultate the Silhouette documentation for more information. If you need help with the integration of Silhouette into your project, don't hesitate and ask questions in our mailing list or on Stack Overflow.

Next Features

  • Link logged user with one or more social profile (already done, but not tested yet!)
  • Custom avatar service

License

The code is licensed under Apache License v2.0.

silhouette-rest-seed's People

Contributors

datalek avatar stephenmuss avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.