/// <inheritdoc/> public async Task <bool> LoginAsync() { _isConnected = false; if (!_isInitialized) { throw new InvalidOperationException("Microsoft OneDrive not initialized."); } if (_accountProviderType == AccountProviderType.Msal) { _accountProvider = GraphOneDriveAuthenticationHelper.CreateMsalAuthenticationProvider(_appClientId, _scopes); await GraphOneDriveAuthenticationHelper.AuthenticateMsalUserAsync(_scopes); } else { GraphOneDriveAuthenticationHelper.ResourceUri = "https://graph.microsoft.com/"; _accountProvider = GraphOneDriveAuthenticationHelper.CreateAdalAuthenticationProvider(_appClientId); await GraphOneDriveAuthenticationHelper.AuthenticateAdalUserAsync(); } _oneDriveProvider = new GraphServiceClient("https://graph.microsoft.com/v1.0/me", _accountProvider); _isConnected = true; return(_isConnected); }
/// <summary> /// Create an ADAL Authentication provider /// </summary> /// <param name="appClientId">client application id</param> /// <returns>an authentication provider for Azure Active Directory</returns> internal static IAuthenticationProvider CreateAdalAuthenticationProvider(string appClientId) { _appClientId = appClientId; _accountProvider = new DelegateAuthenticationProvider( async(requestMessage) => { requestMessage.Headers.Authorization = new AuthenticationHeaderValue( "bearer", await GraphOneDriveAuthenticationHelper.AuthenticateAdalUserAsync().ConfigureAwait(false)); return; }); return(_accountProvider); }