Skip to content

Instantly share code, notes, and snippets.

@kevinblumenfeld
Created November 24, 2021 19:45
Show Gist options
  • Save kevinblumenfeld/74ed39c87c233d258f9b4ec418607e10 to your computer and use it in GitHub Desktop.
Save kevinblumenfeld/74ed39c87c233d258f9b4ec418607e10 to your computer and use it in GitHub Desktop.
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