From b85b3f1459c4feee6306cf9ca7611c4273782622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20N=C3=A5rstad?= Date: Mon, 25 Dec 2017 19:22:49 +0100 Subject: [PATCH] Add audience field for oauth2 client credentials (#679) --- .../insomnia-app/app/network/o-auth-2/constants.js | 1 + .../insomnia-app/app/network/o-auth-2/get-token.js | 3 ++- .../network/o-auth-2/grant-client-credentials.js | 4 +++- .../ui/components/editors/auth/o-auth-2-auth.js | 14 +++++++++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/insomnia-app/app/network/o-auth-2/constants.js b/packages/insomnia-app/app/network/o-auth-2/constants.js index e60ad0b64..2a6969a7f 100644 --- a/packages/insomnia-app/app/network/o-auth-2/constants.js +++ b/packages/insomnia-app/app/network/o-auth-2/constants.js @@ -10,6 +10,7 @@ export const RESPONSE_TYPE_TOKEN = 'token'; export const P_ACCESS_TOKEN = 'access_token'; export const P_CLIENT_ID = 'client_id'; export const P_CLIENT_SECRET = 'client_secret'; +export const P_AUDIENCE = 'audience'; export const P_CODE = 'code'; export const P_ERROR = 'error'; export const P_ERROR_DESCRIPTION = 'error_description'; diff --git a/packages/insomnia-app/app/network/o-auth-2/get-token.js b/packages/insomnia-app/app/network/o-auth-2/get-token.js index 1545e88e4..4389e37c2 100644 --- a/packages/insomnia-app/app/network/o-auth-2/get-token.js +++ b/packages/insomnia-app/app/network/o-auth-2/get-token.js @@ -72,7 +72,8 @@ async function _getOAuth2ClientCredentialsHeader ( authentication.credentialsInBody, authentication.clientId, authentication.clientSecret, - authentication.scope + authentication.scope, + authentication.audience ); return _updateOAuth2Token(requestId, results); diff --git a/packages/insomnia-app/app/network/o-auth-2/grant-client-credentials.js b/packages/insomnia-app/app/network/o-auth-2/grant-client-credentials.js index 9e7ff5919..5f17905cd 100644 --- a/packages/insomnia-app/app/network/o-auth-2/grant-client-credentials.js +++ b/packages/insomnia-app/app/network/o-auth-2/grant-client-credentials.js @@ -12,7 +12,8 @@ export default async function ( credentialsInBody: boolean, clientId: string, clientSecret: string, - scope: string = '' + scope: string = '', + audience: string = '' ): Promise { const params = [ {name: c.P_GRANT_TYPE, value: c.GRANT_TYPE_CLIENT_CREDENTIALS} @@ -20,6 +21,7 @@ export default async function ( // Add optional params scope && params.push({name: c.P_SCOPE, value: scope}); + audience && params.push({name: c.P_AUDIENCE, value: audience}); const headers = [ {name: 'Content-Type', value: 'application/x-www-form-urlencoded'}, diff --git a/packages/insomnia-app/app/ui/components/editors/auth/o-auth-2-auth.js b/packages/insomnia-app/app/ui/components/editors/auth/o-auth-2-auth.js index c0e3748ef..474e55871 100644 --- a/packages/insomnia-app/app/ui/components/editors/auth/o-auth-2-auth.js +++ b/packages/insomnia-app/app/ui/components/editors/auth/o-auth-2-auth.js @@ -159,6 +159,10 @@ class OAuth2Auth extends React.PureComponent { this._handleChangeProperty('tokenPrefix', value); } + _handleChangeAudience (value: string): void { + this._handleChangeProperty('audience', value); + } + _handleChangeGrantType (e: SyntheticEvent): void { trackEvent('OAuth 2', 'Change Grant Type', e.currentTarget.value); this._handleChangeProperty('grantType', e.currentTarget.value); @@ -306,6 +310,13 @@ class OAuth2Auth extends React.PureComponent { 'Change Authorization header prefix from Bearer to something else' ); + const audience = this.renderInputRow( + 'Audience', + 'audience', + this._handleChangeAudience, + 'Indicate what resource server to access' + ); + const credentialsInBody = this.renderSelectRow( 'Credentials', 'credentialsInBody', @@ -342,7 +353,8 @@ class OAuth2Auth extends React.PureComponent { advancedFields = [ scope, credentialsInBody, - tokenPrefix + tokenPrefix, + audience ]; } else if (grantType === GRANT_TYPE_PASSWORD) { basicFields = [