Add 'Connect-Spotify.ps1'
This commit is contained in:
parent
7c194d1195
commit
f3befe09a7
13
Connect-Spotify.ps1
Normal file
13
Connect-Spotify.ps1
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user