mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-20 14:17:29 -04:00
Add OAuth 2.0 token to Request template tag (#715)
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user