MGalaCyber / Github-OAuth2

Github OAuth2 simplifies user authentication and profile management for Github-integrated applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GITHUB OAUTH2

Github OAuth2 is a comprehensive utility designed for Github integration, offering robust functionalities for user authentication and profile management.

Features

  • 🚀 Streamlined OAuth2 workflow for seamless user authentication and authorization.
  • 📦 Retrieve comprehensive user profiles, including details like username, avatar, and other.

Installation

npm:

$ npm install @mgalacyber/github-oauth2

yarn:

$ yarn add @mgalacyber/github-oauth2

Simple to Use

CommonJs (CJS) syntax

const { GithubOAuth2 } = require("@mgalacyber/github-oauth2");

ECMAScript Modules (ESM) syntax

import { GithubOAuth2 } from "@mgalacyber/github-oauth2";

Get Started

CREATE CLIENT

  1. Create a new application on the Github Developer
  2. Follow guide from official Github Documentation

Create OAuth2

const { GithubOAuth2 } = require("@mgalacyber/github-oauth2");

const oauth2 = new GithubOAuth2({
    clientId: "123456789012345678", // Required
    clientSecret: "1234567890ABCDEFGHIJ1234567890", // Required
    redirectUri: "https://example.com/callback" // Required
});

Generate OAuth2 URL

const { Scopes } = require("@mgalacyber/github-oauth2");

oauth2.GenerateOAuth2Url({
    scope: [ // Required
        Scopes.User,
        Scopes.UserEmail,
        Scopes.UserFollow,
        Scopes.ReadUser,
        Scopes.Repo,
    ],
    loginAccount: "Username", // Optional
    allowSignUp: true // Optional

}).then((result) => {
    console.log(result);
    // Response {
    //     state: string,
    //     url: string,
    // }
});

Get Access Token

oauth2.GetAccessToken(callbackCode).then((result) => {
    console.log(result);
    // Response {
    //     accessToken: string,
    //     tokenType: string,
    //     scope: string,
    // }
});

USER OAUTH2

  1. Follow guide from official Github Documentation

Get User Profile

Tip

Require scope for this function:

  • Use the user scope to retrieve the user profile.
  • Use the repo scope to retrieve the user's public repository and private repository status.
oauth2.GetUserProfile({
    accessToken: "1234567890ABCDEFGHIJ1234567890", // Required
    userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0", // Required

}).then((result) => {
    console.log(result);
    // Response {
    //     login: string;
    //     id: number;
    //     nodeId: string;
    //     avatarUrl: string;
    //     gravatarId: string;
    //     url: string;
    //     htmlUrl: string;
    //     followersUrl: string;
    //     followingUrl: string;
    //     gistsUrl: string;
    //     starredUrl: string;
    //     subscriptionsUrl: string;
    //     organizationsUrl: string;
    //     reposUrl: string;
    //     eventsUrl: string;
    //     receivedEventsUrl: string;
    //     type: string;
    //     siteAdmin: boolean;
    //     name: string;
    //     company: string;
    //     blog: string;
    //     location: string;
    //     email: string;
    //     hireable: boolean;
    //     bio: string;
    //     twitterUsername: string;
    //     publicRepos: number;
    //     publicGists: number;
    //     followers: number;
    //     following: number;
    //     createdAt: string;
    //     updatedAt: string;
    //     privateGists: string;
    //     totalPrivateRepos: number;
    //     ownedPrivateRepos: number;
    //     diskUsage: number;
    //     collaborators: number;
    //     twoFactorAuthentication: boolean;
    //     plan: {
    //         name: string;
    //         space: number;
    //         collaborators: number;
    //         privateRepos: number;
    //     }
    // }
});

Get User Repositories

Tip

Require scope for this function:

  • Use the repo scope to retrieve the user's public repository and private repository status.
