diff --git a/packages/insomnia-app/app/network/o-auth-2/misc.js b/packages/insomnia-app/app/network/o-auth-2/misc.js index d579c9284a..51c28199e5 100644 --- a/packages/insomnia-app/app/network/o-auth-2/misc.js +++ b/packages/insomnia-app/app/network/o-auth-2/misc.js @@ -33,7 +33,6 @@ export function authorizeUserInWindow ( ) { return new Promise((resolve, reject) => { let finalUrl = null; - let hasError = false; function _parseUrl (currentUrl) { if (currentUrl.match(urlSuccessRegex)) { diff --git a/packages/insomnia-app/app/templating/base-extension.js b/packages/insomnia-app/app/templating/base-extension.js index 8a6ee358d9..2434ab43dc 100644 --- a/packages/insomnia-app/app/templating/base-extension.js +++ b/packages/insomnia-app/app/templating/base-extension.js @@ -79,6 +79,7 @@ export default class BaseExtension { models: { request: {getById: models.request.getById}, workspace: {getById: models.workspace.getById}, + oAuth2Token: {getByRequestId: models.oAuth2Token.getByParentId}, cookieJar: { getOrCreateForWorkspace: workspace => { return models.cookieJar.getOrCreateForParentId(workspace._id); diff --git a/plugins/insomnia-plugin-request/index.js b/plugins/insomnia-plugin-request/index.js index 80020c1c11..3a28cbfc4f 100644 --- a/plugins/insomnia-plugin-request/index.js +++ b/plugins/insomnia-plugin-request/index.js @@ -12,12 +12,13 @@ module.exports.templateTags = [{ options: [ {displayName: 'URL', value: 'url', description: 'fully qualified URL'}, {displayName: 'Cookie', value: 'cookie', description: 'cookie value by name'}, - {displayName: 'Header', value: 'header', description: 'header value by name'} + {displayName: 'Header', value: 'header', description: 'header value by name'}, + {displayName: 'OAuth 2.0 Token', value: 'oauth2', description: 'access token'} ] }, { type: 'string', - hide: args => ['url'].includes(args[0].value), + hide: args => ['url', 'oauth2'].includes(args[0].value), displayName: args => { switch (args[0].value) { case 'cookie': @@ -82,6 +83,12 @@ module.exports.templateTags = [{ const namesStr = names.map(n => `"${n}"`).join(',\n\t'); throw new Error(`No header with name "${name}".\nChoices are [\n\t${namesStr}\n]`); + case 'oauth2': + const token = await context.util.models.oAuth2Token.getByRequestId(request._id); + if (!token) { + throw new Error('No OAuth 2.0 tokens found for request'); + } + return token.accessToken; } return null;