/// <summary> /// Creates an authenticated OneDrive client for use against OneDrive consumer. /// </summary> /// <param name="appId">The application ID for Microsoft account authentication.</param> /// <param name="returnUrl">The application return URL for Microsoft account authentication.</param> /// <param name="scopes">The requested scopes for Microsoft account authentication.</param> /// <param name="authenticationProvider">The <see cref="IAuthenticationProvider"/> for authenticating the client.</param> /// <param name="credentialCache">The cache instance for storing user credentials.</param> /// <param name="httpProvider">The <see cref="IHttpProvider"/> for sending HTTP requests.</param> /// <returns>The <see cref="IOneDriveClient"/> for the session.</returns> public static Task <IOneDriveClient> GetAuthenticatedMicrosoftAccountClient( string appId, string returnUrl, string[] scopes, IAuthenticationProvider authenticationProvider, CredentialCache credentialCache = null, IHttpProvider httpProvider = null) { return(OneDriveClient.GetAuthenticatedMicrosoftAccountClient( appId, returnUrl, scopes, /* clientSecret */ null, new ServiceInfoProvider(authenticationProvider), credentialCache, httpProvider)); }
/// <summary> /// Creates a OneDrive client for use against OneDrive consumer. /// </summary> /// <param name="appId">The application ID for Microsoft account authentication.</param> /// <param name="returnUrl">The application return URL for Microsoft account authentication.</param> /// <param name="scopes">The requested scopes for Microsoft account authentication.</param> /// <param name="credentialCache">The cache instance for storing user credentials.</param> /// <param name="httpProvider">The <see cref="IHttpProvider"/> for sending HTTP requests.</param> /// <param name="webAuthenticationUi">The <see cref="IWebAuthenticationUi"/> for displaying authentication UI to the user.</param> /// <returns>The <see cref="IOneDriveClient"/> for the session.</returns> public static IOneDriveClient GetMicrosoftAccountClient( string appId, string returnUrl, string[] scopes, CredentialCache credentialCache = null, IHttpProvider httpProvider = null, IWebAuthenticationUi webAuthenticationUi = null) { return(OneDriveClient.GetMicrosoftAccountClient( appId, returnUrl, scopes, /* clientSecret */ null, credentialCache, httpProvider, new ServiceInfoProvider(webAuthenticationUi))); }
/// <summary> /// Creates an authenticated OneDrive client for use against OneDrive consumer. /// </summary> /// <param name="appId">The application ID for Microsoft account authentication.</param> /// <param name="returnUrl">The application return URL for Microsoft account authentication.</param> /// <param name="scopes">The requested scopes for Microsoft account authentication.</param> /// <param name="webAuthenticationUi">The <see cref="IWebAuthenticationUi"/> for displaying authentication UI to the user.</param> /// <param name="credentialCache">The cache instance for storing user credentials.</param> /// <param name="httpProvider">The <see cref="IHttpProvider"/> for sending HTTP requests.</param> /// <returns>The <see cref="IOneDriveClient"/> for the session.</returns> public static Task <IOneDriveClient> GetAuthenticatedMicrosoftAccountClient( string appId, string returnUrl, string[] scopes, IWebAuthenticationUi webAuthenticationUi, CredentialCache credentialCache = null, IHttpProvider httpProvider = null) { return(OneDriveClient.GetAuthenticatedMicrosoftAccountClient( appId, returnUrl, scopes, /* clientSecret */ null, webAuthenticationUi, credentialCache, httpProvider)); }
/// <summary> /// Creates an authenticated OneDrive client for use against OneDrive consumer for silent (refresh token) authentication. /// </summary> /// <param name="appId">The application ID for Microsoft account authentication.</param> /// <param name="returnUrl">The application return URL for Microsoft account authentication.</param> /// <param name="scopes">The requested scopes for Microsoft account authentication.</param> /// <param name="refreshToken">The refresh token for silent authentication.</param> /// <param name="serviceInfoProvider">The <see cref="IServiceInfoProvider"/> for initializing the <see cref="IServiceInfo"/> for the session.</param> /// <param name="credentialCache">The cache instance for storing user credentials.</param> /// <param name="httpProvider">The <see cref="IHttpProvider"/> for sending HTTP requests.</param> /// <returns>The <see cref="IOneDriveClient"/> for the session.</returns> public static Task <IOneDriveClient> GetSilentlyAuthenticatedMicrosoftAccountClient( string appId, string returnUrl, string[] scopes, string refreshToken, IServiceInfoProvider serviceInfoProvider, CredentialCache credentialCache = null, IHttpProvider httpProvider = null) { return(OneDriveClient.GetSilentlyAuthenticatedMicrosoftAccountClient( appId, returnUrl, scopes, /* clientSecret */ null, refreshToken, serviceInfoProvider, credentialCache, httpProvider)); }
/// <summary> /// Creates an authenticated OneDrive client for use against OneDrive consumer. /// </summary> /// <param name="appId">The application ID for Microsoft account authentication.</param> /// <param name="returnUrl">The application return URL for Microsoft account authentication.</param> /// <param name="scopes">The requested scopes for Microsoft account authentication.</param> /// <param name="serviceInfoProvider">The <see cref="IServiceInfoProvider"/> for initializing the <see cref="IServiceInfo"/> for the session.</param> /// <param name="credentialCache">The cache instance for storing user credentials.</param> /// <param name="httpProvider">The <see cref="IHttpProvider"/> for sending HTTP requests.</param> /// <returns>The <see cref="IOneDriveClient"/> for the session.</returns> public static async Task <IOneDriveClient> GetAuthenticatedMicrosoftAccountClient( string appId, string returnUrl, string[] scopes, IServiceInfoProvider serviceInfoProvider, CredentialCache credentialCache = null, IHttpProvider httpProvider = null) { var client = OneDriveClient.GetMicrosoftAccountClient( appId, returnUrl, scopes, /* clientSecret */ null, credentialCache, httpProvider, serviceInfoProvider); await client.AuthenticateAsync(); return(client); }
/// <summary> /// Creates an authenticated OneDrive client for use against OneDrive consumer for silent (refresh token) authentication. /// </summary> /// <param name="appId">The application ID for Microsoft account authentication.</param> /// <param name="returnUrl">The application return URL for Microsoft account authentication.</param> /// <param name="scopes">The requested scopes for Microsoft account authentication.</param> /// <param name="clientSecret">The client secret for Microsoft account authentication.</param> /// <param name="refreshToken">The refresh token for silent authentication.</param> /// <param name="serviceInfoProvider">The <see cref="IServiceInfoProvider"/> for initializing the <see cref="IServiceInfo"/> for the session.</param> /// <param name="credentialCache">The cache instance for storing user credentials.</param> /// <param name="httpProvider">The <see cref="IHttpProvider"/> for sending HTTP requests.</param> /// <returns>The <see cref="IOneDriveClient"/> for the session.</returns> public static async Task <IOneDriveClient> GetSilentlyAuthenticatedMicrosoftAccountClient( string appId, string returnUrl, string[] scopes, string clientSecret, string refreshToken, IServiceInfoProvider serviceInfoProvider, CredentialCache credentialCache = null, IHttpProvider httpProvider = null) { var clientServiceInfoProvider = serviceInfoProvider ?? new ServiceInfoProvider(); var client = OneDriveClient.GetMicrosoftAccountClient( appId, returnUrl, scopes, clientSecret, credentialCache, httpProvider, clientServiceInfoProvider) as OneDriveClient; if (client.ServiceInfo == null) { client.ServiceInfo = await clientServiceInfoProvider.GetServiceInfo( client.appConfig, client.credentialCache, client.HttpProvider, client.ClientType); } client.AuthenticationProvider.CurrentAccountSession = new AccountSession { RefreshToken = refreshToken }; await client.AuthenticateAsync(); return(client); }
public async Task BaseRequest_SendAsync_ClientNotAuthenticated() { var client = new OneDriveClient(new AppConfig()); var baseRequest = new BaseRequest("https://localhost", client); try { await baseRequest.SendAsync<Item>("string"); } catch (OneDriveException exception) { Assert.AreEqual(OneDriveErrorCode.InvalidRequest.ToString(), exception.Error.Code, "Unexpected error code."); Assert.AreEqual("The client must be authenticated before sending a request.", exception.Error.Message, "Unexpected error message."); throw; } }
public async Task Authenticate() { var msaAuthenticationProvider = new OnlineIdAuthenticationProvider(new string[] { "onedrive.readwrite" }); await msaAuthenticationProvider.AuthenticateUserAsync(); client = new OneDriveClient("https://api.onedrive.com/v1.0", msaAuthenticationProvider); }