Coder Social home page Coder Social logo

oauth-gateway-exploration's Introduction

Spring Security OAuth 2.0 Gateway Exploration Example

This is the full source-code for the following blog post series.

No license is provided as it is only meant for learning purposes.

Set-up

The basic set-up we are going for is:

  • gateway at localhost:8080

  • dummy service at localhost:8081

  • keycloak at localhost:9090

run docker-compose up -d inside the keycloak directory to start a local keycloak server mapped to host port 9090

One-time Keycloak set-up

  • login with admin / admin

  • create a realm called service

  • a client called gateway

    • use valid redirect url: http://localhost:8080/*

    • select Access Type: confidential

    • save and click on the newly visible tab Credentials

  • Copy the Secret to the client-secret in the oauth-gateway application.yml

  • create a user for yourself to login with

  • create a role called dummy and assign it to your user

Running the services

run GatewayApplication to start the gateway

run DummyApplication to start the dummy backend service

Manual verification

Browse incognito to http://localhost:8080

  • login with the user you created

  • checkout the result (in case of a silent 401/403 failure, check for a WWW-Authenticate header in the response for a clue)

Note
In order to see one of the powers of OAuth-based AuthN/AuthZ, restart the Gateway and/or Dummy service and/or remove you Session Cookie stored in your browser (F12, Application, Cookies, http://localhost:8080, Clear All in Chrome) and refresh the page.
Note
If you just want to look at how the request with the token to the backend looks like, you could also just run netcat instead of the dummy-service using: nc -l localhost 8081

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.