Skip to content

Commit

Permalink
Extract rfc8693 tokenexchange logic to a helper function
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vallejo <rvallejo@vmware.com>
  • Loading branch information
rvallejony committed Sep 12, 2023
1 parent fa10765 commit 8f45ee8
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions plugins/auth-backend-module-pinniped-provider/src/authenticator.ts
Expand Up @@ -92,18 +92,29 @@ export const pinnipedAuthenticator = createOAuthAuthenticator({
? decodeOAuthState(stateParam).audience
: undefined;

const rfc8693TokenExchange = ({
subject_token,
target_audience,
}: {
subject_token: string;
target_audience: string;
}): Promise<TokenSet> => {
return client.grant({
grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',
subject_token,
audience: target_audience,
subject_token_type: 'urn:ietf:params:oauth:token-type:access_token',
requested_token_type: 'urn:ietf:params:oauth:token-type:jwt',
});
};

return new Promise((resolve, reject) => {
strategy.success = user => {
(audience
? client
.grant({
grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',
subject_token: user.tokenset.access_token,
audience,
subject_token_type:
'urn:ietf:params:oauth:token-type:access_token',
requested_token_type: 'urn:ietf:params:oauth:token-type:jwt',
})
? rfc8693TokenExchange({
subject_token: user.tokenset.access_token,
target_audience: audience,
})
.then(tokenset => tokenset.access_token)
.catch(err =>
reject(
Expand Down

0 comments on commit 8f45ee8

Please sign in to comment.