private async Task RedeemUsernameAndPasswordAsync() { if (string.IsNullOrEmpty(this.AccessToken)) { var creds = new Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential(this.Username, this.Password); var context = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(this.TokenService); var token = await context.AcquireTokenAsync(this.Resource, this.ClientId, creds); if (null != token) { this.AccessToken = token.AccessToken; } else { throw new OAuthAccountException( string.Format("Failed to convert username + password to access token for account: {0}", this.Name)); } } }
private async Task RedeemUsernameAndPasswordAsync() { if (string.IsNullOrEmpty(this.AccessToken)) { var creds = new Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential(this.Username, this.Password); var context = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(this.TokenService); var token = await context.AcquireTokenAsync(this.Resource, this.ClientId, creds); if (null != token) { this.AccessToken = token.AccessToken; } else { throw new InvalidOperationException( string.Format("Failed to convert username + password to access token for account: {0}", this.Name)); } } }