Giter Club home page Giter Club logo

spring-rest-oauth2-sample's Introduction

Spring Rest OAuth2 Sample

This is REST service sample that protected by Spring OAuth 2.

Build and Run

$ cd <spring-rest-oauth2-sample root path>
$ ./gradlew clean build bootRun

Usage

  1. Take your token from oauth/token in terminal, if you use ssl remember add -k:
$ curl -X POST -vu ios_app:123456 http://localhost:8080/oauth/token -H "Accept: application/json" -d "password=admin&username=admin&grant_type=password&scope=read&client_secret=123456&client_id=ios_app"

or Advanced REST Client in your Chrome with:

url: http://localhost:8080/oauth/token
POST
headers: Authorization: Basic <Encrypt client_id:client_secret by HTTP Basic>
playload: password=admin&username=admin&grant_type=password&scope=read
  1. Use the 'access_json' returned to make the authorized request to the protected endpoint:
$ curl http://localhost:8080/welcome -H "Authorization: Bearer <access_token_returned>"

If the request is successful, you will see the following JSON response:

{
	"id":2,
	"content":"Hello, admin!"
}

or use Advanced REST Client:

url: http://localhost:8080/welcome
GET
headers: Authorization: bearer <access_token_returned>
  1. Get user information:
$ curl http://localhost:8080/resources/users/admin -H "Authorization: Bearer <access_token_returned>"

If the request is successful, you will see the following JSON response:

{
	"name":"admin",
	"username":"admin"
}

or use Advanced REST Client:

url: http://localhost:8080/resources/users/admin
GET
headers: Authorization: bearer <access_token_returned>
  1. Refresh token:
curl -X POST -vu ios_app:123456 http://localhost:8080/oauth/token -H "Accept: application/json" -d "grant_type=refresh_token&refresh_token=<refresh_token_returned>&client_secret=123456&client_id=ios_app"

or use Advanced REST Client:

url: http://localhost:8080/oauth/token
POST
headers: Authorization: Basic <Encrypt client_id:client_secret by HTTP Basic>
playload: grant_type=refresh_token&refresh_token=<refresh_token_returned>

Version History:

  • 0.0.1-SNAPSHOT
    • Initial version.
  • 0.1.0-RELEASE
    • Release version.
  • 0.2.0-RELEASE
    • Change authorities to resources.
    • Add https.
    • Fix some bugs.
  • 0.2.1-RELEASE
    • Add name to Resource PO.
    • Change getAuthorities().
    • Change import.sql.
  • 0.3.0-RELEASE
    • Add /bo, /enums, /exception.
    • Add UserService and its implement.
  • 0.3.1-RELEASE
    • Modify build.gradle.
    • Add refresh token usage.
  • 0.3.2-RELEASE
    • Fix some hidden bugs.
    • Add SystemRuntimeException and UnknownException.

spring-rest-oauth2-sample's People

Contributors

danielliao11 avatar

Watchers

James Cloos avatar jianli ZHANG 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.