npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mgalacyber/github-oauth2

v3.1.4

Published

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

Downloads

91

Readme

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.UserSchemas.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 Emails

[!TIP] Require scope for this function:

  • Use the user:email scope to retrieve the user emails.
oauth2.UserSchemas.EmailSchemas.GetEmails({
    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 [
    //     {
    //         email: string;
    //         primary: boolean;
    //         verified: boolean;
    //         visibility: string;
    //     },
    // ]
});

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.UserSchemas.GetUserRepositories({
    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.RespositorySchemas.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