Skip to content

Latest commit

 

History

History

github-client

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Intro Labs: Client app to GitHub API

This introduction lab shows how easy it is to use one of the well known OAuth2/OIDC provider like GitHub, Google or Facebook with Spring Security.

Spring Security provides the class CommonOAuth2Provider containing predefined configurations for setting up one of these providers in your client application:

  • Google
  • GitHub
  • Facebook
  • Okta

For details please see the corresponding section in the spring security reference doc

This lab implements a simple client to display notifications for the GitHub user who will authorize this client to use his/her GitHub credentials.

The relevant OAuth2 configuration part is quite simple and is located in application.yml file:

spring:
  security:
    oauth2:
      client:
        registration:
          github:
            client-id: <clientid>
            client-secret: <client_secret>
            scope:
              - read:user
              - notifications
            redirect-uri: '{baseUrl}/login/oauth2/code/{registrationId}'

As you can see there are placeholders or clientid and client_secret. To get these credentials you need a GitHub account, after logging into our account:

  1. Go to your personal settings
  2. Then select Developer Settings, select OAuth Apps and click on New OAuth App
  3. Use Notification-Client as application name
  4. Use http://localhost:9090/login/oauth2/code/github as redirect uri
  5. Use http://localhost:9090 as homepage url
  6. Click on _Register application'
  7. Now you should see the generated values for Client ID and Client Secret
  8. Copy these values over the placeholders in application.yml file

No start the main class com.example.github.GitHubClientApplication and browse to localhost:9090.

After you login into GitHub you should see user attributes and you should be able to get the notifications by clicking on the button on the top of the screen.