Socket
Socket
Sign inDemoInstall

@octokit/auth-oauth-device

Package Overview
Dependencies
Maintainers
4
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@octokit/auth-oauth-device - npm Package Compare versions

Comparing version 4.0.3 to 4.0.4

54

dist-node/index.js

@@ -11,5 +11,5 @@ 'use strict';

const cachedAuthentication = getCachedAuthentication(state, options.auth);
if (cachedAuthentication) return cachedAuthentication; // Step 1: Request device and user codes
if (cachedAuthentication) return cachedAuthentication;
// Step 1: Request device and user codes
// https://docs.github.com/en/developers/apps/authorizing-oauth-apps#step-1-app-requests-the-device-and-user-verification-codes-from-github
const {

@@ -23,8 +23,8 @@ data: verification

scopes: options.auth.scopes || state.scopes
}); // Step 2: User must enter the user code on https://github.com/login/device
});
// Step 2: User must enter the user code on https://github.com/login/device
// See https://docs.github.com/en/developers/apps/authorizing-oauth-apps#step-2-prompt-the-user-to-enter-the-user-code-in-a-browser
await state.onVerification(verification); // Step 3: Exchange device code for access token
await state.onVerification(verification);
// Step 3: Exchange device code for access token
// See https://docs.github.com/en/developers/apps/authorizing-oauth-apps#step-3-app-polls-github-to-check-if-the-user-authorized-the-device
const authentication = await waitForAccessToken(options.request || state.request, state.clientId, state.clientType, verification);

@@ -34,11 +34,8 @@ state.authentication = authentication;

}
function getCachedAuthentication(state, auth) {
if (auth.refresh === true) return false;
if (!state.authentication) return false;
if (state.clientType === "github-app") {
return state.authentication;
}
const authentication = state.authentication;

@@ -49,7 +46,5 @@ const newScope = ("scopes" in auth && auth.scopes || state.scopes).join(" ");

}
async function wait(seconds) {
await new Promise(resolve => setTimeout(resolve, seconds * 1000));
}
async function waitForAccessToken(request, clientId, clientType, verification) {

@@ -61,9 +56,11 @@ try {

code: verification.device_code
}; // WHY TYPESCRIPT WHY ARE YOU DOING THIS TO ME
};
// WHY TYPESCRIPT WHY ARE YOU DOING THIS TO ME
const {
authentication
} = clientType === "oauth-app" ? await oauthMethods.exchangeDeviceCode({ ...options,
} = clientType === "oauth-app" ? await oauthMethods.exchangeDeviceCode({
...options,
clientType: "oauth-app"
}) : await oauthMethods.exchangeDeviceCode({ ...options,
}) : await oauthMethods.exchangeDeviceCode({
...options,
clientType: "github-app"

@@ -79,6 +76,5 @@ });

// @ts-ignore
if (!error.response) throw error; // @ts-ignore
if (!error.response) throw error;
// @ts-ignore
const errorType = error.response.data.error;
if (errorType === "authorization_pending") {

@@ -88,3 +84,2 @@ await wait(verification.interval);

}
if (errorType === "slow_down") {

@@ -94,3 +89,2 @@ await wait(verification.interval + 5);

}
throw error;

@@ -107,8 +101,7 @@ }

