Partner-Center-PowerShell icon indicating copy to clipboard operation
Partner-Center-PowerShell copied to clipboard

Error: The provided tokens must have less than 180 seconds difference in the time range of expiration

Open seanunuy opened this issue 3 years ago • 2 comments

Starting this month MicrosoftTeams Module cmdlet "Connect-MicrosoftTeams -AccessTokens @()"receives the ff error when connecting

The provided tokens must have less than 180 seconds difference in the time range of expiration.

seanunuy avatar Nov 04 '21 23:11 seanunuy

The problem seems to be that the tokens issued from New-PartnerAccessToken have wildly varying expiration dates. I'm seeing two tokens issued at the same time have expiration times varying between 10 seconds and 20 minutes.

Here's a "dumb but it works" temporary solution until Microsoft fixes this which just keeps reissuing the tokens and checking the difference between their expiration date until it's under 180 seconds.

do { $teamsToken = New-PartnerAccessToken -ApplicationId $appId -Credential $appCred -RefreshToken $refreshToken -Scopes '48ac35b8-9aa8-4d74-927d-1f4a14a0b239/.default' -ServicePrincipal -Tenant $tenantId $graphToken = New-PartnerAccessToken -ApplicationId $appId -Credential $appCred -RefreshToken $refreshToken -Scopes 'https://graph.microsoft.com/.default' -ServicePrincipal -Tenant $tenantId

$diffSeconds = [Math]::Abs(($graphToken.ExpiresOn - $teamsToken.ExpiresOn).TotalSeconds)
Write-Output "Graph Token: $($graphToken.ExpiresOn) - Teams Token: $($teamsToken.ExpiresOn) - $diffSeconds"

if ($diffSeconds -ge 180)
{
    Write-Output "Expiration time range too high, waiting to reissue"
    Start-Sleep 10
}
else
{
    break
}

} while ($true)

Connect-MicrosoftTeams -AccessTokens @($graphToken.AccessToken, $teamsToken.AccessToken)

clownwilleatme avatar Nov 26 '21 02:11 clownwilleatme

Having the same issue, unfortunately I am unable to use an Application auth in my project, so the work around @clownwilleatme posted doesn't seem to work. Tested using the latest module.

If there are any other suggestions let me know.

NZLostboy avatar Jan 27 '22 00:01 NZLostboy