Add 'Connect-Spotify.ps1'

This commit is contained in:
n 2022-07-16 23:30:41 +01:00
parent 7c194d1195
commit f3befe09a7

13
Connect-Spotify.ps1 Normal file
View File

@ -0,0 +1,13 @@
$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
}