Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@octokit/auth-oauth-user

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 1.0.0 to 1.1.0

20

dist-node/index.js

@@ -95,3 +95,3 @@ 'use strict';

const VERSION = "1.0.0";
const VERSION = "1.1.0";

@@ -148,3 +148,4 @@ async function getAuthentication(state) {

if (!state.authentication) {
state.authentication = await getAuthentication(state);
// This is what TS makes us do ¯\_(ツ)_/¯
state.authentication = state.clientType === "oauth-app" ? await getAuthentication(state) : await getAuthentication(state);
}

@@ -159,4 +160,3 @@

if ("expiresAt" in currentAuthentication) {
if (options.type === "refresh" || // @ts-expect-error TBD
new Date(currentAuthentication.expiresAt) < new Date()) {
if (options.type === "refresh" || new Date(currentAuthentication.expiresAt) < new Date()) {
const {

@@ -168,3 +168,2 @@ authentication

clientSecret: state.clientSecret,
// @ts-expect-error TBD
refreshToken: currentAuthentication.refreshToken,

@@ -210,2 +209,3 @@ request: state.request

}, authentication);
return state.authentication;
} catch (error) {

@@ -221,4 +221,2 @@ // istanbul ignore else

}
return state.authentication;
} // invalidate

@@ -252,6 +250,9 @@

async function hook(state, request, route, parameters = {}) {
// TS makes us do this ¯\_(ツ)_/¯
const {
token
} = await auth(_objectSpread2(_objectSpread2({}, state), {}, {
} = state.clientType === "oauth-app" ? await auth(_objectSpread2(_objectSpread2({}, state), {}, {
request
})) : await auth(_objectSpread2(_objectSpread2({}, state), {}, {
request
}));

@@ -282,5 +283,6 @@ const endpoint = request.endpoint.merge(route, parameters);

request: request$1
}); // @ts-expect-error the extra code is not worth it just to make TS happpy
}); // @ts-expect-error not worth the extra code needed to appease TS
return Object.assign(auth.bind(null, state), {
// @ts-expect-error not worth the extra code needed to appease TS
hook: hook.bind(null, state)

@@ -287,0 +289,0 @@ });

@@ -5,3 +5,7 @@ import { getAuthentication } from "./get-authentication";

if (!state.authentication) {
state.authentication = await getAuthentication(state);
// This is what TS makes us do ¯\_(ツ)_/¯
state.authentication =
state.clientType === "oauth-app"
? await getAuthentication(state)
: await getAuthentication(state);
}

@@ -15,3 +19,2 @@ if (state.authentication.invalid) {

if (options.type === "refresh" ||
// @ts-expect-error TBD
new Date(currentAuthentication.expiresAt) < new Date()) {

@@ -22,3 +25,2 @@ const { authentication } = await refreshToken({

clientSecret: state.clientSecret,
// @ts-expect-error TBD
refreshToken: currentAuthentication.refreshToken,

@@ -61,2 +63,3 @@ request: state.request,

};
return state.authentication;
}

@@ -72,3 +75,2 @@ catch (error) {

}
return state.authentication;
}

@@ -75,0 +77,0 @@ // invalidate

import { auth } from "./auth";
export async function hook(state, request, route, parameters = {}) {
const { token } = await auth({
...state,
request,
});
// TS makes us do this ¯\_(ツ)_/¯
const { token } = state.clientType === "oauth-app"
? await auth({ ...state, request })
: await auth({ ...state, request });
const endpoint = request.endpoint.merge(route, parameters);

@@ -8,0 +8,0 @@ endpoint.headers.authorization = "token " + token;

@@ -18,4 +18,5 @@ import { getUserAgent } from "universal-user-agent";

});
// @ts-expect-error the extra code is not worth it just to make TS happpy
// @ts-expect-error not worth the extra code needed to appease TS
return Object.assign(auth.bind(null, state), {
// @ts-expect-error not worth the extra code needed to appease TS
hook: hook.bind(null, state),

@@ -22,0 +23,0 @@ });

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

export const VERSION = "1.0.0";
export const VERSION = "1.1.0";

@@ -1,2 +0,3 @@

import { AuthOptions, Authentication, State, ClientType } from "./types";
export declare function auth<TClientType extends ClientType>(state: State, options?: AuthOptions): Promise<Authentication<TClientType>>;
import { OAuthAppAuthOptions, GitHubAppAuthOptions, OAuthAppAuthentication, GitHubAppAuthentication, GitHubAppAuthenticationWithExpiration, OAuthAppState, GitHubAppState } from "./types";
export declare function auth(state: OAuthAppState, options?: OAuthAppAuthOptions): Promise<OAuthAppAuthentication>;
export declare function auth(state: GitHubAppState, options?: GitHubAppAuthOptions): Promise<GitHubAppAuthentication | GitHubAppAuthenticationWithExpiration>;

