7.1.1 • Published 24 days ago

@octokit/oauth-authorization-url v7.1.1

Weekly downloads
783
License
MIT
Repository
github
Last release
24 days ago

oauth-authorization-url.js

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

@latest Build Status

See GitHub’s Developer Guide for the OAuth App web application flow. Note that the OAuth 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

Load @octokit/oauth-authorization-url directly from esm.sh

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

Install with npm install @octokit/oauth-authorization-url

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

!IMPORTANT As we use conditional exports, you will need to adapt your tsconfig.json by setting "moduleResolution": "node16", "module": "node16".

See the TypeScript docs on package.json "exports". See this helpful 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

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

Only relevant when clientType 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 [] if clientType is set to "oauth-app".

Result

oauthAuthorizationUrl() returns an object with the following properties

Only set if options.clientType is set to "oauth-app".

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

Types

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

License

MIT

7.1.1

24 days ago

7.1.0

1 month ago

7.0.1

2 months ago

7.0.0

2 months ago

7.0.0-beta.1

3 months ago

6.0.1

11 months ago

6.0.0

11 months ago

6.0.2

11 months ago

5.0.0

2 years ago

4.3.3

3 years ago

4.3.2

3 years ago

4.3.1

3 years ago

4.3.0

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.2

3 years ago

4.1.1

4 years ago

4.1.0

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.0

4 years ago