@octokit/auth-oauth-device
Advanced tools
Comparing version 3.0.2 to 3.1.0
@@ -95,2 +95,3 @@ 'use strict'; | ||
async function getOAuthAccessToken(state, options) { | ||
// @ts-expect-error looks like TypeScript cannot handle the different OAuth App/GitHub App paths here | ||
const cachedAuthentication = getCachedAuthentication(state, options.auth); | ||
@@ -105,3 +106,3 @@ if (cachedAuthentication) return cachedAuthentication; // The "/login/device/code" is not part of the REST API hosted on api.github.com, | ||
const scope = "scopes" in state ? { | ||
scope: (options.auth.scopes || state.scopes).join(" ") | ||
scope: ("scopes" in options.auth && options.auth.scopes || state.scopes).join(" ") | ||
} : {}; | ||
@@ -148,3 +149,3 @@ | ||
const authentication = state.authentication; | ||
const newScope = (auth.scopes || state.scopes).join(" "); | ||
const newScope = ("scopes" in auth && auth.scopes || state.scopes).join(" "); | ||
const currentScope = authentication.scopes.join(" "); | ||
@@ -231,2 +232,3 @@ return newScope === currentScope ? authentication : false; | ||
async function auth(state, authOptions) { | ||
// @ts-expect-error looks like TypeScript cannot handle the different OAuth App/GitHub App paths here | ||
return getOAuthAccessToken(state, { | ||
@@ -242,4 +244,5 @@ auth: authOptions | ||
return request(endpoint); | ||
} | ||
} // @ts-expect-error looks like TypeScript cannot handle the different OAuth App/GitHub App paths here | ||
const { | ||
@@ -257,3 +260,3 @@ token | ||
const VERSION = "3.0.2"; | ||
const VERSION = "3.1.0"; | ||
@@ -268,16 +271,14 @@ function createOAuthDeviceAuth(options) { | ||
const { | ||
request: request$1 = requestWithDefaults, | ||
clientType = "oauth-app", | ||
scopes = [] | ||
request: request$1 = requestWithDefaults | ||
} = options, | ||
otherOptions = _objectWithoutProperties(options, ["request", "clientType", "scopes"]); | ||
otherOptions = _objectWithoutProperties(options, ["request"]); | ||
const state = clientType === "github-app" ? _objectSpread2({ | ||
clientType, | ||
const state = options.clientType === "github-app" ? _objectSpread2(_objectSpread2({}, otherOptions), {}, { | ||
clientType: "github-app", | ||
request: request$1 | ||
}, otherOptions) : _objectSpread2({ | ||
clientType, | ||
}) : _objectSpread2(_objectSpread2({}, otherOptions), {}, { | ||
clientType: "oauth-app", | ||
request: request$1, | ||
scopes | ||
}, otherOptions); | ||
scopes: options.scopes || [] | ||
}); | ||
@@ -290,6 +291,7 @@ if (!options.clientId) { | ||
throw new Error('[@octokit/auth-oauth-device] "onVerification" option must be a function (https://github.com/octokit/auth-oauth-device.js#usage)'); | ||
} | ||
} // @ts-expect-error looks like TypeScript cannot handle the different OAuth App/GitHub App paths here | ||
return Object.assign(options => auth(state, options), { | ||
hook: (request, route, parameters) => hook(state, request, route, parameters) | ||
return Object.assign(auth.bind(null, state), { | ||
hook: hook.bind(null, state) | ||
}); | ||
@@ -296,0 +298,0 @@ } |
import { getOAuthAccessToken } from "./get-oauth-access-token"; | ||
export async function auth(state, authOptions) { | ||
// @ts-expect-error looks like TypeScript cannot handle the different OAuth App/GitHub App paths here | ||
return getOAuthAccessToken(state, { | ||
@@ -4,0 +5,0 @@ auth: authOptions, |
import { RequestError } from "@octokit/request-error"; | ||
export async function getOAuthAccessToken(state, options) { | ||
// @ts-expect-error looks like TypeScript cannot handle the different OAuth App/GitHub App paths here | ||
const cachedAuthentication = getCachedAuthentication(state, options.auth); | ||
@@ -15,3 +16,6 @@ if (cachedAuthentication) | ||
const scope = "scopes" in state | ||
? { scope: (options.auth.scopes || state.scopes).join(" ") } | ||
? { | ||
scope: (("scopes" in options.auth && options.auth.scopes) || | ||
state.scopes).join(" "), | ||
} | ||
: {}; | ||
@@ -54,7 +58,5 @@ const parameters = { | ||
const authentication = state.authentication; | ||
const newScope = (auth.scopes || state.scopes).join(" "); | ||
const newScope = (("scopes" in auth && auth.scopes) || state.scopes).join(" "); | ||
const currentScope = authentication.scopes.join(" "); | ||
return newScope === currentScope | ||
? authentication | ||
: false; | ||
return newScope === currentScope ? authentication : false; | ||
} | ||
@@ -61,0 +63,0 @@ async function wait(seconds) { |
@@ -8,2 +8,3 @@ import { getOAuthAccessToken } from "./get-oauth-access-token"; | ||
} | ||
// @ts-expect-error looks like TypeScript cannot handle the different OAuth App/GitHub App paths here | ||
const { token } = await getOAuthAccessToken(state, { | ||
@@ -10,0 +11,0 @@ request, |
@@ -13,14 +13,14 @@ import { getUserAgent } from "universal-user-agent"; | ||
}); | ||
const { request = requestWithDefaults, clientType = "oauth-app", scopes = [], ...otherOptions } = options; | ||
const state = clientType === "github-app" | ||
const { request = requestWithDefaults, ...otherOptions } = options; | ||
const state = options.clientType === "github-app" | ||
? { | ||
clientType, | ||
...otherOptions, | ||
clientType: "github-app", | ||
request, | ||
...otherOptions, | ||
} | ||
: { | ||
clientType, | ||
...otherOptions, | ||
clientType: "oauth-app", | ||
request, | ||
scopes, | ||
...otherOptions, | ||
scopes: options.scopes || [], | ||
}; | ||
@@ -33,5 +33,6 @@ if (!options.clientId) { | ||
} | ||
return Object.assign((options) => auth(state, options), { | ||
hook: (request, route, parameters) => hook(state, request, route, parameters), | ||
// @ts-expect-error looks like TypeScript cannot handle the different OAuth App/GitHub App paths here | ||
return Object.assign(auth.bind(null, state), { | ||
hook: hook.bind(null, state), | ||
}); | ||
} |
@@ -1,1 +0,1 @@ | ||
export const VERSION = "3.0.2"; | ||
export const VERSION = "3.1.0"; |
@@ -1,2 +0,3 @@ | ||
import { State, AuthOptions, Authentication, ClientType } from "./types"; | ||
export declare function auth<TClientType extends ClientType>(state: State, authOptions: AuthOptions): Promise<Authentication<TClientType>>; | ||
import { OAuthAppAuthOptions, GitHubAppAuthOptions, OAuthAppAuthentication, GitHubAppAuthentication, OAuthAppState, GitHubAppState } from "./types"; | ||
export declare function auth(state: OAuthAppState, authOptions: OAuthAppAuthOptions): Promise<OAuthAppAuthentication>; | ||
export declare function auth(state: GitHubAppState, authOptions: GitHubAppAuthOptions): Promise<GitHubAppAuthentication>; |
import { RequestInterface } from "@octokit/types"; | ||
import { AuthOptions, ClientType, State, Authentication } from "./types"; | ||
export declare function getOAuthAccessToken<TClientType extends ClientType>(state: State, options: { | ||
import { OAuthAppState, GitHubAppState, OAuthAppAuthOptions, GitHubAppAuthOptions, OAuthAppAuthentication, GitHubAppAuthentication } from "./types"; | ||
export declare function getOAuthAccessToken(state: OAuthAppState, options: { | ||
request?: RequestInterface; | ||
auth: AuthOptions; | ||
}): Promise<Authentication<TClientType>>; | ||
auth: OAuthAppAuthOptions; | ||
}): Promise<OAuthAppAuthentication>; | ||
export declare function getOAuthAccessToken(state: GitHubAppState, options: { | ||
request?: RequestInterface; | ||
auth: GitHubAppAuthOptions; | ||
}): Promise<GitHubAppAuthentication>; |
import { RequestInterface, OctokitResponse, EndpointOptions, RequestParameters, Route } from "@octokit/types"; | ||
import { ClientType, State } from "./types"; | ||
export declare function hook<TClientType extends ClientType>(state: State, request: RequestInterface, route: Route | EndpointOptions, parameters?: RequestParameters): Promise<OctokitResponse<any>>; | ||
import { OAuthAppState, GitHubAppState } from "./types"; | ||
export declare function hook(state: OAuthAppState | GitHubAppState, request: RequestInterface, route: Route | EndpointOptions, parameters?: RequestParameters): Promise<OctokitResponse<any>>; |
@@ -1,3 +0,4 @@ | ||
import * as Types from "./types"; | ||
export { StrategyOptions, AuthOptions, Authentication, OAuthAppAuthentication, GitHubAppAuthentication, GitHubAppAuthenticationWithExpiration, } from "./types"; | ||
export declare function createOAuthDeviceAuth<TClientType extends Types.ClientType = "oauth-app">(options: Types.StrategyOptions<TClientType>): Types.AuthInterface<TClientType>; | ||
import { GitHubAppAuthInterface, GitHubAppStrategyOptions, OAuthAppAuthInterface, OAuthAppStrategyOptions } from "./types"; | ||
export { OAuthAppStrategyOptions, OAuthAppAuthOptions, OAuthAppAuthentication, GitHubAppStrategyOptions, GitHubAppAuthOptions, GitHubAppAuthentication, GitHubAppAuthenticationWithExpiration, } from "./types"; | ||
export declare function createOAuthDeviceAuth(options: OAuthAppStrategyOptions): OAuthAppAuthInterface; | ||
export declare function createOAuthDeviceAuth(options: GitHubAppStrategyOptions): GitHubAppAuthInterface; |
import { RequestInterface, Route, EndpointOptions, RequestParameters, OctokitResponse } from "@octokit/types"; | ||
export declare type ClientType = "oauth-app" | "github-app"; | ||
export declare type OAuthAppStrategyOptions<TClientType extends ClientType> = { | ||
export declare type OAuthAppStrategyOptions = { | ||
clientId: string; | ||
clientType?: TClientType; | ||
clientType?: "oauth-app"; | ||
onVerification: OnVerificationCallback; | ||
@@ -10,16 +10,17 @@ scopes?: string[]; | ||
}; | ||
export declare type GitHubAppStrategyOptions<TClientType extends ClientType> = { | ||
export declare type GitHubAppStrategyOptions = { | ||
clientId: string; | ||
clientType: TClientType; | ||
clientType: "github-app"; | ||
onVerification: OnVerificationCallback; | ||
/** `scopes` are not permitted for GitHub Apps */ | ||
scopes?: never; | ||
request?: RequestInterface; | ||
}; | ||
export declare type StrategyOptions<TClientType extends ClientType = "oauth-app"> = TClientType extends "oauth-app" ? OAuthAppStrategyOptions<TClientType> : TClientType extends "github-app" ? GitHubAppStrategyOptions<TClientType> : never; | ||
export interface AuthInterface<TClientType extends ClientType> { | ||
(options: AuthOptions): Promise<Authentication<TClientType>>; | ||
export interface OAuthAppAuthInterface { | ||
(options: OAuthAppAuthOptions): Promise<OAuthAppAuthentication>; | ||
hook(request: RequestInterface, route: Route | EndpointOptions, parameters?: RequestParameters): Promise<OctokitResponse<any>>; | ||
} | ||
export declare type AuthOptions = { | ||
export interface GitHubAppAuthInterface { | ||
(options: GitHubAppAuthOptions): Promise<GitHubAppAuthentication | GitHubAppAuthenticationWithExpiration>; | ||
hook(request: RequestInterface, route: Route | EndpointOptions, parameters?: RequestParameters): Promise<OctokitResponse<any>>; | ||
} | ||
export declare type OAuthAppAuthOptions = { | ||
type: "oauth"; | ||
@@ -29,2 +30,6 @@ scopes?: string[]; | ||
}; | ||
export declare type GitHubAppAuthOptions = { | ||
type: "oauth"; | ||
refresh?: boolean; | ||
}; | ||
export declare type OAuthAppAuthentication = { | ||
@@ -44,4 +49,2 @@ type: "token"; | ||
token: string; | ||
/** GitHub apps do not support scopes */ | ||
scopes: never; | ||
}; | ||
@@ -57,6 +60,3 @@ export declare type GitHubAppAuthenticationWithExpiration = { | ||
refreshTokenExpiresAt: string; | ||
/** GitHub apps do not support scopes */ | ||
scopes: never; | ||
}; | ||
export declare type Authentication<TClientType extends ClientType = "oauth-app"> = TClientType extends "oauth-app" ? OAuthAppAuthentication : TClientType extends "github-app" ? GitHubAppAuthentication | GitHubAppAuthenticationWithExpiration : never; | ||
export declare type Verification = { | ||
@@ -76,3 +76,3 @@ device_code: string; | ||
request: RequestInterface; | ||
authentication?: Authentication<"oauth-app">; | ||
authentication?: OAuthAppAuthentication; | ||
}; | ||
@@ -84,5 +84,4 @@ export declare type GitHubAppState = { | ||
request: RequestInterface; | ||
authentication?: Authentication<"github-app">; | ||
authentication?: GitHubAppAuthentication | GitHubAppAuthenticationWithExpiration; | ||
}; | ||
export declare type State = OAuthAppState | GitHubAppState; | ||
export declare type CodeExchangeResponseError = "authorization_pending" | "slow_down" | "expired_token" | "unsupported_grant_type" | "incorrect_client_credentials" | "incorrect_device_code" | "access_denied"; |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "3.0.2"; | ||
export declare const VERSION = "3.1.0"; |
@@ -6,2 +6,3 @@ import { getUserAgent } from 'universal-user-agent'; | ||
async function getOAuthAccessToken(state, options) { | ||
// @ts-expect-error looks like TypeScript cannot handle the different OAuth App/GitHub App paths here | ||
const cachedAuthentication = getCachedAuthentication(state, options.auth); | ||
@@ -19,3 +20,6 @@ if (cachedAuthentication) | ||
const scope = "scopes" in state | ||
? { scope: (options.auth.scopes || state.scopes).join(" ") } | ||
? { | ||
scope: (("scopes" in options.auth && options.auth.scopes) || | ||
state.scopes).join(" "), | ||
} | ||
: {}; | ||
@@ -58,7 +62,5 @@ const parameters = { | ||
const authentication = state.authentication; | ||
const newScope = (auth.scopes || state.scopes).join(" "); | ||
const newScope = (("scopes" in auth && auth.scopes) || state.scopes).join(" "); | ||
const currentScope = authentication.scopes.join(" "); | ||
return newScope === currentScope | ||
? authentication | ||
: false; | ||
return newScope === currentScope ? authentication : false; | ||
} | ||
@@ -131,2 +133,3 @@ async function wait(seconds) { | ||
async function auth(state, authOptions) { | ||
// @ts-expect-error looks like TypeScript cannot handle the different OAuth App/GitHub App paths here | ||
return getOAuthAccessToken(state, { | ||
@@ -143,2 +146,3 @@ auth: authOptions, | ||
} | ||
// @ts-expect-error looks like TypeScript cannot handle the different OAuth App/GitHub App paths here | ||
const { token } = await getOAuthAccessToken(state, { | ||
@@ -152,3 +156,3 @@ request, | ||
const VERSION = "3.0.2"; | ||
const VERSION = "3.1.0"; | ||
@@ -162,14 +166,14 @@ function createOAuthDeviceAuth(options) { | ||
}); | ||
const { request: request$1 = requestWithDefaults, clientType = "oauth-app", scopes = [], ...otherOptions } = options; | ||
const state = clientType === "github-app" | ||
const { request: request$1 = requestWithDefaults, ...otherOptions } = options; | ||
const state = options.clientType === "github-app" | ||
? { | ||
clientType, | ||
...otherOptions, | ||
clientType: "github-app", | ||
request: request$1, | ||
...otherOptions, | ||
} | ||
: { | ||
clientType, | ||
...otherOptions, | ||
clientType: "oauth-app", | ||
request: request$1, | ||
scopes, | ||
...otherOptions, | ||
scopes: options.scopes || [], | ||
}; | ||
@@ -182,4 +186,5 @@ if (!options.clientId) { | ||
} | ||
return Object.assign((options) => auth(state, options), { | ||
hook: (request, route, parameters) => hook(state, request, route, parameters), | ||
// @ts-expect-error looks like TypeScript cannot handle the different OAuth App/GitHub App paths here | ||
return Object.assign(auth.bind(null, state), { | ||
hook: hook.bind(null, state), | ||
}); | ||
@@ -186,0 +191,0 @@ } |
{ | ||
"name": "@octokit/auth-oauth-device", | ||
"description": "GitHub OAuth Device authentication strategy for JavaScript", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"license": "MIT", | ||
@@ -20,2 +20,3 @@ "files": [ | ||
"dependencies": { | ||
"@octokit/oauth-methods": "^1.1.0", | ||
"@octokit/request": "^5.4.14", | ||
@@ -22,0 +23,0 @@ "@octokit/request-error": "^2.0.5", |
@@ -294,2 +294,4 @@ # auth-oauth-device.js | ||
Only relevant if the `clientType` strategy options was set to `"oauth-app"` | ||
Array of scope names enabled for the token. Defaults to what was set in the [strategy options](#createoauthdeviceauthoptions). See <a href="https://docs.github.com/en/developers/apps/scopes-for-oauth-apps#available-scopes">available scopes</a> | ||
@@ -625,6 +627,7 @@ | ||
import { | ||
StrategyOptions, | ||
AuthOptions, | ||
Authentication, | ||
OAuthAppStrategyOptions, | ||
OAuthAppAuthOptions, | ||
OAuthAppAuthentication, | ||
GitHubAppStrategyOptions, | ||
GitHubAppAuthOptions, | ||
GitHubAppAuthentication, | ||
@@ -631,0 +634,0 @@ GitHubAppAuthenticationWithExpiration, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77129
705
656
5
+ Added@octokit/oauth-authorization-url@4.3.3(transitive)
+ Added@octokit/oauth-methods@1.2.6(transitive)
+ Addedbtoa-lite@1.0.0(transitive)