oauth2.GetUserRepos({
    accessToken: "1234567890ABCDEFGHIJ1234567890", // Required
    userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0", // Required

}).then((result) => {
    console.log(result);
    // Response {
    //     id: number;
    //     nodeId: string;
    //     name: string;
    //     fullName: string;
    //     private: boolean;
    //     owner: {
    //         login: string;
    //         id: number;
    //         nodeId: string;
    //         avatarUrl: string;
    //         gravatarId: string;
    //         url: string;
    //         htmlUrl: string;
    //         followersUrl: string;
    //         followingUrl: string;
    //         gistsUrl: string;
    //         starredUrl: string;
    //         subscriptionsUrl: string;
    //         organizationsUrl: string;
    //         reposUrl: string;
    //         eventsUrl: string;
    //         receivedEventsUrl: string;
    //         type: string;
    //         siteAdmin: boolean;
    //     };
    //     htmlUrl: string;
    //     description: string;
    //     fork: boolean;
    //     url: string;
    //     forksUrl: string;
    //     keysUrl: string;
    //     collaboratorsUrl: string;
    //     teamsUrl: string;
    //     hooksUrl: string;
    //     issueEventsUrl: string;
    //     eventsUrl: string;
    //     assigneesUrl: string;
    //     branchesUrl: string;
    //     tagsUrl: string;
    //     blobsUrl: string;
    //     gitTagsUrl: string;
    //     gitRefsUrl: string;
    //     treesUrl: string;
    //     statusesUrl: string;
    //     languagesUrl: string;
    //     stargazersUrl: string;
    //     contributorsUrl: string;
    //     subscribersUrl: string;
    //     subscriptionUrl: string;
    //     commitsUrl: string;
    //     gitCommitsUrl: string;
    //     commentsUrl: string;
    //     issueCommentUrl: string;
    //     contentsUrl: string;
    //     compareUrl: string;
    //     mergesUrl: string;
    //     archiveUrl: string;
    //     downloadsUrl: string;
    //     issuesUrl: string;
    //     pullsUrl: string;
    //     milestonesUrl: string;
    //     notificationsUrl: string;
    //     labelsUrl: string;
    //     releasesUrl: string;
    //     deploymentsUrl: string;
    //     createdAt: string;
    //     updatedAt: string;
    //     pushedAt: string;
    //     gitUrl: string;
    //     sshUrl: string;
    //     cloneUrl: string;
    //     svnUrl: string;
    //     homepage: string;
    //     size: number;
    //     stargazersCount: number;
    //     watchersCount: number;
    //     language: string;
    //     hasIssues: boolean;
    //     hasProjects: boolean;
    //     hasDownloads: boolean;
    //     hasWiki: boolean;
    //     hasPages: boolean;
    //     hasDiscussions: boolean;
    //     forksCount: number;
    //     mirrorUrl: string;
    //     archived: boolean;
    //     disabled: boolean;
    //     openIssuesCount: number;
    //     license: {
    //         key: string;
    //         name: string;
    //         spdxId: string;
    //         url: string;
    //         nodeId: string;
    //     };
    //     allowForking: boolean;
    //     isTemplate: boolean;
    //     webCommitSignoffRequired: boolean;
    //     topics: string[];
    //     visibility: string;
    //     forks: number;
    //     openIssues: number;
    //     watchers: number;
    //     defaultBranch: string;
    //     permissions: {
    //         admin: boolean;
    //         maintain: boolean;
    //         push: boolean;
    //         triage: boolean;
    //         pull: boolean;
    //     };
    // }
});

Clone Github Repositories

Tip

Require scope for this function:

  • Use the repo scope to retrieve the user's public repository and private repository permission.
oauth2.CloneRepository({
    accessToken: "1234567890ABCDEFGHIJ1234567890", // Required
    repoName: "example", // Required
    repoOwner: "username", // Required
    localPath: "./folderPath" // Required

}).then((result) => {
    console.log(result);
    // Response: { any }
});

How It Works

Github OAuth2 simplifies user authentication and profile management for Github-integrated applications. It offers a straightforward OAuth2 workflow, enabling developers to seamlessly integrate Github features into their projects.

Bugs, glitches and issues

If you encounter any problems feel free to open an issue in our

About

Github OAuth2 simplifies user authentication and profile management for Github-integrated applications.

License:Apache License 2.0


Languages

Language:JavaScript 100.0%