-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guidance on Invoke-D365LcsApiRefreshToken
usage
#736
Comments
Hi, nice use case. If you don't want to call You can then use this information to check if the token expires soon and if so, refresh it. d365fo.tools/d365fo.tools/functions/set-d365lcsapiconfig.ps1 Lines 18 to 21 in 5c5d5d4
|
Hi, thanks for the reply. So I could fetch the exact timestamp via while ( ($DeploymentStatus -ne "Completed") -and ($DeploymentPollingCount -lt 72) ) {
if (<check if the token will expire in the next couple of minutes>) {
Get-D365LcsApiConfig | Invoke-D365LcsApiRefreshToken | Set-D365LcsApiConfig
}
$DeploymentStatus = Get-D365LcsDeploymentStatus -ActivityId $DeploymentOperation.ActivityId -EnvironmentId $TargetEnvironment.EnvironmentId -SleepInSeconds 300
Write-Host "Status: $($DeploymentStatus.OperationStatus)"
$DeploymentPollingCount++
} I'll update this issue if I eventually get this working. |
Personally I'd just go for the Refresh on every X minutes. Moving forward faster, keeping stuff simple for other to take over. Looking at how many request the Azure AD is handling during a day, my argument is that getting a refresh token every 5. minutes, doesn't do much harm. Happy to learn that people at using some of the LCS specific stuff from the module 🔥 |
Having some issues with piping the different cmdlets, which I saw here. Get-D365LcsApiConfig | Invoke-D365LcsApiRefreshToken -Verbose | Set-D365LcsApiConfig
VERBOSE: [10:20:52][Invoke-Authorization] Authenticating against Azure Active Directory (AAD).
VERBOSE: HTTP/1.1 POST with 836-byte payload
VERBOSE: received 469-byte response of content type application/json
[10:20:53][Invoke-Authorization] Something went wrong while working against Azure Active Directory (AAD) | Response status code does not
indicate success: 400 (Bad Request).
WARNING: [10:20:53][Invoke-Authorization] Stopping because of errors This however seems to work and generates a fresh access token: Invoke-D365LcsApiRefreshToken -ClientId $LCS_ClientId -RefreshToken $(Get-D365LcsApiConfig).refreshToken 💡 EDIT: just stumbled upon #496 I needed to explicitly specify the client ID when storing the LCS API config: Get-D365LcsApiToken -ClientId $LCS_ClientId `
-Username $LCS_Username `
-Password $LCS_Password `
-LcsApiUri $LCS_ApiUri | Set-D365LcsApiConfig -ProjectId $LCS_ProjectId -ClientId $LCS_ClientId 👈
Get-D365LcsApiConfig | Invoke-D365LcsApiRefreshToken | Set-D365LcsApiConfig |
I had the same issue as well in the past. It would be more intuitive if, when piping |
I hear what you are saying, but from a pure powershell point of view - it is only the real output that is being piped from one cmdlet to another.
But if we were to reorder things a bit, we could show things to following way:
Above is just pseudo code - but would that make more sense? |
Hm, maybe if we could pipe |
Ok, so here is what I was able to figure out:
I propose that
This would result in the following usage of the token cmdlets: Set-D365LcsApiConfig -ProjectId $LCS_ProjectId -ClientId $LCS_ClientId -LcsApiUri $LCS_ApiUri
Get-D365LcsApiToken -Username $LCS_Username -Password $LCS_Password | Set-D365LcsApiConfig
Invoke-D365LcsApiRefreshToken | Set-D365LcsApiConfig Personally, I would prefer an alternative where only the Set-D365LcsApiConfig -ProjectId $LCS_ProjectId -ClientId $LCS_ClientId -LcsApiUri $LCS_ApiUri
Get-D365LcsApiConfig | Get-D365LcsApiToken -Username $LCS_Username -Password $LCS_Password | Set-D365LcsApiConfig
Get-D365LcsApiConfig | Invoke-D365LcsApiRefreshToken | Set-D365LcsApiConfig |
Thanks for putting in the effort to think about these things and providing feedback, AND a PR with fixes to a hidden bug 🔥 So what do we need to agree on, or work on, after this PR has been merged? Do we need to refactor the |
@Splaxi Thanks for the speedy merge :) Yes, if you agree with the proposal that |
Hi 👋
I'm using this module to apply quality updates to our (rather extensive collection of 🥴) cloud-hosted environments. This works great but I'm not sure how I should make use of the
Invoke-D365LcsApiRefreshToken
cmdlet.Pseudo code of the steps we're going through:
* these steps never get executed as I'm no longer authenticated against the LCS API
Steps
1
through5a
work fine, but I'm running into issues as the token expires after 60 min, which is right around the time when the deployment has started and I'm in the process of polling the deployment status every 5 minutes:What would be the best way to incorporate the
Invoke-D365LcsApiRefreshToken
cmdlet in my script? Adding it to the abovewhile
loop would mean that it would refresh every 5 min which I guess would be overkill?The text was updated successfully, but these errors were encountered: