-
Notifications
You must be signed in to change notification settings - Fork 254
Get ms alias from github identity. #2581
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
Merged
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
13d7999
Generate token for aad app.
sima-zhu fd410cc
Remove testing mode
sima-zhu ec79b8f
Update Generate-AddToken.ps1
sima-zhu 5379df3
Update Generate-AddToken.ps1
sima-zhu db95959
Generate token inside of opensource API call scripts
sima-zhu 58c6c8e
Add resource
sima-zhu e0801fb
Address feedback
sima-zhu 29c1ef2
Update eng/common/scripts/Get-AADIdentityFromGithubUser.ps1
sima-zhu e3f317c
Update eng/common/scripts/Get-AADIdentityFromGithubUser.ps1
sima-zhu 4f1f62d
Remove the printout
sima-zhu d804557
Merge branch 'generate_token' of https://github.com/sima-zhu/azure-sd…
sima-zhu ddf02ad
Update eng/common/scripts/Get-AADIdentityFromGithubUser.ps1
sima-zhu a081b55
Update eng/common/scripts/Get-AADIdentityFromGithubUser.ps1
sima-zhu 24a61be
Added PS script strict mode
sima-zhu 52efc42
Update Get-AADIdentityFromGithubUser.ps1
sima-zhu b9f758d
Update Get-AADIdentityFromGithubUser.ps1
sima-zhu 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| <# | ||
| .DESCRIPTION | ||
| Get the corresponding ms alias from github identity | ||
| .PARAMETER AadToken | ||
| The aad access token. | ||
| .PARAMETER GithubName | ||
| Github identity. E.g sima-zhu | ||
| .PARAMETER ContentType | ||
| Content type of http requests. | ||
| .PARAMETER AdditionalHeaders | ||
| Additional parameters for http request headers in key-value pair format, e.g. @{ key1 = val1; key2 = val2; key3 = val3} | ||
| #> | ||
| [CmdletBinding(SupportsShouldProcess = $true)] | ||
| param( | ||
| [Parameter(Mandatory = $true)] | ||
| [string]$TenantId, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [string]$ClientId, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [string]$ClientSecret, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [string]$GithubUser | ||
| ) | ||
| . "${PSScriptRoot}\logging.ps1" | ||
|
sima-zhu marked this conversation as resolved.
Outdated
|
||
|
|
||
| $OpensourceAPIBaseURI = "https://repos.opensource.microsoft.com/api/people/links/github/$GithubUser" | ||
|
|
||
| function Generate-AadToken ($TenantId, $ClientId, $ClientSecret) { | ||
| $LoginAPIBaseURI = "https://login.microsoftonline.com/$TenantId/oauth2/token" | ||
| try { | ||
| $headers = @{ | ||
| "content-type" = "application/x-www-form-urlencoded" | ||
| } | ||
|
|
||
| $body = @{ | ||
| "grant_type" = "client_credentials" | ||
| "client_id" = $ClientId | ||
| "client_secret" = $ClientSecret | ||
| "resource" = "api://repos.opensource.microsoft.com/audience/7e04aa67" | ||
| } | ||
| Write-Host "Generating aad token..." | ||
| $resp = Invoke-RestMethod $LoginAPIBaseURI -Method 'POST' -Headers $headers -Body $body | ||
| } | ||
| catch { | ||
| LogError $_ | ||
| exit 1 | ||
| } | ||
|
|
||
| return $resp.access_token | ||
| } | ||
|
|
||
| $Headers = @{ | ||
| "Content-Type" = "application/json" | ||
| "api-version" = "2019-10-01" | ||
| } | ||
|
|
||
| try { | ||
| $opsAuthToken = Generate-AadToken -TenantId $TenantId -ClientId $ClientId -ClientSecret $ClientSecret | ||
| $Headers["Authorization"] = "Bearer $opsAuthToken" | ||
| Write-Host "Fetching aad identity for github user: $GithubName" | ||
| $resp = Invoke-RestMethod $OpensourceAPIBaseURI -Method 'GET' -Headers $Headers | ||
| } | ||
| catch { | ||
| LogError $_ | ||
| exit 1 | ||
| } | ||
|
|
||
| $resp | Write-Verbose | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be worth adding some logging of what value we got back so it shows up in the logs something like this in the if statement:
|
||
| if ($resp.aad) { | ||
| return $resp.aad.alias | ||
| } | ||
|
|
||
| LogError "Failed to retrieve the aad identity from given github user: $GithubName" | ||
|
sima-zhu marked this conversation as resolved.
|
||
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.