Skip to content

Commit eb3eac8

Browse files
authored
Add files via upload
1 parent 69bb9cd commit eb3eac8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#1) generate a device code. The ClientID in the below command is for 'Microsoft Inture Company Portal':
2+
$ClientID = "9ba1a5c7-f17a-4de9-a1f1-6178c8d51223"
3+
$Scope = ".default offline_access"
4+
$body = @{
5+
"client_id" = $ClientID
6+
"scope" = $Scope
7+
}
8+
$authResponse = Invoke-RestMethod -UseBasicParsing -Method Post -Uri "https://login.microsoftonline.com/common/oauth2/v2.0/devicecode" -Body $body
9+
$authResponse
10+
11+
#Sleep to give time to enter code in Browser
12+
Sleep 60
13+
14+
#2) to request refresh token and access token for the Graph API:
15+
$GrantType = "urn:ietf:params:oauth:grant-type:device_code"
16+
$body=@{
17+
"client_id" = $ClientID
18+
"grant_type" = $GrantType
19+
"code" = $authResponse.device_code
20+
}
21+
$Tokens = Invoke-RestMethod -UseBasicParsing -Method Post -Uri "https://login.microsoftonline.com/common/oauth2/v2.0/token" -Body $body -ErrorAction SilentlyContinue
22+
$Tokens
23+
$GraphToken = $Tokens.access_token
24+
25+
#request access token for the ARM API
26+
$scope = 'https://management.azure.com/.default'
27+
$refresh_token = $tokens.refresh_token
28+
$GrantType = 'refresh_token'
29+
$body=@{
30+
"client_id" = $ClientID
31+
"scope" = $Scope
32+
"refresh_token" = $refresh_token
33+
"grant_type" = $GrantType
34+
}
35+
$Token_output = Invoke-RestMethod -UseBasicParsing -Method Post -Uri "https://login.microsoftonline.com/common/oauth2/v2.0/token" -Body $body
36+
$token = $Token_output.access_token

0 commit comments

Comments
 (0)