Skip to content

A Spring Boot application demonstrating OAuth 2.0 authentication with GitHub using the Authorization Code flow.

License

Notifications You must be signed in to change notification settings

adityamishra1105/Github-OAuth-Login

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub OAuth Login Implementation

This project implements a complete OAuth 2.0 authentication system with GitHub integration. It showcases the Authorization Code flow, where users can sign in with their GitHub accounts, and the application retrieves and displays their profile information. Built with Spring Boot, Spring Security, and Thymeleaf, this project demonstrates real-world OAuth implementation skills that are valuable for web development roles.

Features

1 - Complete OAuth 2.0 Authorisation Code flow implementation
2 - GitHub authentication integration
3 - User profile data retrieval and display
4 - Responsive UI with Bootstrap and custom CSS
5 - Spring Security configuration

Technologies

Technologies
Java 17
Spring Boot 3.1.0
Spring Security OAuth2 Client
Thymeleaf
Bootstrap 5

Configuration

  • Go to GitHub Settings > Developer Settings > OAuth Apps
  • Create a new OAuth application with:
  • Homepage URL: http://localhost:8080
  • Authorisation callback URL: http://localhost:8080/login/oauth2/code/github
  • Copy the Client ID and Client Secret
  • Update src/main/resources/application.properties:
  • spring.security.oauth2.client.registration.github.client-id=YOUR_CLIENT_ID
    spring.security.oauth2.client.registration.github.client-secret=YOUR_CLIENT_SECRET

    Running the Application

    mvn spring-boot:run

    -> Access the application at: http://localhost:8080 (change the port if you want to)

    How It Works

  • User clicks "Sign in with GitHub"
  • Application redirects to GitHub's authorisation endpoint
  • After authentication, GitHub redirects back with an authorisation code
  • Spring Security exchanges the code for an access token
  • The access token is used to fetch user data from GitHub's API
  • User profile information is displayed
  • Project Structure

      src/main/java/com/example/githubauth/
      ├── config/SecurityConfig.java
      ├── controller/MainController.java
      └── GithubAuthApplication.java
    
    src/main/resources/
      ├── static/css/style.css
      ├── templates/
      │   ├── index.html
      │   ├── login.html
      │   └── profile.html
      └── application.properties
    

    License

    MIT LICENSE

    By

    Aditya Mishra. Happy Coding </>.

    About

    A Spring Boot application demonstrating OAuth 2.0 authentication with GitHub using the Authorization Code flow.

    Topics

    Resources

    License

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published