@@ -1,2 +0,3 @@

import { State, ClientType, Authentication } from "./types";
export declare function getAuthentication<TClientType extends ClientType>(state: State): Promise<Authentication<TClientType>>;
import { OAuthAppState, GitHubAppState, OAuthAppAuthentication, GitHubAppAuthentication, GitHubAppAuthenticationWithExpiration } from "./types";
export declare function getAuthentication(state: OAuthAppState): Promise<OAuthAppAuthentication>;
export declare function getAuthentication(state: GitHubAppState): Promise<GitHubAppAuthentication | GitHubAppAuthenticationWithExpiration>;
import { EndpointOptions, OctokitResponse, RequestInterface, RequestParameters, Route } from "@octokit/types";
import { State } from "./types";
import { OAuthAppState, GitHubAppState } from "./types";
declare type AnyResponse = OctokitResponse<any>;
export declare function hook(state: State, request: RequestInterface, route: Route | EndpointOptions, parameters?: RequestParameters): Promise<AnyResponse>;
export declare function hook(state: OAuthAppState, request: RequestInterface, route: Route | EndpointOptions, parameters: RequestParameters): Promise<AnyResponse>;
export declare function hook(state: GitHubAppState, request: RequestInterface, route: Route | EndpointOptions, parameters: RequestParameters): Promise<AnyResponse>;
export {};

@@ -1,5 +0,10 @@

import { StrategyOptions, ClientType, AuthInterface } from "./types";
export declare function createOAuthUserAuth<TClientType extends ClientType = "oauth-app">({ clientId, clientSecret, clientType, request, ...strategyOptions }: StrategyOptions<TClientType>): AuthInterface<TClientType>;
import { OAuthAppStrategyOptions, GitHubAppStrategyOptions, OAuthAppAuthInterface, GitHubAppAuthInterface } from "./types";
export { OAuthAppStrategyOptionsWebFlow, GitHubAppStrategyOptionsWebFlow, OAuthAppStrategyOptionsDeviceFlow, GitHubAppStrategyOptionsDeviceFlow, OAuthAppStrategyOptionsExistingAuthentication, GitHubAppStrategyOptionsExistingAuthentication, GitHubAppStrategyOptionsExistingAuthenticationWithExpiration, OAuthAppStrategyOptions, GitHubAppStrategyOptions, OAuthAppAuthOptions, GitHubAppAuthOptions, OAuthAppAuthentication, GitHubAppAuthentication, GitHubAppAuthenticationWithExpiration, } from "./types";
export declare function createOAuthUserAuth(options: OAuthAppStrategyOptions): OAuthAppAuthInterface;
export declare namespace createOAuthUserAuth {
var VERSION: string;
}
export declare function createOAuthUserAuth(options: GitHubAppStrategyOptions): GitHubAppAuthInterface;
export declare namespace createOAuthUserAuth {
var VERSION: string;
}

@@ -5,8 +5,2 @@ import * as OctokitTypes from "@octokit/types";

