private async Task <IAuthenticationResult> PromptUserForAuthenticationWithClientSecretAsync( string serviceResourceId, string userId) { IAuthenticationResult authenticationResult = null; var clientCredential = this.GetClientCredentialForAuthentication(this.clientId, this.clientSecret); var userIdentifier = this.GetUserIdentifierForAuthentication(userId); var redirectUri = new Uri(returnUrl); var requestUri = new Uri(this.oAuthHelper.GetAuthorizationCodeRequestUrl( this.clientId, this.returnUrl, null, userId)); var authenticationResponseValues = await webAuthenticationUi.AuthenticateAsync( requestUri, redirectUri).ConfigureAwait(false); OAuthErrorHandler.ThrowIfError(authenticationResponseValues); string code; if (authenticationResponseValues != null && authenticationResponseValues.TryGetValue("code", out code)) { authenticationResult = await this.authenticationContextWrapper.AcquireTokenByAuthorizationCodeAsync( code, redirectUri, clientCredential, serviceResourceId).ConfigureAwait(false); } return(authenticationResult); }
public async Task <string> GetAuthorizationCodeAsync( string clientId, string returnUrl, string[] scopes, IWebAuthenticationUi webAuthenticationUi, string userId = null) { if (webAuthenticationUi != null) { var requestUri = new Uri( this.GetAuthorizationCodeRequestUrl( clientId, returnUrl, scopes, userId)); var authenticationResponseValues = await webAuthenticationUi.AuthenticateAsync( requestUri, new Uri(returnUrl)).ConfigureAwait(false); OAuthErrorHandler.ThrowIfError(authenticationResponseValues); string code; if (authenticationResponseValues != null && authenticationResponseValues.TryGetValue("code", out code)) { return(code); } } return(null); }