public async void RequestInteractiveSignIn( string[] scopes, string[]?extraScopes = null) { try { var builder = _msalSdkClient.AcquireTokenInteractive(scopes); if (extraScopes != null) { builder = builder.WithExtraScopesToConsent(extraScopes); } var authResult = await builder.ExecuteAsync(); if (!string.IsNullOrWhiteSpace(authResult.AccessToken)) { InteractiveSignInCompleted?.Invoke(this, EventArgs.Empty); } } catch (MsalException e) when(e.ErrorCode == "authentication_canceled") { // this is fine } catch (MsalException e) { _telemetry.TrackError(e, new Dictionary <string, string> { { "trace", e.StackTrace }, { "scopes", string.Join(",", scopes) }, { "extraScopes", string.Join(",", extraScopes ?? new string[0]) } }); } }
public async Task RequestInteractiveSignIn( string[] scopes, string[]?extraScopes = null) { try { var builder = _msalSdkClient .AcquireTokenInteractive(scopes) // Use custom web ui because built-in // used by MSAL crashes on ARM devices. // And the proposed workaround, WAM, doesn't work on xbox. .WithCustomWebUi(_customWebUi); if (extraScopes is not null) { builder = builder.WithExtraScopesToConsent(extraScopes); } var authResult = await builder.ExecuteAsync(); if (!string.IsNullOrWhiteSpace(authResult.AccessToken)) { InteractiveSignInCompleted?.Invoke(this, EventArgs.Empty); } } catch (MsalException e) when(e.ErrorCode == "authentication_canceled") { // this is fine } catch (MsalException e) { _telemetry.TrackError(e, new Dictionary <string, string> { { "trace", e.StackTrace }, { "scopes", string.Join(",", scopes) }, { "extraScopes", string.Join(",", extraScopes ?? Array.Empty <string>()) } }); } }
private async Task RequestTokenAndSaveAccount(WebAccountProvider Provider, string Scope, string ClientID) { ClearStoredInfo(); try { WebTokenRequest webTokenRequest = new WebTokenRequest(Provider, Scope, ClientID); WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.RequestTokenAsync(webTokenRequest); if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success) { var response = webTokenRequestResult.ResponseData[0]; _userSettings.Set(UserSettingsConstants.CurrentUserId, response.WebAccount.Id); _userSettings.Set(UserSettingsConstants.CurrentUserProviderId, response.WebAccount.WebAccountProvider.Id); } } catch { } InteractiveSignInCompleted?.Invoke(this, EventArgs.Empty); }