Coder Social home page Coder Social logo

scala-steward / akka-http-jwt-security Goto Github PK

View Code? Open in Web Editor NEW

This project forked from techmonad/akka-http-jwt-security

0.0 1.0 0.0 73 KB

A basic example to implement a role based authentication and authorization with Akka HTTP using JWT Token.

License: MIT License

Scala 100.00%

akka-http-jwt-security's Introduction

AkkaHTTP JWT Security Codeship Status for techmonad/akka-http-jwt-security

A basic example to implement a role based authentication and authorization with Akka HTTP using JWT Token.

Run application:

$ sbt run

[info] Running com.techmonad.QuickStartServer 
Server online at http://127.0.0.1:8080/


1) Get JWT token:

 $ curl -XPOST -H 'Content-Type:application/json'  'localhost:8080/auth' -d '{"name":"Andy"}'
   {"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MTExNDY0MjksImlhdCI6MTYxMTA2MDAyOSwKICAiYWdlIjogMzEsCiAgImNvdW50cnkiOiAiRnJhbmNlIiwKICAibmFtZSI6ICJBbmR5IiwKICAicm9sZXMiOiBbImFkbWluIiwgInVzZXIiXQp9._7nzblnmMKABOK8KnkB9yJwjzH3PZhNZWUsCIrhdd78"}

2) Get User list:

 $ curl  -H 'Content-Type:application/json'  -H 'Authorization:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MTExNDYwMjIsImlhdCI6MTYxMTA1OTYyMiwKICAiYWdlIjogMzEsCiAgImNvdW50cnkiOiAiRnJhbmNlIiwKICAibmFtZSI6ICJBbmR5IiwKICAicm9sZXMiOiBbImFkbWluIiwgInVzZXIiXQp9.YVytWBCqFupvH2UEbPafFmGCmCq6l_6UNLx9VealSig' 'localhost:8080/users'
    {"users":[{"age":31,"country":"France","name":"Andy","roles":["admin","user"]}]}


3) Create new User:
 $ curl -XPOST -H 'Content-Type:application/json'  -H 'Authorization:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MTExNDYwMjIsImlhdCI6MTYxMTA1OTYyMiwKICAiYWdlIjogMzEsCiAgImNvdW50cnkiOiAiRnJhbmNlIiwKICAibmFtZSI6ICJBbmR5IiwKICAicm9sZXMiOiBbImFkbWluIiwgInVzZXIiXQp9.YVytWBCqFupvH2UEbPafFmGCmCq6l_6UNLx9VealSig' 'localhost:8080/users' \
 -d '{ "name": "bob", "age": 21,  "country": "CSA", "roles": ["user"]}'
      User bob created.

License

This code is open source software licensed under the MIT license.

akka-http-jwt-security's People

Contributors

anand-singh avatar satendrakumar avatar scala-steward avatar

Watchers

 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.