diff --git a/types/simple-oauth2/index.d.ts b/types/simple-oauth2/index.d.ts index 19a1ff2698..8091a56f2d 100644 --- a/types/simple-oauth2/index.d.ts +++ b/types/simple-oauth2/index.d.ts @@ -3,13 +3,14 @@ // Definitions by: Michael Müller , // Troy Lamerton // Martín Rodriguez +// Linus Unnebäck // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.9 /** Creates a new simple-oauth2 client with the passed configuration */ -export function create(options: ModuleOptions): OAuthClient; +export function create(options: ModuleOptions): OAuthClient; -export interface ModuleOptions { +export interface ModuleOptions { client: { /** Service registered client id. Required. */ id: string, @@ -18,7 +19,7 @@ export interface ModuleOptions { /** Parameter name used to send the client secret. Default to client_secret. */ secretParamName?: string, /** Parameter name used to send the client id. Default to client_id. */ - idParamName?: string + idParamName?: ClientIdName }; auth: { /** String used to set the host to request the tokens to. Required. */ @@ -91,7 +92,7 @@ export interface ClientCredentialTokenConfig { scope?: string | string[]; } -export interface OAuthClient { +export interface OAuthClient { authorizationCode: { /** * Redirect the user to the autorization page @@ -99,8 +100,8 @@ export interface OAuthClient { */ authorizeURL( params?: { - /** A key-value pair where key is ModuleOptions#client.idParamName and the value represents the Client-ID */ - [ idParamName: string ]: string | undefined + /** A string that represents the Client-ID */ + [key in ClientIdName]?: string } & { /** A string that represents the registered application URI where the user is redirected after authentication */ redirect_uri?: string, diff --git a/types/simple-oauth2/simple-oauth2-tests.ts b/types/simple-oauth2/simple-oauth2-tests.ts index e066ad41c0..c33564b7cd 100644 --- a/types/simple-oauth2/simple-oauth2-tests.ts +++ b/types/simple-oauth2/simple-oauth2-tests.ts @@ -17,6 +17,12 @@ const credentials: oauth2lib.ModuleOptions = { const oauth2 = oauth2lib.create(credentials); +// Test custom `idParamName` +{ + const oauth2 = oauth2lib.create({ client: { id: 'x', secret: 'x', idParamName: 'foobar' }, auth: { tokenHost: 'x' } }); + oauth2.authorizationCode.authorizeURL({ foobar: 'x' }); +} + // #Authorization Code flow (async () => { // Authorization oauth2 URI @@ -26,6 +32,12 @@ const oauth2 = oauth2lib.create(credentials); state: '' }); + oauth2.authorizationCode.authorizeURL({ + redirect_uri: 'http://localhost:3000/callback', + scope: ['', ''], + state: '' + }); + // Redirect example using Express (see http://expressjs.com/api.html#res.redirect) // res.redirect(authorizationUri);