Coder Social home page Coder Social logo

spring-oauth2-jwt-jdbc's Introduction

Spring Boot OAuth 2 with JWT authentication and JDBC client store

This is based on the original project from: http://www.hascode.com/2016/03/setting-up-an-oauth2-authorization-server-and-resource-provider-with-spring-boot/ Please refer to: 2016 Micha Kops / hasCode.com

Enhanced functionality

Added JWT based authorization, OpenAPI access token enrichment, JDBC based client store.

Pre-requisits: Createa Mysql database jdbc:mysql://localhost:3306/identity with user name root and blank password. This is configured in DatabaseConfig.

  1. Start up com.hascode.tutorial.Oauth2AuthorizationServerApplication as a spring boot application.

  2. POST to http://localhost:9000/login with Content-Type application/json and body {"username":"greenrabbit948", "password":"celeste"} A JWT will be returned in the header, with a success 200.

  3. GET to http://localhost:9000/oauth/authorize?redirect_uri=http://localhost:8080/&client_id=ING_BANK&response_type=code with a header a Authorization Bearer jwt-token You will be redirected to localhost:8080 with an authorization code.

  4. Use the authorization code POST http://localhost:9000/oauth/token?redirect_uri=http://localhost:8080/&grant_type=authorization_code&code=YOUR_AUTH_CODE_FROM_ABOVE

  5. You will get an access token and an id_token in a json response

{
"access_token": "950d44c9-54b5-445f-8e82-02995d2468a0",
"token_type": "bearer",
"expires_in": 43199,
"scope": "openid",
"id_token": "ad9f151c-1296-4dc4-976b-3eaed9eb08dd"
}      

Original Doco:

Examples how to set up an OAuth2 identity server and resource provider within a few minutes using [Spring Boot] and Maven.

Please feel free to take a look at [my blog] for the full tutorial.

Running the Identity Server

Using Maven

cd identity-server && mvn spring-boot:run

Running the Resource Provider

Using Maven

cd resource-provider && mvn spring-boot:run

Requesting a Token

Using Curl

curl -XPOST -k -vi foo:foosecret@localhost:9000/hascode/oauth/token \
-d grant_type=password -d client_id=foo -d client_secret=abc123 \
-d redirect_uri=http://www.hascode.com -d username=bar -d password=barsecret

Accessing the secured Resource

TOKEN = 'xxxxxxx'
curl -vi -H "Authorization: Bearer $TOKEN" http://localhost:9001/resource/

spring-oauth2-jwt-jdbc's People

Contributors

nilathj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.