-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Added OIDC client functionality in core package #887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TingluoHuang
merged 45 commits into
actions:features/oidcpreview
from
souravchanduka:main-oidc-client
Aug 25, 2021
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
bdacfc4
Inital draft of OIDC Client
souravchanduka 1322acb
Comments Resolved
souravchanduka f733089
oidc client changes
souravchanduka c45ad60
require added
souravchanduka 53a7529
Resolved issues
souravchanduka 4831d7a
removed unnecesary files
souravchanduka 9df7428
package.json modified
souravchanduka 8071504
added dist folder
souravchanduka 962ff70
updated readme
souravchanduka 885469e
updated version
souravchanduka a6114b6
version updated
souravchanduka f541fb1
version update
souravchanduka 7965cc3
null ref fix
souravchanduka 456cf5a
package.json updated
souravchanduka 58dfa1c
readme modified
souravchanduka 330dc0b
Updated Readme
souravchanduka 662a937
Resolved comments
souravchanduka a2adaa8
Readme updated
souravchanduka ff90431
Update README.md
souravchanduka 0c1cb72
Resolved Comments
souravchanduka 5afccaa
removed whitespaces
souravchanduka 9c6e7d8
Moved oidc functionality to actions/core
souravchanduka 0a94a78
README.md updated
souravchanduka f559006
Resolved Comments
souravchanduka aa1968c
async call fix
souravchanduka 5d9c674
comments resolved
souravchanduka cca2b18
Addressed Comments
souravchanduka 33891d9
addressed comments
souravchanduka dac801e
error message updated
souravchanduka d0f4aae
Error Message updated
souravchanduka c7ec407
resolved comments
souravchanduka 1c86c4c
payload updated
souravchanduka 22e5d95
addressed comments
souravchanduka 547e30c
addressed comments
souravchanduka 619566e
Merge branch 'main' into main-oidc-client
souravchanduka 3ceb264
readme updated
souravchanduka 1162975
removed whitespaces
souravchanduka 1c03cd3
audience can be undefined
souravchanduka 1f8d7b5
default aud parameter
souravchanduka 09e9478
comments resolved
souravchanduka 4631854
version updated
souravchanduka 2b58973
Merge branch 'main' into main-oidc-client
souravchanduka d9212ff
Addressed minor comments
souravchanduka af75719
Merge branch 'main-oidc-client' of https://github.com/souravchanduka/…
souravchanduka 0bab362
eslint fix
souravchanduka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,94 @@ | ||
| /* eslint-disable @typescript-eslint/no-extraneous-class */ | ||
| import * as actions_http_client from '@actions/http-client' | ||
| import {IRequestOptions} from '@actions/http-client/interfaces' | ||
| import {HttpClient} from '@actions/http-client' | ||
| import {BearerCredentialHandler} from '@actions/http-client/auth' | ||
| import {debug, setSecret} from './core' | ||
|
|
||
| interface TokenRequest { | ||
| aud?: string | ||
| } | ||
|
|
||
| interface TokenResponse { | ||
| value?: string | ||
| } | ||
|
|
||
| export class OidcClient { | ||
| private static createHttpClient( | ||
| allowRetry = true, | ||
| maxRetry = 10 | ||
| ): actions_http_client.HttpClient { | ||
| const requestOptions: IRequestOptions = { | ||
| allowRetries: allowRetry, | ||
| maxRetries: maxRetry | ||
| } | ||
|
|
||
| return new HttpClient( | ||
| 'actions/oidc-client', | ||
| [new BearerCredentialHandler(OidcClient.getRuntimeToken())], | ||
| requestOptions | ||
| ) | ||
| } | ||
|
|
||
| private static getApiVersion(): string { | ||
| return '2.0' | ||
| } | ||
|
|
||
| private static getRuntimeToken(): string { | ||
| const token = process.env['ACTIONS_RUNTIME_TOKEN'] | ||
| if (!token) { | ||
| throw new Error('Unable to get ACTIONS_RUNTIME_TOKEN env variable') | ||
| } | ||
| return token | ||
| } | ||
|
|
||
| private static getIDTokenUrl(): string { | ||
| const runtimeUrl = process.env['ACTIONS_ID_TOKEN_REQUEST_URL'] | ||
| if (!runtimeUrl) { | ||
| throw new Error('Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable') | ||
| } | ||
| return `${runtimeUrl}?api-version=${OidcClient.getApiVersion()}` | ||
| } | ||
|
|
||
| private static async postCall( | ||
| id_token_url: string, | ||
| data: TokenRequest | ||
| ): Promise<string> { | ||
| const httpclient = OidcClient.createHttpClient() | ||
|
|
||
| const res = await httpclient | ||
| .postJson<TokenResponse>(id_token_url, data) | ||
| .catch(error => { | ||
| throw new Error( | ||
| `Failed to get ID Token. \n | ||
| Error Code : ${error.statusCode}\n | ||
| Error Message: ${error.result.message}` | ||
| ) | ||
| }) | ||
|
|
||
| const id_token = res.result?.value | ||
| if (!id_token) { | ||
| throw new Error('Response json body do not have ID Token field') | ||
| } | ||
| return id_token | ||
| } | ||
|
|
||
| static async getIDToken(audience?: string): Promise<string> { | ||
| try { | ||
| // New ID Token is requested from action service | ||
| const id_token_url: string = OidcClient.getIDTokenUrl() | ||
|
|
||
| debug(`ID token url is ${id_token_url}`) | ||
|
|
||
| const data: TokenRequest = {aud: audience} | ||
|
|
||
| debug(`audience is ${audience ? audience : 'not defined'}`) | ||
|
|
||
| const id_token = await OidcClient.postCall(id_token_url, data) | ||
| setSecret(id_token) | ||
| return id_token | ||
| } catch (error) { | ||
| throw new Error(`Error message: ${error.message}`) | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.