Skip to content

🗄️ A lightweight Node.js + Express server that handles GitHub OAuth authentication, exchanges authorization codes for access tokens, and retrieves user information. Perfect for integrating GitHub login into your apps.

License

Notifications You must be signed in to change notification settings

art2url/git-oauth-bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub OAuth Server

This repository provides a simple Node.js + Express backend that handles GitHub OAuth authentication. It exchanges the GitHub authorization code for an access token and retrieves user information.

Features

  • Handles GitHub OAuth authentication
  • Exchanges authorization code for access token
  • Retrieves authenticated GitHub user's information
  • Configurable via environment variables
  • CORS-enabled for integration with front-end applications

Prerequisites

  • Node.js and npm installed on your machine
  • A GitHub OAuth application with Client ID and Client Secret

Setup

  1. Clone the Repository:
git clone https://github.com/art2url/git-oauth-bridge.git
cd git-oauth-bridge
  1. Install Dependencies:
npm install
  1. Retrieve GitHub OAuth Credentials:

    • Go to GitHub Developer Settings.
    • Click on "New OAuth App".
    • Fill in the required fields:
      • Application Name: Your app's name.
      • Homepage URL: Your app's homepage (e.g., http://localhost:3000).
      • Authorization Callback URL: http://localhost:3000/auth/github/callback (or your actual callback URL).
    • After creating the app, you will see Client ID and Client Secret.
  2. Configure Environment Variables: Create a .env file in the root directory with the following content:

GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
PORT=3000 # Optional, defaults to 3000
  1. Run the Server:
node server.js

API Endpoints

POST /auth/github

Handles GitHub OAuth authentication by exchanging the authorization code for an access token and retrieving user information.

Request Body:

{
  "code": "<github_authorization_code>"
}

Successful Response:

{
  "access_token": "<github_access_token>",
  "github_username": "<github_username>"
}

Error Responses:

  • 400 Bad Request: If the authorization code is missing or invalid.
  • 500 Internal Server Error: If there's an issue during the OAuth flow.

License

This project is licensed under the MIT License.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

About

🗄️ A lightweight Node.js + Express server that handles GitHub OAuth authentication, exchanges authorization codes for access tokens, and retrieves user information. Perfect for integrating GitHub login into your apps.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published