spotify-p-aa/Connect-Spotify.ps1

13 lines
627 B
PowerShell
Raw Normal View History

2022-07-16 23:30:41 +01:00
$ExpiresOn = Get-AutomationVariable -Name "ExpiresOn"
if ([DateTime]::Now -gt [DateTime]$ExpiresOn) {
Write-Verbose "ExpiresOn has passed, getting new token"
$RefreshToken = Get-AutomationVariable -Name 'RefreshToken'
$RequestParameters = @{
URI = "$(Get-AutomationVariable -Name 'AuthenticationURI')/refresh"
Body = @{ token = $RefreshToken }
}
$Data = Invoke-RestMethod @RequestParameters
Set-AutomationVariable -Name "AccessToken" -Value $Data.data.token.access_token
$NewExpiresOn = [DateTime]::Now.AddSeconds($Data.data.token.expires_in)
Set-AutomationVariable -Name "ExpiresOn" -Value $NewExpiresOn
}