habuma / spring-auth-server

Essential Spring Authorization Server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Essential Spring Authorization Server

This project is an essential Spring Authorization Server. It can run as-is or you can use it as the starting point to create your own authorization server.

It is not considered "production-ready", as a real authorization server wouldn't use a hard-coded client or a single user in an in-memory user details service. But it's a great start.

I created this project and pushed it to GitHub because I got tired of recreating the same authorization server project over and over every time I needed one.

How to use

Although the typical use of an authorization server would involve a resource server (e.g., an API) that wants to accept OAuth2 tokens as authorization from a client that wants access to the resources that the resource server serves. For that, you'll need to see how to create a resource server with Spring. (Eventually, I may push such a resource server to GitHub to pair up with this project.)

But, in lieu of a resource server and a client, you can pretend to be a client application using your web browser and curl. Here are the steps:

  • Start the authorization server:
% ./mvnw spring-boot:run
% export code=<<CODE COPIED IN PREVIOUS STEP>>
  • In the terminal, use curl to exchange the code for an access token:
% curl localhost:9000/oauth2/token \
-H"Content-type: application/x-www-form-urlencoded" \
-d"grant_type=authorization_code&redirect_uri=http://127.0.0.1:8080/authorized&code=$code" \
-u myclient:secret -v
  • In the response you'll get an access token, a refresh token, the token's scope and type, and the token's expiration time (in seconds). Copy the access token value.

  • Paste the token into the form at http://jwt.io to see the contents of the token. Alternatively, use the jwt command line tool (https://www.npmjs.com/package/jwt-cli):

% jwt <<ACCESS TOKEN COPIED FROM RESPONSE>>

About

Essential Spring Authorization Server


Languages

Language:Java 100.0%