Created
November 24, 2021 19:45
-
-
Save kevinblumenfeld/74ed39c87c233d258f9b4ec418607e10 to your computer and use it in GitHub Desktop.
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
function Connect-GraphRefresh { | |
[CmdletBinding()] | |
param ( | |
) | |
if (-not $Delegated) { | |
Connect-Graph -Tenant $Script:Tenant -Workload $Script:Workload -Delegated:$Script:Delegated | |
} | |
else { | |
$Request = @{ | |
Method = 'POST' | |
Body = @{ | |
Grant_Type = 'refresh_token' | |
Client_Id = $Script:Config.ClientId | |
Client_Secret = $Script:Config.cred.GetNetworkCredential().password | |
Username = $Script:cred.UserName | |
Password = $Script:cred.GetNetworkCredential().password | |
refresh_token = $Script:RefreshToken | |
Scope = "offline_access https://graph.microsoft.com/.default" | |
} | |
Uri = "https://login.microsoftonline.com/$Script:Tenant.onmicrosoft.com/oauth2/v2.0/token" | |
} | |
$Response = Invoke-RestMethod @Request | |
$Script:RefreshTime = ([datetime]::UtcNow).AddSeconds($Response.expires_in - 10) | |
$Script:Token = $Response.access_token | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment