Forum Discussion
Implementing RefreshToken for AuthenticationManager.GetAppOnlyAuthenticatedContext (OfficeDevPnP)
Hi all - I recently stumbled upon a small issue with OfficeDevPnP AuthenticationManager. I have a long-running console program using GetAppOnlyAuthenticatedContext() to build SharePoint Online context for me, but after roughly 70 minutes I start getting 401 errors for my queries. That's understandable - access token lifespan is 75 minutes. However, I couldn't find any method to get a RefreshToken, and prolong the time my session would be valid...
I proceeded to fork the repository and see if I could implement a reauthentication flow into EnsureToken, since it sets the accesstoken to null when it's about to expire (which is smart in a sense, but doesn't help me here), but I couldn't get a RefreshToken by using the TokenHelper (it's null in the response). Is there something I'm missing, or is implementing a reauthentication using a RefreshToken impossible for a console app here? Should I change authentication method?
My app is quite often going to run for hours at a time, so it would be handy to find a way to enable the sessions to be more long-lived... :)
Thanks for any feedback or ideas. Cheers!