mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
3f5e7e2e14
* Proof of concept authorize call * Authorize and Refresh endpoints done * OAuth2 editor started * Some small fixes * Set OAuth headers on request * Started on some OAuth tests * Updated network logic with new OAuth API * OAuth forms and refactor flows * Fix grant type handling * Moved auth handling out of render pipeline * Fixed legacy auth header * Fix vertical center * Prompt user on auth type change * Refresh tokens working (I think) and better UI * Catch same type auth change * POC refresh token and small refactor * Better token handling * LOading state to token refresh * Show o-auth-2 errors * Some minor updates
38 lines
939 B
JavaScript
38 lines
939 B
JavaScript
import {AUTH_BASIC, AUTH_OAUTH_2} from '../common/constants';
|
|
import {getBasicAuthHeader} from '../common/misc';
|
|
import getOAuth2Token from './o-auth-2/get-token';
|
|
|
|
export async function getAuthHeader (requestId, authentication) {
|
|
if (authentication.disabled) {
|
|
return null;
|
|
}
|
|
|
|
if (authentication.type === AUTH_BASIC) {
|
|
const {username, password} = authentication;
|
|
return getBasicAuthHeader(username, password);
|
|
}
|
|
|
|
if (authentication.type === AUTH_OAUTH_2) {
|
|
const oAuth2Token = await getOAuth2Token(requestId, authentication);
|
|
if (oAuth2Token) {
|
|
const token = oAuth2Token.refreshToken || oAuth2Token.accessToken;
|
|
return _buildBearerHeader(token);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
function _buildBearerHeader (accessToken) {
|
|
if (!accessToken) {
|
|
return null;
|
|
}
|
|
|
|
const name = 'Authorization';
|
|
const value = `Bearer ${accessToken}`;
|
|
|
|
return {name, value};
|
|
}
|