GithubHelp home page GithubHelp logo

nithin100 / spring-security-multiple-auth Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 74 KB

This is a demonstration of using multiple authentication mechanisms for a spring boot resource server

Java 100.00%

spring-security-multiple-auth's Introduction

spring-security-multiple-auth

This is a demonstration of using multiple authentication mechanisms for a spring boot resource server

Disclaimer:

This code is only a proof of concept and is no way a production standard. However it is a great way to start with mutiple authentication scenarios. The best possible way of using a framework is to respect the way in which a framework is built. With that said, the best way someone can extend this code is by using multiple AuthenticationProviders and have AuthenticationManger to authenticate. This is how the spring security was built. Please refer to spring security documentation to understand the internal framework contracts.

About the code:

In the code I have two types of controllers: /api and /mobile. These two resources are protected by JWT and OAuth respectively. In order to simulate JWT issuing, I have a piece of code that gets triggered once the app starts. The token gets printed onto the console for you to validate the security. However, in production you would have an AuthorizationServer to issue tokens. You can write your own AuthorizationServer or use third party providers like OKTA, ISAM etc. In order to simulate OAuth2 security I have my own Authroization server (you can find it here: https://github.com/nithin100/spring-security/tree/master/authorization-server) running on localhost. This server gives me a token that I can use for my resource server. However, the userinfo endpoint of my authorization server expects Bearer token in Authorization header which is a problem as the NimbusTokenIntrospector (which is used by my resource server) sends the token as part of request body and not header. This can be easily solved by creating an API in AuthroizationServer (Which I didn't).

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.