From 0d12531ffec18dfca4d90b1374da3085f472aa5c Mon Sep 17 00:00:00 2001 From: Julian Hundeloh Date: Tue, 17 Dec 2019 19:06:32 +0100 Subject: [PATCH] [simple-oauth2] fix: allow custom fields (#40797) * fix: allow custom fields * test: add test --- types/simple-oauth2/index.d.ts | 6 ++++++ types/simple-oauth2/simple-oauth2-tests.ts | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/types/simple-oauth2/index.d.ts b/types/simple-oauth2/index.d.ts index 0cec5a0773..a04a41647b 100644 --- a/types/simple-oauth2/index.d.ts +++ b/types/simple-oauth2/index.d.ts @@ -72,6 +72,8 @@ export interface AccessToken { export type AuthorizationCode = string; export interface AuthorizationTokenConfig { + [key: string]: any; + /** Authorization code (from previous step) */ code: AuthorizationCode; /** A string that represents the callback uri */ @@ -81,6 +83,8 @@ export interface AuthorizationTokenConfig { } export interface PasswordTokenConfig { + [key: string]: any; + /** A string that represents the registered username */ username: string; /** A string that represents the registered password. */ @@ -90,6 +94,8 @@ export interface PasswordTokenConfig { } export interface ClientCredentialTokenConfig { + [key: string]: any; + /** A string that represents the application privileges */ scope?: string | string[]; } diff --git a/types/simple-oauth2/simple-oauth2-tests.ts b/types/simple-oauth2/simple-oauth2-tests.ts index c33564b7cd..7880c0225a 100644 --- a/types/simple-oauth2/simple-oauth2-tests.ts +++ b/types/simple-oauth2/simple-oauth2-tests.ts @@ -143,3 +143,21 @@ const oauth2 = oauth2lib.create(credentials); // // => { "status": "401", "message": "Unauthorized" } // })(); + +// #Custom Grant +(async () => { + const tokenConfig = { + username: 'username', + password: 'password', + scope: [ '', '' ], + grant_type: 'openapi_2lo' + }; + + // Save the access token + try { + const result = await oauth2.ownerPassword.getToken(tokenConfig); + const accessToken = oauth2.accessToken.create(result); + } catch (error) { + console.log('Access Token Error', error.message); + } +})();