-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGet-MSGraphOAuthCode.ps1
50 lines (45 loc) · 1.54 KB
/
Get-MSGraphOAuthCode.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function Get-MSGraphOAuthCode {
[CmdletBinding()]
param (
# Provide your Application ID
[Parameter(Mandatory=$true,
Position=0,
ValueFromPipelineByPropertyName=$true,
ParameterSetName='Parameter Set 1')]
[string]
$ClientId,
# Provide your applications redirect URL
[Parameter(Mandatory=$true,
Position=1,
ValueFromPipelineByPropertyName=$true,
ParameterSetName='Parameter Set 1')]
[string]
$RedirectUrl,
# Provide your applications scopes
[Parameter(Mandatory=$true,
Position=2,
ValueFromPipelineByPropertyName=$true,
ParameterSetName='Parameter Set 1')]
[string]
$Scope
)
if ($ClientId -notmatch '%'){
$ClientId = [System.Web.HttpUtility]::UrlEncode($ClientId)
}
if ($RedirectUrl -notmatch '%'){
$RedirectUrl = [System.Web.HttpUtility]::UrlEncode($RedirectUrl)
}
if ($Scope -notmatch '%'){
$Scope = [System.Web.HttpUtility]::UrlEncode($Scope)
}
$commonOAuthURL = @"
https://login.microsoftonline.com/common/oauth2/v2.0/authorize
?client_id=$ClientId
&response_type=code
&redirect_uri=$RedirectUrl
&response_mode=query
&scope=openid%20profile%20email%20offline_access%20$Scope
&state=12345
"@
Write-Output "Copy this URL into your browser and authenticate using the appropriate credentials: $($commonOAuthURL -replace '\r*\n', '')"
}