From c21ee1885d6cb5b09ef457ef164117695ee8dffa Mon Sep 17 00:00:00 2001 From: Bert Verhelst Date: Tue, 5 Nov 2019 01:35:00 +0100 Subject: [PATCH] [simple-oauth2] Allow http options for getToken (#39940) * [simple-oauth2] Allow http options for getToken According to the docs of simple-oauth2 the getToken function optionally accepts an httpOptions object: https://www.npmjs.com/package/simple-oauth2#authorization-code-flow ``` // Optional per-call http options const httpOptions = {}; // Save the access token try { const result = await oauth2.authorizationCode.getToken(tokenConfig, httpOptions); const accessToken = oauth2.accessToken.create(result); } catch (error) { console.log('Access Token Error', error.message); } ``` * [simple-oauth2] Allow scope in getToken config According to the docs of simple-oauth2 a scope property is allowed: https://www.npmjs.com/package/simple-oauth2#authorization-code-flow ``` // Get the access token object (the authorization code is given from the previous step). const tokenConfig = { code: '', redirect_uri: 'http://localhost:3000/callback', scope: '', // also can be an array of multiple scopes, ex. [', '', '...'] }; // Optional per-call http options const httpOptions = {}; // Save the access token try { const result = await oauth2.authorizationCode.getToken(tokenConfig, httpOptions); const accessToken = oauth2.accessToken.create(result); } catch (error) { console.log('Access Token Error', error.message); } ``` * [simple-oauth2] Fix missing type for scope * [simple-oauth2] Add http options to all func * [simple-oauth2] Update interface for WreckHttpOptions * [simple-oauth2] bump version to trigger rebuild * [simple-oauth2] Fix build errors Error in simple-oauth2 Error: /home/travis/build/DefinitelyTyped/DefinitelyTyped/types/simple-oauth2/index.d.ts:1:25 ERROR: 1:25 dt-header Error parsing header. Expected: foo MAJOR.MINOR (patch version not allowed). See: https://github.com/Microsoft/dtslint/blob/master/docs/dt-header.md ERROR: 97:11 strict-export-declare-modifiers All declarations in this module are exported automatically. Prefer to explicitly write 'export' for clarity. If you have a good reason not to export this declaration, add 'export {}' to the module to shut off automatic exporting. See: https://github.com/Microsoft/dtslint/blob/master/docs/strict-export-declare-modifiers.md ERROR: 99:13 typedef-whitespace expected nospace before colon in property-declaration ERROR: 110:10 no-any-union Including `any` in a union will override all other members of the union. See: https://github.com/Microsoft/dtslint/blob/master/docs/no-any-union.md --- types/simple-oauth2/index.d.ts | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/types/simple-oauth2/index.d.ts b/types/simple-oauth2/index.d.ts index 8091a56f2d..8c60a38139 100644 --- a/types/simple-oauth2/index.d.ts +++ b/types/simple-oauth2/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for simple-oauth2 2.2 +// Type definitions for simple-oauth2 2.5 // Project: https://github.com/lelylan/simple-oauth2 // Definitions by: Michael Müller , // Troy Lamerton @@ -76,6 +76,8 @@ export interface AuthorizationTokenConfig { code: AuthorizationCode; /** A string that represents the callback uri */ redirect_uri: string; + /** A string or array of strings that represents the application privileges */ + scope: string | string[]; } export interface PasswordTokenConfig { @@ -92,6 +94,27 @@ export interface ClientCredentialTokenConfig { scope?: string | string[]; } +export interface WreckHttpOptions { + baseUrl?: string; + socketPath?: string; + payload?: any; + headers?: { [key: string]: any }; + redirects?: number; + redirect303?: boolean; + beforeRedirect?: (redirectMethod: string, statusCode: number, location: string, resHeaders: { [key: string]: any }, redirectOptions: any, next: () => {}) => void; + redirected?: (statusCode: number, location: string, req: any) => void; + timeout?: number; + maxBytes?: number; + rejectUnauthorized?: boolean; + downstreamRes?: any; + agent?: any; + secureProtocol?: string; + ciphers?: string; + events?: boolean; + json?: true | "strict" | "force"; + gunzip?: boolean | "force"; +} + export interface OAuthClient { authorizationCode: { /** @@ -113,21 +136,21 @@ export interface OAuthClient { ): string, /** Returns the Access Token object */ - getToken(params: AuthorizationTokenConfig): Promise; + getToken(params: AuthorizationTokenConfig, httpOptions?: WreckHttpOptions): Promise; }; ownerPassword: { /** Returns the Access Token Object */ - getToken(params: PasswordTokenConfig): Promise; + getToken(params: PasswordTokenConfig, httpOptions?: WreckHttpOptions): Promise; }; clientCredentials: { /** Returns the Access Token Object */ - getToken(params: ClientCredentialTokenConfig): Promise; + getToken(params: ClientCredentialTokenConfig, httpOptions?: WreckHttpOptions): Promise; }; accessToken: { /** Creates an OAuth2.AccessToken instance */ - create(tokenToUse: Token): AccessToken; + create(tokenToUse: Token, httpOptions?: WreckHttpOptions): AccessToken; }; }