diff --git a/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-authorization-code.test.js b/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-authorization-code.test.js index b94aa449ba..75697e394a 100644 --- a/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-authorization-code.test.js +++ b/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-authorization-code.test.js @@ -14,6 +14,8 @@ const CLIENT_SECRET = 'secret_12345456677756343'; const REDIRECT_URI = 'https://foo.com/redirect'; const SCOPE = 'scope_123'; const STATE = 'state_123'; +const AUDIENCE = 'https://foo.com/resource'; +const RESOURCE = 'foo.com'; describe('authorization_code', () => { beforeEach(globalBeforeEach); @@ -27,6 +29,8 @@ describe('authorization_code', () => { access_token: 'token_123', token_type: 'token_type', scope: SCOPE, + audience: AUDIENCE, + resource: RESOURCE, }), ); @@ -48,6 +52,8 @@ describe('authorization_code', () => { REDIRECT_URI, SCOPE, STATE, + AUDIENCE, + RESOURCE, ); // Check the request to fetch the token @@ -64,6 +70,8 @@ describe('authorization_code', () => { { name: 'code', value: 'code_123' }, { name: 'redirect_uri', value: REDIRECT_URI }, { name: 'state', value: STATE }, + { name: 'audience', value: AUDIENCE }, + { name: 'resource', value: RESOURCE }, ], }, headers: [ @@ -91,6 +99,8 @@ describe('authorization_code', () => { expires_in: null, token_type: 'token_type', scope: SCOPE, + audience: AUDIENCE, + resource: RESOURCE, error: null, error_uri: null, error_description: null, @@ -108,6 +118,8 @@ describe('authorization_code', () => { access_token: 'token_123', token_type: 'token_type', scope: SCOPE, + audience: AUDIENCE, + resource: RESOURCE, }), ); @@ -129,6 +141,8 @@ describe('authorization_code', () => { REDIRECT_URI, SCOPE, STATE, + AUDIENCE, + RESOURCE, ); // Check the request to fetch the token @@ -145,6 +159,8 @@ describe('authorization_code', () => { { name: 'code', value: 'code_123' }, { name: 'redirect_uri', value: REDIRECT_URI }, { name: 'state', value: STATE }, + { name: 'audience', value: AUDIENCE }, + { name: 'resource', value: RESOURCE }, { name: 'client_id', value: CLIENT_ID }, { name: 'client_secret', value: CLIENT_SECRET }, ], @@ -170,6 +186,8 @@ describe('authorization_code', () => { expires_in: null, token_type: 'token_type', scope: SCOPE, + audience: AUDIENCE, + resource: RESOURCE, error: null, error_uri: null, error_description: null, 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 29b1f0ae59..e8756c55fc 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 @@ -63,6 +63,8 @@ async function _getOAuth2AuthorizationCodeHeader( authentication.redirectUrl, authentication.scope, authentication.state, + authentication.audience, + authentication.resource, ); return _updateOAuth2Token(requestId, results); diff --git a/packages/insomnia-app/app/network/o-auth-2/grant-authorization-code.js b/packages/insomnia-app/app/network/o-auth-2/grant-authorization-code.js index 0e6dee7d35..76de98c023 100644 --- a/packages/insomnia-app/app/network/o-auth-2/grant-authorization-code.js +++ b/packages/insomnia-app/app/network/o-auth-2/grant-authorization-code.js @@ -18,6 +18,8 @@ export default async function( redirectUri: string = '', scope: string = '', state: string = '', + audience: string = '', + resource: string = '', ): Promise { if (!authorizeUrl) { throw new Error('Invalid authorization URL'); @@ -27,7 +29,15 @@ export default async function( throw new Error('Invalid access token URL'); } - const authorizeResults = await _authorize(authorizeUrl, clientId, redirectUri, scope, state); + const authorizeResults = await _authorize( + authorizeUrl, + clientId, + redirectUri, + scope, + state, + audience, + resource, + ); // Handle the error if (authorizeResults[c.P_ERROR]) { @@ -46,10 +56,20 @@ export default async function( authorizeResults[c.P_CODE], redirectUri, state, + audience, + resource, ); } -async function _authorize(url, clientId, redirectUri = '', scope = '', state = '') { +async function _authorize( + url, + clientId, + redirectUri = '', + scope = '', + state = '', + audience = '', + resource = '', +) { const params = [ { name: c.P_RESPONSE_TYPE, value: c.RESPONSE_TYPE_CODE }, { name: c.P_CLIENT_ID, value: clientId }, @@ -59,6 +79,8 @@ async function _authorize(url, clientId, redirectUri = '', scope = '', state = ' redirectUri && params.push({ name: c.P_REDIRECT_URI, value: redirectUri }); scope && params.push({ name: c.P_SCOPE, value: scope }); state && params.push({ name: c.P_STATE, value: state }); + audience && params.push({ name: c.P_AUDIENCE, value: audience }); + resource && params.push({ name: c.P_RESOURCE, value: resource }); // Add query params to URL const qs = buildQueryStringFromParams(params); @@ -89,6 +111,8 @@ async function _getToken( code: string, redirectUri: string = '', state: string = '', + audience: string = '', + resource: string = '', ): Promise { const params = [ { name: c.P_GRANT_TYPE, value: c.GRANT_TYPE_AUTHORIZATION_CODE }, @@ -98,6 +122,8 @@ async function _getToken( // Add optional params redirectUri && params.push({ name: c.P_REDIRECT_URI, value: redirectUri }); state && params.push({ name: c.P_STATE, value: state }); + audience && params.push({ name: c.P_AUDIENCE, value: audience }); + resource && params.push({ name: c.P_RESOURCE, value: resource }); const headers = [ { name: 'Content-Type', value: 'application/x-www-form-urlencoded' }, @@ -145,6 +171,8 @@ async function _getToken( c.P_EXPIRES_IN, c.P_TOKEN_TYPE, c.P_SCOPE, + c.P_AUDIENCE, + c.P_RESOURCE, c.P_ERROR, c.P_ERROR_URI, c.P_ERROR_DESCRIPTION, 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 7b0e08956e..1332d6fa4c 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 @@ -425,7 +425,7 @@ class OAuth2Auth extends React.PureComponent { enabled, ]; - advancedFields = [scope, state, credentialsInBody, tokenPrefix]; + advancedFields = [scope, state, credentialsInBody, tokenPrefix, audience, resource]; } else if (grantType === GRANT_TYPE_CLIENT_CREDENTIALS) { basicFields = [accessTokenUrl, clientId, clientSecret, enabled];