GithubHelp home page GithubHelp logo

gazbert / openid-connect-spring-client Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 4.0 65 KB

An OpenID Connect client using Spring Security and the Google Identity Platform.

License: MIT License

Shell 21.15% Batchfile 15.00% Java 61.73% HTML 2.12%
openid-connect google-identity spring-security spring-oauth2 spring-boot google-oauth jwt oidc

openid-connect-spring-client's Introduction

OpenID Connect Spring Client

Build Status

A simple demo of an OpenId Connect client using Spring Security and Spring OAuth2 to authenticate with the Google Identity Platform.

User Guide

Google Credentials

  1. Instructions assume you already have a Google account.
  2. Create a new project at Google Developer Console.
  3. Click on 'Credentials' on left menu.
  4. Click on 'OAuth consent screen' tab,
  5. Add 'Product name shown to users' e.g. MyThingyApp. Save.
  6. Click 'Create credentials' and select 'OAuth client ID'.
  7. Credentials: Create Client ID: Select 'Web Application'.
  8. Credentials: Create Client ID: Set 'Authorised redirect URIs': http://localhost:8080/login
  9. Click 'Create'. This will create your OAuth2 clientId and clientSecret.

Demo App

  1. Rename application.properties.template to application.properties.
  2. Add your clientId and clientSecret to the application.properties file.
  3. Update google.openidconnect.optional.scopes in application.properties as required.
  4. Build the app: mvn clean install
  5. Start the app: mvn spring-boot:run
  6. Open a browser and go to: http://localhost:8080

Once you've authenticated with Google and authorized the app, you should get redirected to the Homepage:

Secured Homepage

UserId: ALongNumber
Email: <username>@gmail.com

It's worth taking a look at the browser network tab to see the OpenID Connect interactions. The app console log dumps out some useful stuff too, e.g. token details and user info.

Testing

A bare-bones integration test is included and can be run as part of the build. To do this:

  1. Start the app: mvn spring-boot:run
  2. Run the test: mvn verify -Dskip.integration.tests=false

Credits

This app was inspired by the excellent tutorial written by eugenp. The integration test originated from code written by fromi.

References

  1. A good introduction to OpenID Connect.
  2. OpenID Connect Core Specification.
  3. RFC7519 - the Java Web Token (JWT) spec.
  4. A useful JWT Debugger.

openid-connect-spring-client's People

Contributors

gazbert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

openid-connect-spring-client's Issues

401 Unauthorized while running the application

Followed the steps in the readme to setup the clientId and clientSecret for my app from the google developer console. However, there is a 401 error

This application has no explicit mapping for /error, so you are seeing this as a fallback.
There was an unexpected error (type=Unauthorized, status=401).
Authentication Failed: Could not obtain access token

The authorization code is sent as a param to the redirect url; it looks like the step to fetch the token from the code is failing. Not sure about the reason.
Please let me know what is the issue and how to resolve this

http://localhost:8080/login?state=lPUTMz&code=4/AAABGwcvimYggXTgS_PE_FA0Kj5yC51BMDbWwMtoHapeF3KV0ZlSQ65fMZymLE6KUkMyNp_4US1pn7eW2UKU5g0&authuser=0&session_state=916976b3d98f07bb514aee7cd69208b78ec0c762..b804&prompt=consent#

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.