Skip to content

Latest commit

 

History

History
29 lines (19 loc) · 2.15 KB

auth.md

File metadata and controls

29 lines (19 loc) · 2.15 KB

Authenticate your C# app for OneDrive

To authenticate your app to use OneDrive, you need to instantiate an object that implements IAuthenticationProvider from Microsoft.Graph and call AuthenticateAsync on it. Then, you must create a OneDriveClient object and pass in your auth provider as an argument. Note that if the user changes their password, your app must re-authenticate. If you see 401 error codes, this is most likely the case. See Error codes for the OneDrive C# SDK for more info.

Note This topic assumes that you are familiar with app authentication. For more info about authentication in OneDrive, see Authentication for the OneDrive API.

Standard authentication components

When implementing IAuthenticationProvider, a standard set of parameters will be required:

Parameter Description
clientId The client ID of the app. Required.
returnUrl A redirect URL. Required.
baseUrl URL where the target OneDrive service is found. Required.
scopes Permissions that your app requires from the user. Required.
client_secret The client secret created for your app. Optional. Not available for Windows Store 8.1, Windows Phone 8.1, and Universal Windows Platform (UWP) apps.

In addition to clientId, returnURL, scopes, and client_secret the method takes in implementations for a client type, credential cache, HTTP provider, and a service info provider or web authentication UI. If not provided, the default implementations of each item will be used.

ClientType

A single client can only call OneDrive for Consumer or OneDrive for Business, not both. The target service is configured implicitly by the IAuthenticationProvider and the baseUrl passed into the OneDriveClient constructor.

If the application would like to interact with both OneDrive for Consumer and OneDrive for Business, a client should be created for each.

More Information

More information, and a fuller example of authentication, can be found at the MSA Auth Adapter repository.