From f3befe09a7da3e70420d74209a3d86a1adb44406 Mon Sep 17 00:00:00 2001 From: n Date: Sat, 16 Jul 2022 23:30:41 +0100 Subject: [PATCH] Add 'Connect-Spotify.ps1' --- Connect-Spotify.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Connect-Spotify.ps1 diff --git a/Connect-Spotify.ps1 b/Connect-Spotify.ps1 new file mode 100644 index 0000000..384a9d0 --- /dev/null +++ b/Connect-Spotify.ps1 @@ -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 +} \ No newline at end of file