I'm tinkering with the OneDrive API.
Find the code here https://github.com/onedrive/onedrive-sdk-csharp
Specificaly the OneDrive Api Browser.
I have no formal education on this specific subject (Authentication).
I want to know, how would I stay authenticated after the first login? That is, how would I store the login information when it seems that you are expected to query the URI for a token every time?
For example, when the OneDrive API Browser solution is run, You must sign in every time the app is run. What if I wanted to save the credentials somewhere, say in a text file? How would I do that? (I am aware of the security issues / poor practice there)
Should I save the token somewhere? Is there another service to use for longterm tokens? Is it even possible? Are cookies involved?
The OneDrive REST API is a portion of the Microsoft Graph API which allows your app to connect to content stored in OneDrive and SharePoint.
Conceptually after you authenticated your app using code flow, you will receive a refresh token which you can save along with your client Id and use it later to retrieve the access token as described here . For windows and windows phone you can also use the Authentication Adapter for the OneDrive SDK which does all the job:
MsaAuthenticationProvider msaAuthProvider = new MsaAuthenticationProvider(
MsaClientId,
MsaClientSecret,
RedirectUri,
Scopes,
null,
new CredentialVault(MsaClientId));
await msaAuthProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync(userName);
OneDriveClient oneDriveClient = new OneDriveClient("https://api.onedrive.com/v1.0", msaAuthProvider);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With