@octokit/auth-oauth-app
Advanced tools
Comparing version 3.0.8 to 3.1.0
@@ -60,2 +60,6 @@ 'use strict'; | ||
if (authOptions.type === "token") { | ||
console.warn(`[@octokit/auth-oauth-app] "{type: 'token'}" is deprecated, use "{type: 'oauth-user'}" instead`); | ||
} | ||
if (authOptions.type === "token" || authOptions.type === "oauth-user") { | ||
const { | ||
@@ -134,2 +138,3 @@ token, | ||
console.warn(`[@octokit/auth-oauth-app] setting user authentication is deprecated. Use "@octokit/auth-oauth-user" instead`); | ||
const { | ||
@@ -144,5 +149,12 @@ token | ||
const VERSION = "3.0.8"; | ||
const VERSION = "3.1.0"; | ||
const deprecatedStrategyOptions = ["code", "redirectUrl", "state"]; | ||
function createOAuthAppAuth(options) { | ||
const usedDeprecatedOptions = deprecatedStrategyOptions.filter(option => option in options); | ||
if (usedDeprecatedOptions.length) { | ||
console.warn(`[@octokit/auth-oauth-app] "${usedDeprecatedOptions.join(", ")}" strategy options are deprecated. Use "@octokit/auth-oauth-user" instead`); | ||
} | ||
const state = Object.assign({ | ||
@@ -154,3 +166,4 @@ request: request.request.defaults({ | ||
}) | ||
}, options); | ||
}, options); // @ts-expect-error wtf | ||
return Object.assign(auth.bind(null, state), { | ||
@@ -157,0 +170,0 @@ hook: hook.bind(null, state) |
@@ -5,4 +5,7 @@ import btoa from "btoa-lite"; | ||
if (authOptions.type === "token") { | ||
console.warn(`[@octokit/auth-oauth-app] "{type: 'token'}" is deprecated, use "{type: 'oauth-user'}" instead`); | ||
} | ||
if (authOptions.type === "token" || authOptions.type === "oauth-user") { | ||
const { token, scopes } = await getOAuthAccessToken(state, { | ||
auth: authOptions | ||
auth: authOptions, | ||
}); | ||
@@ -13,3 +16,3 @@ return { | ||
tokenType: "oauth", | ||
scopes | ||
scopes, | ||
}; | ||
@@ -22,5 +25,5 @@ } | ||
headers: { | ||
authorization: `basic ${btoa(`${state.clientId}:${state.clientSecret}`)}` | ||
} | ||
authorization: `basic ${btoa(`${state.clientId}:${state.clientSecret}`)}`, | ||
}, | ||
}; | ||
} |
@@ -31,2 +31,3 @@ import btoa from "btoa-lite"; | ||
} | ||
console.warn(`[@octokit/auth-oauth-app] setting user authentication is deprecated. Use "@octokit/auth-oauth-user" instead`); | ||
const { token } = await getOAuthAccessToken(state, { request }); | ||
@@ -33,0 +34,0 @@ endpoint.headers.authorization = `token ${token}`; |
@@ -6,13 +6,19 @@ import { getUserAgent } from "universal-user-agent"; | ||
import { VERSION } from "./version"; | ||
const deprecatedStrategyOptions = ["code", "redirectUrl", "state"]; | ||
export function createOAuthAppAuth(options) { | ||
const usedDeprecatedOptions = deprecatedStrategyOptions.filter((option) => option in options); | ||
if (usedDeprecatedOptions.length) { | ||
console.warn(`[@octokit/auth-oauth-app] "${usedDeprecatedOptions.join(", ")}" strategy options are deprecated. Use "@octokit/auth-oauth-user" instead`); | ||
} | ||
const state = Object.assign({ | ||
request: request.defaults({ | ||
headers: { | ||
"user-agent": `octokit-auth-oauth-app.js/${VERSION} ${getUserAgent()}` | ||
} | ||
}) | ||
"user-agent": `octokit-auth-oauth-app.js/${VERSION} ${getUserAgent()}`, | ||
}, | ||
}), | ||
}, options); | ||
// @ts-expect-error wtf | ||
return Object.assign(auth.bind(null, state), { | ||
hook: hook.bind(null, state) | ||
hook: hook.bind(null, state), | ||
}); | ||
} |
@@ -1,1 +0,1 @@ | ||
export const VERSION = "3.0.8"; | ||
export const VERSION = "3.1.0"; |
@@ -1,2 +0,7 @@ | ||
import { State, AuthOptions, Authentication } from "./types"; | ||
export declare function auth(state: State, authOptions: AuthOptions): Promise<Authentication>; | ||
import { State, AuthAppOptions, AuthTokenOptions, DeprecatedAuthTokenOptions, Authentication } from "./types"; | ||
export declare function auth(state: State, authOptions: AuthAppOptions): Promise<Authentication>; | ||
export declare function auth(state: State, authOptions: AuthTokenOptions): Promise<Authentication>; | ||
/** | ||
* @deprecated `type: "token"` is deprecate. Use `type: "oauth"` instead | ||
*/ | ||
export declare function auth(state: State, authOptions: DeprecatedAuthTokenOptions): Promise<Authentication>; |
@@ -1,5 +0,5 @@ | ||
import { AuthTokenOptions, RequestInterface, State, TokenWithScopes } from "./types"; | ||
import { AuthTokenOptions, DeprecatedAuthTokenOptions, RequestInterface, State, TokenWithScopes } from "./types"; | ||
export declare function getOAuthAccessToken(state: State, options: { | ||
request?: RequestInterface; | ||
auth?: AuthTokenOptions; | ||
auth?: AuthTokenOptions | DeprecatedAuthTokenOptions; | ||
}): Promise<TokenWithScopes>; |
@@ -1,2 +0,2 @@ | ||
import { StrategyOptions, AuthOptions, Authentication } from "./types"; | ||
import { StrategyOptions, AuthOptions, Authentication, OAuthAppAuthInterface } from "./types"; | ||
export declare type Types = { | ||
@@ -7,4 +7,2 @@ StrategyOptions: StrategyOptions; | ||
}; | ||
export declare function createOAuthAppAuth(options: StrategyOptions): ((authOptions: AuthOptions) => Promise<Authentication>) & { | ||
hook: (request: import("./types").RequestInterface, route: string | import("@octokit/types").EndpointOptions, parameters?: import("@octokit/types").RequestParameters | undefined) => Promise<import("@octokit/types").OctokitResponse<any, number>>; | ||
}; | ||
export declare function createOAuthAppAuth(options: StrategyOptions): OAuthAppAuthInterface; |
@@ -21,6 +21,13 @@ import * as OctokitTypes from "@octokit/types"; | ||
}; | ||
declare type AuthAppOptions = { | ||
export declare type AuthAppOptions = { | ||
type: "oauth-app"; | ||
}; | ||
export declare type AuthTokenOptions = { | ||
type: "oauth-user"; | ||
code?: string; | ||
redirectUrl?: string; | ||
state?: string; | ||
}; | ||
/** @deprecated type: "token" is deprecated. Use type: "oauth-user" */ | ||
export declare type DeprecatedAuthTokenOptions = { | ||
type: "token"; | ||
@@ -31,3 +38,3 @@ code?: string; | ||
}; | ||
export declare type AuthOptions = AuthAppOptions | AuthTokenOptions; | ||
export declare type AuthOptions = AuthAppOptions | AuthTokenOptions | DeprecatedAuthTokenOptions; | ||
export declare type TokenWithScopes = { | ||
@@ -54,2 +61,5 @@ token: string; | ||
}; | ||
export {}; | ||
export interface OAuthAppAuthInterface { | ||
(options?: AuthOptions): Promise<Authentication>; | ||
hook(request: OctokitTypes.RequestInterface, route: OctokitTypes.Route | OctokitTypes.EndpointOptions, parameters?: OctokitTypes.RequestParameters): Promise<OctokitTypes.OctokitResponse<any>>; | ||
} |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "3.0.8"; | ||
export declare const VERSION = "3.1.0"; |
@@ -50,4 +50,7 @@ import { getUserAgent } from 'universal-user-agent'; | ||
if (authOptions.type === "token") { | ||
console.warn(`[@octokit/auth-oauth-app] "{type: 'token'}" is deprecated, use "{type: 'oauth-user'}" instead`); | ||
} | ||
if (authOptions.type === "token" || authOptions.type === "oauth-user") { | ||
const { token, scopes } = await getOAuthAccessToken(state, { | ||
auth: authOptions | ||
auth: authOptions, | ||
}); | ||
@@ -58,3 +61,3 @@ return { | ||
tokenType: "oauth", | ||
scopes | ||
scopes, | ||
}; | ||
@@ -67,4 +70,4 @@ } | ||
headers: { | ||
authorization: `basic ${btoa(`${state.clientId}:${state.clientSecret}`)}` | ||
} | ||
authorization: `basic ${btoa(`${state.clientId}:${state.clientSecret}`)}`, | ||
}, | ||
}; | ||
@@ -120,2 +123,3 @@ } | ||
} | ||
console.warn(`[@octokit/auth-oauth-app] setting user authentication is deprecated. Use "@octokit/auth-oauth-user" instead`); | ||
const { token } = await getOAuthAccessToken(state, { request }); | ||
@@ -126,14 +130,20 @@ endpoint.headers.authorization = `token ${token}`; | ||
const VERSION = "3.0.8"; | ||
const VERSION = "3.1.0"; | ||
const deprecatedStrategyOptions = ["code", "redirectUrl", "state"]; | ||
function createOAuthAppAuth(options) { | ||
const usedDeprecatedOptions = deprecatedStrategyOptions.filter((option) => option in options); | ||
if (usedDeprecatedOptions.length) { | ||
console.warn(`[@octokit/auth-oauth-app] "${usedDeprecatedOptions.join(", ")}" strategy options are deprecated. Use "@octokit/auth-oauth-user" instead`); | ||
} | ||
const state = Object.assign({ | ||
request: request.defaults({ | ||
headers: { | ||
"user-agent": `octokit-auth-oauth-app.js/${VERSION} ${getUserAgent()}` | ||
} | ||
}) | ||
"user-agent": `octokit-auth-oauth-app.js/${VERSION} ${getUserAgent()}`, | ||
}, | ||
}), | ||
}, options); | ||
// @ts-expect-error wtf | ||
return Object.assign(auth.bind(null, state), { | ||
hook: hook.bind(null, state) | ||
hook: hook.bind(null, state), | ||
}); | ||
@@ -140,0 +150,0 @@ } |
{ | ||
"name": "@octokit/auth-oauth-app", | ||
"description": "GitHub OAuth App authentication for JavaScript", | ||
"version": "3.0.8", | ||
"version": "3.1.0", | ||
"license": "MIT", | ||
@@ -19,7 +19,3 @@ "files": [ | ||
], | ||
"homepage": "https://github.com/octokit/auth-oauth-app.js#readme", | ||
"bugs": { | ||
"url": "https://github.com/octokit/auth-oauth-app.js/issues" | ||
}, | ||
"repository": "https://github.com/octokit/auth-oauth-app.js", | ||
"repository": "github:octokit/auth-oauth-app.js", | ||
"dependencies": { | ||
@@ -26,0 +22,0 @@ "@octokit/request": "^5.3.0", |
@@ -16,6 +16,6 @@ # auth-oauth-app.js | ||
- [`createOAuthAppAuth(options)`](#createoauthappauthoptions) | ||
- [`auth()`](#auth) | ||
- [`auth(options)`](#authoptions) | ||
- [Authentication object](#authentication-object) | ||
- [OAuth authentication](#oauth-authentication) | ||
- [OAuth access token authentication](#oauth-access-token-authentication) | ||
- [OAuth authentication](#oauth-authentication) | ||
- [OAuth access token authentication](#oauth-access-token-authentication) | ||
- [`auth.hook(request, route, parameters)` or `auth.hook(request, options)`](#authhookrequest-route-parameters-or-authhookrequest-options) | ||
@@ -80,4 +80,4 @@ - [Implementation details](#implementation-details) | ||
const tokenAuthentication = await auth({ | ||
type: "token", | ||
const userAuthentication = await auth({ | ||
type: "oauth-user", | ||
code: "random123", // code from OAuth web flow, see https://git.io/fhd1D | ||
@@ -194,3 +194,3 @@ state: "mystate123", | ||
## `auth()` | ||
## `auth(options)` | ||
@@ -222,3 +222,3 @@ The async `auth()` method returned by `createOAuthAppAuth(options)` accepts the following options | ||
<td> | ||
<strong>Required.</strong> Either <code>"oauth-app"</code> or <code>"token"</code>. | ||
<strong>Required.</strong> Either <code>"oauth-app"</code> or <code>"oauth-user"</code>. | ||
</td> | ||
@@ -425,3 +425,3 @@ </tr> | ||
`auth.hook` will set the correct authentication header automatically based on the request URL. For all [OAuth Application endpoints](https://developer.github.com/v3/apps/oauth_applications/), the `Authorization` header is set to basic auth. For all other endpoints and token is retrieved and used in the `Authorization` header. The token is cached and used for succeeding requsets. | ||
`auth.hook` will set the correct authentication header automatically based on the request URL. For all [OAuth Application endpoints](https://developer.github.com/v3/apps/oauth_applications/), the `Authorization` header is set to basic auth. For all other endpoints and token is retrieved and used in the `Authorization` header. The token is cached and used for succeeding requests. | ||
@@ -428,0 +428,0 @@ To reset the cached access token, you can do this |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
64046
516
2
1