[Investigate] B2C Xamarin Sample getAccounts does not return an account after first sign-in
See original GitHub issueMy Code
public async Task<UserContext> SingInWithoutInteractively()
{
UserContext newContext;
try
{
// acquire token silent
newContext = await AcquireToken();
} catch
{
newContext = null;
}
return newContext;
}
public async Task<UserContext> SignInAsync()
{
UserContext newContext;
try
{
// acquire token silent
newContext = await AcquireToken();
}
catch (MsalUiRequiredException)
{
// acquire token interactive
newContext = await SignInInteractively();
}
return newContext;
}
private async Task<UserContext> AcquireToken()
{
IEnumerable<IAccount> accounts = await _pca.GetAccountsAsync();
AuthenticationResult authResult = await _pca.AcquireTokenSilent(B2CConstants.Scopes, GetAccountByPolicy(accounts, B2CConstants.PolicySignUpSignIn))
.WithB2CAuthority(B2CConstants.AuthoritySignInSignUp)
.ExecuteAsync();
var newContext = UpdateUserInfo(authResult);
return newContext;
}
private async Task<UserContext> SignInInteractively()
{
IEnumerable<IAccount> accounts = await _pca.GetAccountsAsync();
AuthenticationResult authResult = await _pca.AcquireTokenInteractive(B2CConstants.Scopes)
.WithPrompt(Prompt.SelectAccount)
.WithAccount(GetAccountByPolicy(accounts, B2CConstants.PolicySignUpSignIn))
.ExecuteAsync();
var newContext = UpdateUserInfo(authResult);
return newContext;
}
private IAccount GetAccountByPolicy(IEnumerable<IAccount> accounts, string policy)
{
foreach (var account in accounts)
{
string userIdentifier = account.HomeAccountId.ObjectId.Split('.')[0];
if (userIdentifier.EndsWith(policy.ToLower())) return account;
}
return null;
}
Expected behavior
After first login, I think _pca.GetAccountsAsync() should return accounts list and be able to refresh token
Actual behavior
always _pca.GetAccountsAsync() returns empty array so, can’t refresh token So it ask to login every time app launches.
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (3 by maintainers)
Top Results From Across the Web
Not Returning from B2C Login - xamarin
I'm trying to follow this guide against my tenant but after I sign-in, I'm not returning to my Android Xamarin app. I've updated...
Read more >Authenticate user in xamarin using AD B2C
I tried this sample https://t.co/E1wfsbGcHa. However, after login it goes back to the login page instead of the login result page where the ......
Read more >User Authentication in Xamarin with Azure AD B2C
In this post we'll examine what you need to do to implement Azure AD B2C ... that we want to collect and return...
Read more >Authenticate Users with Azure Active Directory B2C
It allows users to sign in to your application using their existing social accounts or custom credentials such as email or username, and ......
Read more >Xamarin + Azure Active Directory B2C - Matt Soucoup
Add Azure Active Directory B2C authentication to your Xamarin app. Recorded February 13, 2018 For more great, cross-platform mobile ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jennyf19 , I am using simulator- google pixel-2 Pie 9.0
@jennyf19 , almost didn’t changed, but the authentication code is the code provided