[simple-oauth2] fix: allow custom fields (#40797)

* fix: allow custom fields

* test: add test
This commit is contained in:
Julian Hundeloh
2019-12-17 10:06:32 -08:00
committed by Nathan Shively-Sanders
parent a1708a1b80
commit 0d12531ffe
2 changed files with 24 additions and 0 deletions
+6
View File
@@ -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[];
}
@@ -143,3 +143,21 @@ const oauth2 = oauth2lib.create(credentials);
// // => { "status": "401", "message": "Unauthorized" }
// })();
// #Custom Grant
(async () => {
const tokenConfig = {
username: 'username',
password: 'password',
scope: [ '<scope1>', '<scope2>' ],
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);
}
})();