async function hook(state, request, route, parameters) {
let endpoint = request.endpoint.merge(route, parameters); // Do not intercept request to retrieve codes or token
let endpoint = request.endpoint.merge(route, parameters);
// Do not intercept request to retrieve codes or token
if (/\/login\/(oauth\/access_token|device\/code)$/.test(endpoint.url)) {
return request(endpoint);
}
const {

@@ -126,3 +119,3 @@ token

const VERSION = "4.0.3";
const VERSION = "4.0.4";

@@ -139,6 +132,8 @@ function createOAuthDeviceAuth(options) {

} = options;
const state = options.clientType === "github-app" ? { ...otherOptions,
const state = options.clientType === "github-app" ? {
...otherOptions,
clientType: "github-app",
request: request$1
} : { ...otherOptions,
} : {
...otherOptions,
clientType: "oauth-app",

@@ -148,12 +143,9 @@ request: request$1,

};
if (!options.clientId) {
throw new Error('[@octokit/auth-oauth-device] "clientId" option must be set (https://github.com/octokit/auth-oauth-device.js#usage)');
}
if (!options.onVerification) {
throw new Error('[@octokit/auth-oauth-device] "onVerification" option must be a function (https://github.com/octokit/auth-oauth-device.js#usage)');
} // @ts-ignore too much for tsc / ts-jest ¯\_(ツ)_/¯
}
// @ts-ignore too much for tsc / ts-jest ¯\_(ツ)_/¯
return Object.assign(auth.bind(null, state), {

@@ -160,0 +152,0 @@ hook: hook.bind(null, state)

@@ -1,1 +0,1 @@

export const VERSION = "4.0.3";
export const VERSION = "4.0.4";
import { RequestInterface, Route, EndpointOptions, RequestParameters, OctokitResponse } from "@octokit/types";
import * as OAuthMethodsTypes from "@octokit/oauth-methods";
export declare type ClientType = "oauth-app" | "github-app";
export declare type OAuthAppStrategyOptions = {
export type ClientType = "oauth-app" | "github-app";
export type OAuthAppStrategyOptions = {
clientId: string;

@@ -11,3 +11,3 @@ clientType?: "oauth-app";

};
export declare type GitHubAppStrategyOptions = {
export type GitHubAppStrategyOptions = {
clientId: string;

@@ -26,3 +26,3 @@ clientType: "github-app";

}
export declare type OAuthAppAuthOptions = {
export type OAuthAppAuthOptions = {
type: "oauth";

@@ -32,19 +32,19 @@ scopes?: string[];

};
export declare type GitHubAppAuthOptions = {
export type GitHubAppAuthOptions = {
type: "oauth";
refresh?: boolean;
};
export declare type OAuthAppAuthentication = {
export type OAuthAppAuthentication = {
type: "token";
tokenType: "oauth";
} & Omit<OAuthMethodsTypes.OAuthAppAuthentication, "clientSecret">;
export declare type GitHubAppAuthentication = {
export type GitHubAppAuthentication = {
type: "token";
tokenType: "oauth";
} & Omit<OAuthMethodsTypes.GitHubAppAuthentication, "clientSecret">;
export declare type GitHubAppAuthenticationWithExpiration = {
export type GitHubAppAuthenticationWithExpiration = {
type: "token";
tokenType: "oauth";
} & Omit<OAuthMethodsTypes.GitHubAppAuthentication, "clientSecret">;
export declare type Verification = {
export type Verification = {
device_code: string;

@@ -56,4 +56,4 @@ user_code: string;

};
export declare type OnVerificationCallback = (verification: Verification) => any | Promise<any>;
export declare type OAuthAppState = {
export type OnVerificationCallback = (verification: Verification) => any | Promise<any>;
export type OAuthAppState = {
clientId: string;

@@ -66,3 +66,3 @@ clientType: "oauth-app";

};
export declare type GitHubAppState = {
export type GitHubAppState = {
clientId: string;

@@ -69,0 +69,0 @@ clientType: "github-app";

@@ -1,1 +0,1 @@

export declare const VERSION = "4.0.3";
export declare const VERSION = "4.0.4";

@@ -105,3 +105,3 @@ import { getUserAgent } from 'universal-user-agent';

const VERSION = "4.0.3";
const VERSION = "4.0.4";

@@ -108,0 +108,0 @@ function createOAuthDeviceAuth(options) {

{
"name": "@octokit/auth-oauth-device",
"description": "GitHub OAuth Device authentication strategy for JavaScript",
"version": "4.0.3",
"version": "4.0.4",
"license": "MIT",

@@ -22,3 +22,3 @@ "files": [

"@octokit/request": "^6.0.0",
"@octokit/types": "^8.0.0",
"@octokit/types": "^9.0.0",
"universal-user-agent": "^6.0.0"

@@ -33,7 +33,7 @@ },

"@types/jest": "^29.0.0",
"@types/node": "^16.0.0",
"@types/node": "^18.0.0",
"fetch-mock": "^9.11.0",
"jest": "^29.0.0",
"prettier": "2.7.1",
"semantic-release": "^19.0.0",
"prettier": "2.8.3",
"semantic-release": "^20.0.0",
"semantic-release-plugin-update-version-in-files": "^1.1.0",

@@ -40,0 +40,0 @@ "ts-jest": "^29.0.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc