-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add authorization token to generate code
Fixes #1791
- Loading branch information
Leonardo Ferreira Lima
committed
Apr 27, 2024
1 parent
c17e4ef
commit 5d73ff1
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import get from 'lodash/get'; | ||
|
||
export const getAuthHeaders = (collectionRootAuth, requestAuth) => { | ||
const auth = collectionRootAuth && ['inherit', 'none'].includes(requestAuth.mode) ? collectionRootAuth : requestAuth; | ||
|
||
switch (auth.mode) { | ||
case 'basic': | ||
const username = get(auth, 'basic.username'); | ||
const password = get(auth, 'basic.password'); | ||
const basicToken = Buffer.from(`${username}:${password}`).toString('base64'); | ||
|
||
return [ | ||
{ | ||
enabled: true, | ||
name: 'Authorization', | ||
value: `Basic ${basicToken}` | ||
} | ||
]; | ||
case 'bearer': | ||
return [ | ||
{ | ||
enabled: true, | ||
name: 'Authorization', | ||
value: `Bearer ${get(auth, 'bearer.token')}` | ||
} | ||
]; | ||
default: | ||
return []; | ||
} | ||
}; |