We can create a new spring project for GitHub OAuth from site: start.spring.io with the following dependency:

We need to create GitHub OAuth, under GitHub SETTINGS – developer settings – OAuth Apps -New OAuth App

After creating the OAuth app we need to generate a new client-secret

Lets specify the clientId and clientsecret in out application properties

Our controller class with test endpoint

Lets specify OAuth login in our configuration

Lets test the application. when we hit the test/hello endpoint we’ll get a page to put username/password if we have or else login with GitHub

After selecting GitHub login, we’ll be redirected to GitHub login page or if we have already logged in session with GitHub we’ll get a prompt to authorize the app.

After successful authentication, we’ll be redirected to our application endpoint:

Leave a Reply

Your email address will not be published. Required fields are marked *