Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Universal library to retrieve GitHub’s identity URL for the OAuth web flow

License

NotificationsYou must be signed in to change notification settings

octokit/oauth-authorization-url.js

Repository files navigation

Universal library to retrieve GitHub’s identity URL for the OAuth web flow

@latestBuild Status

SeeGitHub’s Developer Guide for the OAuth App web application flow. Note that theOAuth web application flow for GitHub Apps is slightly different. GitHub Apps do not support scopes for its user access tokens (they are called user-to-server tokens for GitHub Apps), instead they inherit the user permissions from the GitHub App's registration and the repository/organization access and permissions from the respective installation.

Usage

Browsers

Load@octokit/oauth-authorization-url directly fromesm.sh

<scripttype="module">import{oauthAuthorizationUrl}from"https://esm.sh/@octokit/oauth-authorization-url";</script>
Node

Install withnpm install @octokit/oauth-authorization-url

const{ oauthAuthorizationUrl}=require("@octokit/oauth-authorization-url");// or: import { oauthAuthorizationUrl } from "@octokit/oauth-authorization-url";

Important

As we useconditional exports, you will need to adapt yourtsconfig.json by setting"moduleResolution": "node16", "module": "node16".

See the TypeScript docs onpackage.json "exports".
See thishelpful guide on transitioning to ESM from@sindresorhus

For OAuth Apps

const{ url, clientId, redirectUrl, login, scopes, state}=oauthAuthorizationUrl({clientType:"oauth-app",clientId:"1234567890abcdef1234",redirectUrl:"https://example.com",login:"octocat",scopes:["repo","admin:org"],state:"secret123",});

For GitHub Apps

const{ url, clientId, redirectUrl, login, state}=oauthAuthorizationUrl({clientType:"github-app",clientId:"lv1.1234567890abcdef",redirectUrl:"https://example.com",login:"octocat",state:"secret123",});

Options

name description
clientIdRequired. The client ID you received from GitHub when you registered.
clientType

Must be set to either"oauth-app" or"github-app". Defaults to"oauth-app".

redirectUrl The URL in your application where users will be sent after authorization. SeeRedirect URLs in GitHub’s Developer Guide.
login Suggests a specific account to use for signing in and authorizing the app.
scopes

Only relevant whenclientType is set to"oauth-app".

An array of scope names (or: space-delimited list of scopes). If not provided, scope defaults to an empty list for users that have not authorized any scopes for the application. For users who have authorized scopes for the application, the user won't be shown the OAuth authorization page with the list of scopes. Instead, this step of the flow will automatically complete with the set of scopes the user has authorized for the application. For example, if a user has already performed the web flow twice and has authorized one token with user scope and another token with repo scope, a third web flow that does not provide a scope will receive a token with user and repo scope.

Defaults to[] ifclientType is set to"oauth-app".

state An unguessable random string. It is used to protect against cross-site request forgery attacks. Defaults toMath.random().toString(36).substr(2).
allowSignup Whether or not unauthenticated users will be offered an option to sign up for GitHub during the OAuth flow. Usefalse in the case that a policy prohibits signups. Defaults totrue.
baseUrl When using GitHub Enterprise Server, set the baseUrl to the origin, e.g.https://github.my-enterprise.com.

Result

oauthAuthorizationUrl() returns an object with the following properties

name description
allowSignup Returnsoptions.allowSignup if it was set. Defaults totrue.
clientType Returnsoptions.clientType. Defaults to"oauth-app".
clientId Returnsoptions.clientId.
login Returnsoptions.login if it was set. Defaults tonull.
redirectUrl Returnsoptions.redirectUrl if it was set. Defaults tonull.
scopes

Only set ifoptions.clientType is set to"oauth-app".

Returns an array of strings. Returnsoptions.scopes if it was set and turns the string into an array if a string was passed, otherwise[].

state Returnsoptions.state if it was set. Defaults to Defaults toMath.random().toString(36).substr(2).
url The authorization URL

Types

import{ClientType,OAuthAppOptions,OAuthAppResult,GitHubAppOptions,GitHubAppResult,}from"@octokit/oauth-authorization-url";

License

MIT

About

Universal library to retrieve GitHub’s identity URL for the OAuth web flow

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors15


[8]ページ先頭

©2009-2025 Movatter.jp