@octokit/auth-oauth-app
Advanced tools
Comparing version 4.1.2 to 4.2.0
@@ -12,17 +12,2 @@ 'use strict'; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
@@ -33,5 +18,9 @@ var keys = Object.keys(object); | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
if (enumerableOnly) { | ||
symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
} | ||
keys.push.apply(keys, symbols); | ||
@@ -63,2 +52,17 @@ } | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
@@ -143,4 +147,4 @@ if (source == null) return {}; | ||
if (!authOauthUser.requiresBasicAuth(endpoint.url)) { | ||
throw new Error(`[@octokit/auth-oauth-app] "${endpoint.method} ${endpoint.url}" does not support clientId/clientSecret basic authentication. Use @octokit/auth-oauth-user instead.`); | ||
if (state.clientType === "github-app" && !authOauthUser.requiresBasicAuth(endpoint.url)) { | ||
throw new Error(`[@octokit/auth-oauth-app] GitHub Apps cannot use their client ID/secret for basic authentication for endpoints other than "/applications/{client_id}/**". "${endpoint.method} ${endpoint.url}" is not supported.`); | ||
} | ||
@@ -150,6 +154,14 @@ | ||
endpoint.headers.authorization = `basic ${credentials}`; | ||
return await request(endpoint); | ||
try { | ||
return await request(endpoint); | ||
} catch (error) { | ||
/* istanbul ignore if */ | ||
if (error.status !== 401) throw error; | ||
error.message = `[@octokit/auth-oauth-app] "${endpoint.method} ${endpoint.url}" does not support clientId/clientSecret basic authentication.`; | ||
throw error; | ||
} | ||
} | ||
const VERSION = "4.1.2"; | ||
const VERSION = "4.2.0"; | ||
@@ -167,3 +179,2 @@ function createOAuthAppAuth(options) { | ||
return Object.assign(auth.bind(null, state), { | ||
// @ts-expect-error not worth the extra code to appease TS | ||
hook: hook.bind(null, state) | ||
@@ -170,0 +181,0 @@ }); |
@@ -9,8 +9,17 @@ import btoa from "btoa-lite"; | ||
} | ||
if (!requiresBasicAuth(endpoint.url)) { | ||
throw new Error(`[@octokit/auth-oauth-app] "${endpoint.method} ${endpoint.url}" does not support clientId/clientSecret basic authentication. Use @octokit/auth-oauth-user instead.`); | ||
if (state.clientType === "github-app" && !requiresBasicAuth(endpoint.url)) { | ||
throw new Error(`[@octokit/auth-oauth-app] GitHub Apps cannot use their client ID/secret for basic authentication for endpoints other than "/applications/{client_id}/**". "${endpoint.method} ${endpoint.url}" is not supported.`); | ||
} | ||
const credentials = btoa(`${state.clientId}:${state.clientSecret}`); | ||
endpoint.headers.authorization = `basic ${credentials}`; | ||
return await request(endpoint); | ||
try { | ||
return await request(endpoint); | ||
} | ||
catch (error) { | ||
/* istanbul ignore if */ | ||
if (error.status !== 401) | ||
throw error; | ||
error.message = `[@octokit/auth-oauth-app] "${endpoint.method} ${endpoint.url}" does not support clientId/clientSecret basic authentication.`; | ||
throw error; | ||
} | ||
} |
@@ -18,5 +18,4 @@ import { getUserAgent } from "universal-user-agent"; | ||
return Object.assign(auth.bind(null, state), { | ||
// @ts-expect-error not worth the extra code to appease TS | ||
hook: hook.bind(null, state), | ||
}); | ||
} |
@@ -1,1 +0,1 @@ | ||
export const VERSION = "4.1.2"; | ||
export const VERSION = "4.2.0"; |
@@ -99,5 +99,5 @@ import { EndpointOptions, RequestParameters, Route, RequestInterface, OctokitResponse } from "@octokit/types"; | ||
}; | ||
export declare type GitHubAppState = OAuthAppStrategyOptions & { | ||
export declare type GitHubAppState = GitHubAppStrategyOptions & { | ||
clientType: "github-app"; | ||
request: RequestInterface; | ||
}; |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "4.1.2"; | ||
export declare const VERSION = "4.2.0"; |
@@ -52,11 +52,20 @@ import { getUserAgent } from 'universal-user-agent'; | ||
} | ||
if (!requiresBasicAuth(endpoint.url)) { | ||
throw new Error(`[@octokit/auth-oauth-app] "${endpoint.method} ${endpoint.url}" does not support clientId/clientSecret basic authentication. Use @octokit/auth-oauth-user instead.`); | ||
if (state.clientType === "github-app" && !requiresBasicAuth(endpoint.url)) { | ||
throw new Error(`[@octokit/auth-oauth-app] GitHub Apps cannot use their client ID/secret for basic authentication for endpoints other than "/applications/{client_id}/**". "${endpoint.method} ${endpoint.url}" is not supported.`); | ||
} | ||
const credentials = btoa(`${state.clientId}:${state.clientSecret}`); | ||
endpoint.headers.authorization = `basic ${credentials}`; | ||
return await request(endpoint); | ||
try { | ||
return await request(endpoint); | ||
} | ||
catch (error) { | ||
/* istanbul ignore if */ | ||
if (error.status !== 401) | ||
throw error; | ||
error.message = `[@octokit/auth-oauth-app] "${endpoint.method} ${endpoint.url}" does not support clientId/clientSecret basic authentication.`; | ||
throw error; | ||
} | ||
} | ||
const VERSION = "4.1.2"; | ||
const VERSION = "4.2.0"; | ||
@@ -74,3 +83,2 @@ function createOAuthAppAuth(options) { | ||
return Object.assign(auth.bind(null, state), { | ||
// @ts-expect-error not worth the extra code to appease TS | ||
hook: hook.bind(null, state), | ||
@@ -77,0 +85,0 @@ }); |
{ | ||
"name": "@octokit/auth-oauth-app", | ||
"description": "GitHub OAuth App authentication for JavaScript", | ||
"version": "4.1.2", | ||
"version": "4.2.0", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "files": [ |
@@ -21,3 +21,3 @@ # auth-oauth-app.js | ||
- [`auth(options)` or `octokit.auth(options)`](#authoptions-or-octokitauthoptions) | ||
- [Client ID/Client Secret Basic authentication](#client-idclient-server-basic-authentication) | ||
- [Client ID/Client Secret Basic authentication](#client-idclient-secret-basic-authentication) | ||
- [OAuth web flow](#oauth-web-flow) | ||
@@ -524,3 +524,3 @@ - [OAuth device flow](#oauth-device-flow) | ||
await prompt("press enter when you are ready to continue") | ||
await prompt("press enter when you are ready to continue"); | ||
}, | ||
@@ -527,0 +527,0 @@ }); |
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
60928
446