Blue Eyed Behemoth Blue Eyed Behemoth - 1 year ago 166
C# Question

Office 365 App-Only Token Refresh/Update

I currently and retrieving the token just fine running everything that I want to run, but I can't figure out how to "Refresh" my token. It expires after an hour. This method of retrieving the App-Only token doesn't return a refresh token.

How can I "Refresh/Update" the token?

I'm using the following method to retrieve the token:

string authority = appConfig.AuthorizationUri.Replace("common", tenantId);
AuthenticationContext authenticationContext = new AuthenticationContext(authority,false);
string certfile = Server.MapPath(appConfig.ClientCertificatePfx);
X509Certificate2 cert = new X509Certificate(certfile,appConfig.ClientCertificatePfxPassword, X509KeyStorageFlags.MachineKeySet);
ClientAssertionCertificate cac = new ClientAssertionCertificate(appConfig.ClientId, cert);
var authenticationResult = await authenticationContext.AcquireTokenAsync(resource, cac);
return authenticationResult.AccessToken;


Answer Source

Just request another one. There is no refresh for app-only tokens. :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download