Refresh the tokens without user interaction
See original GitHub issueFeature Request
Is your feature request related to a problem? Please describe. I am unable to refresh the token without user interaction, we have a function that renews however PowerShell spawns a browser we must sign into, along with a URL + code combo.
We simply want to automate this process.
Describe the solution you would like A cmdlet option to obtain a new token without any user interaction
Describe alternatives you have considered I have a script I can run every 90d or so but am looking to avoid doing this manual process
Additional context I do not believe there is any additional context needed here but please do ask if need
My function below which works but does require user interaction
Function Get-RefreshedTokens {
$ApplicationId = 'OBFUSCATED'
$ApplicationSecret = 'OBFUSCATED' | Convertto-SecureString -AsPlainText -Force
$TenantID = 'OBFUSCATED'
$Credential = New-Object System.Management.Automation.PSCredential($ApplicationId, $ApplicationSecret)
$Token = New-PartnerAccessToken -ApplicationId $ApplicationId -Scopes 'https://api.partnercenter.microsoft.com/user_impersonation' -ServicePrincipal -Credential $Credential -Tenant $TenantID -UseAuthorizationCode
$ExchangeToken = New-PartnerAccessToken -ApplicationId 'a0c73c16-a7e3-4564-9a95-2bdf47383716' -Scopes 'https://outlook.office365.com/.default' -Tenant $TenantID -UseDeviceAuthentication
Return [PSCustomObject]@{
TenantId = $TenantID
Credential = $Credential
RefreshToken = $Token.RefreshToken
ExchangeToken = $ExchangeToken.RefreshToken
}
}
$Tokens = Get-RefreshedTokens
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
Can refresh tokens renew themselves forever without user ...
As below documentation, by default, Refresh token MaxInactiveTime will be 90 days and MaxAgeMultiFactor will be until revoked. So if are using ...
Read more >How to get refresh token without User interaction
It is not possible to get a refresh using an app key and access token programmatically. You can only get a refresh token...
Read more >What Are Refresh Tokens and How to Use Them Securely
That is, a refresh token is a credential artifact that lets a client application get new access tokens without having to ask the...
Read more >Can a JWT token be refreshed without user interaction?
Yes, it is possible to refresh a JSON Web Token (JWT) without user interaction, by using a technique known as token refresh. The...
Read more >What are Refresh Tokens and How They Interact with JWTs?
A refresh token ensures that a user can regain the access token without providing login credentials. Let's dig deeper about refresh tokens, their...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you @Agazoth I will test and confirm results soon
Hi @kfear27,
I filed an issue on inconsistent documentation on that page. It would be nice to get it cleaned up.
ApplicetionId is always the ApplicationId of your Application. It is the same as the UserName in your Credential object.
If you have a working RefreshToken (less then 90 days old) you can generate a new token with it. All you need to do is this:
This works for me.
If you save the refresh token from the new token every time you run your code, and you run your code with less then 90 days in between, you will never have to re-authenticate.