export declare type ClientType = "oauth-app" | "github-app";
declare type CommonStrategyOptions<TClientType extends ClientType> = {
clientType?: TClientType;
clientId: string;
clientSecret: string;
request?: OctokitTypes.RequestInterface;
};
export declare type WebFlowOptions = {

@@ -17,7 +11,23 @@ code: string;

};
declare type DeviceFlowOptions = {
declare type CommonOAuthAppStrategyOptions = {
clientType?: "oauth-app";
clientId: string;
clientSecret: string;
request?: OctokitTypes.RequestInterface;
};
declare type CommonGitHubAppStrategyOptions = {
clientType?: "github-app";
clientId: string;
clientSecret: string;
request?: OctokitTypes.RequestInterface;
};
declare type OAuthAppDeviceFlowOptions = {
onVerification: DeviceTypes.OAuthAppStrategyOptions["onVerification"];
scopes?: string[];
};
declare type GitHubDeviceFlowOptions = {
onVerification: DeviceTypes.OAuthAppStrategyOptions["onVerification"];
};
declare type ExistingOAuthAppAuthenticationOptions = {
clientType: "oauth-app";
token: string;

@@ -35,24 +45,32 @@ scopes: string[];

};
export interface AuthInterface<TClientType extends ClientType> {
(options?: AuthOptions): Promise<Authentication<TClientType>>;
export declare type OAuthAppStrategyOptionsWebFlow = CommonOAuthAppStrategyOptions & WebFlowOptions;
export declare type GitHubAppStrategyOptionsWebFlow = CommonGitHubAppStrategyOptions & WebFlowOptions;
export declare type OAuthAppStrategyOptionsDeviceFlow = CommonOAuthAppStrategyOptions & OAuthAppDeviceFlowOptions;
export declare type GitHubAppStrategyOptionsDeviceFlow = CommonGitHubAppStrategyOptions & GitHubDeviceFlowOptions;
export declare type OAuthAppStrategyOptionsExistingAuthentication = CommonOAuthAppStrategyOptions & ExistingOAuthAppAuthenticationOptions;
export declare type GitHubAppStrategyOptionsExistingAuthentication = CommonGitHubAppStrategyOptions & ExistingGitHubAppAuthenticationOptions;
export declare type GitHubAppStrategyOptionsExistingAuthenticationWithExpiration = CommonGitHubAppStrategyOptions & ExistingGitHubAppAuthenticationWithExpirationOptions;
export declare type OAuthAppStrategyOptions = OAuthAppStrategyOptionsWebFlow | OAuthAppStrategyOptionsDeviceFlow | OAuthAppStrategyOptionsExistingAuthentication;
export declare type GitHubAppStrategyOptions = GitHubAppStrategyOptionsWebFlow | GitHubAppStrategyOptionsDeviceFlow | GitHubAppStrategyOptionsExistingAuthentication | GitHubAppStrategyOptionsExistingAuthenticationWithExpiration;
export declare type OAuthAppAuthentication = {
tokenType: "oauth";
type: "token";
} & OAuthMethodsTypes.OAuthAppAuthentication;
export declare type GitHubAppAuthentication = {
tokenType: "oauth";
type: "token";
} & OAuthMethodsTypes.GitHubAppAuthentication;
export declare type GitHubAppAuthenticationWithExpiration = {
tokenType: "oauth";
type: "token";
} & OAuthMethodsTypes.GitHubAppAuthenticationWithExpiration;
export interface OAuthAppAuthInterface {
(options?: OAuthAppAuthOptions): Promise<OAuthAppAuthentication>;
hook(request: OctokitTypes.RequestInterface, route: OctokitTypes.Route | OctokitTypes.EndpointOptions, parameters?: OctokitTypes.RequestParameters): Promise<OctokitTypes.OctokitResponse<any>>;
}
export declare type StrategyOptionsExistingOAuthAppAuthentication = CommonStrategyOptions<"oauth-app"> & ExistingOAuthAppAuthenticationOptions & {
clientType: "oauth-app";
};
export declare type StrategyOptionsExistingGitHubAppAuthentication = CommonStrategyOptions<"github-app"> & ExistingGitHubAppAuthenticationOptions & {
clientType: "github-app";
};
export declare type StrategyOptionsExistingGitHubAppAuthenticationWithExpiration = CommonStrategyOptions<"github-app"> & ExistingGitHubAppAuthenticationWithExpirationOptions & {
clientType: "github-app";
};
declare type StrategyOptionsWebFlow<TClientType extends ClientType> = CommonStrategyOptions<TClientType> & WebFlowOptions;
declare type StrategyOptionsDeviceFlow<TClientType extends ClientType> = CommonStrategyOptions<TClientType> & DeviceFlowOptions;
declare type StrategyOptionsExistingAuthentication<TClientType extends ClientType> = TClientType extends "oauth-app" ? StrategyOptionsExistingOAuthAppAuthentication : StrategyOptionsExistingGitHubAppAuthentication | StrategyOptionsExistingGitHubAppAuthenticationWithExpiration;
export declare type StrategyOptions<TClientType extends ClientType = "oauth-app"> = StrategyOptionsWebFlow<TClientType> | StrategyOptionsDeviceFlow<TClientType> | StrategyOptionsExistingAuthentication<TClientType>;
export declare type Authentication<TClientType extends ClientType> = {
tokenType: "oauth";
type: "token";
} & (TClientType extends "oauth-app" ? OAuthMethodsTypes.OAuthAppAuthentication : OAuthMethodsTypes.GitHubAppAuthentication | OAuthMethodsTypes.GitHubAppAuthenticationWithExpiration);
declare type OAuthAppState = {
export interface GitHubAppAuthInterface {
(options?: GitHubAppAuthOptions): Promise<GitHubAppAuthentication>;
hook(request: OctokitTypes.RequestInterface, route: OctokitTypes.Route | OctokitTypes.EndpointOptions, parameters?: OctokitTypes.RequestParameters): Promise<OctokitTypes.OctokitResponse<any>>;
}
export declare type OAuthAppState = {
clientId: string;

@@ -62,8 +80,14 @@ clientSecret: string;

request: OctokitTypes.RequestInterface;
strategyOptions: WebFlowOptions | DeviceFlowOptions | ExistingOAuthAppAuthenticationOptions;
authentication?: Authentication<"oauth-app"> & {
strategyOptions: WebFlowOptions | OAuthAppDeviceFlowOptions | ExistingOAuthAppAuthenticationOptions;
authentication?: OAuthAppAuthentication & {
invalid?: true;
};
};
declare type GitHubAppState = {
declare type GitHubAppStateAuthentication = GitHubAppAuthentication & {
invalid?: true;
};
declare type GitHubAppStateAuthenticationWIthExpiration = GitHubAppAuthenticationWithExpiration & {
invalid?: true;
};
export declare type GitHubAppState = {
clientId: string;

@@ -73,6 +97,4 @@ clientSecret: string;

request: OctokitTypes.RequestInterface;
strategyOptions: WebFlowOptions | DeviceFlowOptions | ExistingGitHubAppAuthenticationOptions | ExistingGitHubAppAuthenticationWithExpirationOptions;
authentication?: Authentication<"github-app"> & {
invalid?: true;
};
strategyOptions: WebFlowOptions | GitHubDeviceFlowOptions | ExistingGitHubAppAuthenticationOptions | ExistingGitHubAppAuthenticationWithExpirationOptions;
authentication?: GitHubAppStateAuthentication | GitHubAppStateAuthenticationWIthExpiration;
};

@@ -87,5 +109,8 @@ export declare type State = OAuthAppState | GitHubAppState;

};
export declare type AuthOptions = {
export declare type OAuthAppAuthOptions = {
type?: "check" | "reset" | "delete" | "deleteAuthorization";
};
export declare type GitHubAppAuthOptions = {
type?: "check" | "reset" | "refresh" | "delete" | "deleteAuthorization";
};
export {};

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

export declare const VERSION = "1.0.0";
export declare const VERSION = "1.1.0";

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

const VERSION = "1.0.0";
const VERSION = "1.1.0";

@@ -58,3 +58,7 @@ // @ts-nocheck there is only place for one of us in this file. And it's not you, TS

if (!state.authentication) {
state.authentication = await getAuthentication(state);
// This is what TS makes us do ¯\_(ツ)_/¯
state.authentication =
state.clientType === "oauth-app"
? await getAuthentication(state)
: await getAuthentication(state);
}

@@ -68,3 +72,2 @@ if (state.authentication.invalid) {

if (options.type === "refresh" ||
// @ts-expect-error TBD
new Date(currentAuthentication.expiresAt) < new Date()) {

@@ -75,3 +78,2 @@ const { authentication } = await refreshToken({

clientSecret: state.clientSecret,
// @ts-expect-error TBD
refreshToken: currentAuthentication.refreshToken,

@@ -114,2 +116,3 @@ request: state.request,

};
return state.authentication;
}

@@ -125,3 +128,2 @@ catch (error) {

}
return state.authentication;
}

@@ -153,6 +155,6 @@ // invalidate

async function hook(state, request, route, parameters = {}) {
const { token } = await auth({
...state,
request,
});
// TS makes us do this ¯\_(ツ)_/¯
const { token } = state.clientType === "oauth-app"
? await auth({ ...state, request })
: await auth({ ...state, request });
const endpoint = request.endpoint.merge(route, parameters);

@@ -175,4 +177,5 @@ endpoint.headers.authorization = "token " + token;

});
// @ts-expect-error the extra code is not worth it just to make TS happpy
// @ts-expect-error not worth the extra code needed to appease TS
return Object.assign(auth.bind(null, state), {
// @ts-expect-error not worth the extra code needed to appease TS
hook: hook.bind(null, state),

@@ -179,0 +182,0 @@ });

{
"name": "@octokit/auth-oauth-user",
"description": "Octokit authentication strategy for OAuth clients",
"version": "1.0.0",
"version": "1.1.0",
"license": "MIT",

@@ -6,0 +6,0 @@ "files": [

@@ -31,2 +31,3 @@ # auth-oauth-user.js

- [`auth.hook(request, route, parameters)` or `auth.hook(request, options)`](#authhookrequest-route-parameters-or-authhookrequest-options)
- [Types](#types)
- [Contributing](#contributing)

@@ -981,2 +982,23 @@ - [License](#license)

## Types
```ts
import {
GitHubAppAuthentication,
GitHubAppAuthenticationWithExpiration,
GitHubAppAuthOptions,
GitHubAppStrategyOptions,
GitHubAppStrategyOptionsDeviceFlow,
GitHubAppStrategyOptionsExistingAuthentication,
GitHubAppStrategyOptionsExistingAuthenticationWithExpiration,
GitHubAppStrategyOptionsWebFlow,
OAuthAppAuthentication,
OAuthAppAuthOptions,
OAuthAppStrategyOptions,
OAuthAppStrategyOptionsDeviceFlow,
OAuthAppStrategyOptionsExistingAuthentication,
OAuthAppStrategyOptionsWebFlow,
} from "@octokit/auth-oauth-user";
```
## Contributing

@@ -983,0 +1005,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