From 976720c8f2c97fa51a2fa55cecb3efaf6cadc039 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Wed, 28 Mar 2018 22:32:09 -0400 Subject: [PATCH] Introspection queries use same OAuth2 tokens (Closes #835) --- package.json | 3 +-- packages/insomnia-app/app/network/authentication.js | 10 +++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 7abe3f3e78..19e368399a 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,5 @@ "electron-rebuild": "^1.6.0", "jest": "^22.1.1", "lerna": "^2.7.1" - }, - "dependencies": {} + } } diff --git a/packages/insomnia-app/app/network/authentication.js b/packages/insomnia-app/app/network/authentication.js index 5aa40310d1..ef8947c6ce 100644 --- a/packages/insomnia-app/app/network/authentication.js +++ b/packages/insomnia-app/app/network/authentication.js @@ -34,7 +34,15 @@ export async function getAuthHeader ( } if (authentication.type === AUTH_OAUTH_2) { - const oAuth2Token = await getOAuth2Token(requestId, authentication); + // HACK: GraphQL requests use a child request to fetch the schema with an + // ID of "{{request_id}}.graphql". Here we are removing the .graphql suffix and + // pretending we are fetching a token for the original request. This makes sure + // the same tokens are used for schema fetching. See issue #835 on GitHub. + const tokenId = requestId.match(/\.graphql$/) + ? requestId.replace(/\.graphql$/, '') + : requestId; + + const oAuth2Token = await getOAuth2Token(tokenId, authentication); if (oAuth2Token) { const token = oAuth2Token.accessToken; return _buildBearerHeader(token, authentication.tokenPrefix);