public async Task <IMsalResult> SilentLoginAsync(string policy) { try { var accounts = await AuthClient.GetAccountsAsync(); var builder = AuthClient.AcquireTokenSilent(Config.Scopes, accounts.FirstOrDefault()); if (Config.IsB2C) { builder.WithB2CAuthority(Config.GetB2CAuthority(policy)); } var authResult = await builder.WithForceRefresh(true) .ExecuteAsync(); _authResult.OnNext(authResult); _accessToken.OnNext(authResult.AccessToken); return(new MsalResult(authResult)); } catch (Exception ex) { return(new MsalResult(ex)); } }
public async Task LogoutAsync() { foreach (var account in await AuthClient.GetAccountsAsync()) { await AuthClient.RemoveAsync(account); } }
public async Task LogoutAsync() { foreach (var account in await AuthClient.GetAccountsAsync()) { await AuthClient.RemoveAsync(account); } _accessToken.OnNext(null); _authResult.OnNext(null); }
private async Task <AuthenticationResult> AcquireTokenInteractive(string policy) { IEnumerable <IAccount> accounts = await AuthClient.GetAccountsAsync(); var account = GetAccountByPolicy(accounts, policy); var builder = AuthClient.AcquireTokenInteractive(Config.Scopes) .WithAccount(account) #if __ANDROID__ .WithParentActivityOrWindow(Xamarin.Essentials.Platform.CurrentActivity) #endif .WithUseEmbeddedWebView(true) .WithAuthority(Config.GetB2CAuthority(policy)); return(await builder.ExecuteAsync()); }
public async Task <AuthenticationResult> SilentLoginAsync(string policy) { AuthenticationResult result = null; try { var accounts = await AuthClient.GetAccountsAsync(); result = await AuthClient.AcquireTokenSilent(Options.Scopes, accounts.FirstOrDefault()) .WithB2CAuthority(Options.GetB2CAuthority(policy)) .WithForceRefresh(true) .ExecuteAsync(); } catch (Exception ex) { LogException(ex, "SilentLoginAsync", policy); } return(result); }
public Task <IEnumerable <IAccount> > GetAccountsAsync() => AuthClient.GetAccountsAsync();