I have a xamarin form app that needs to implement 2fa.
on the login page, I call the send email and send the code by email to the user.
public async Task SendSecurityCode(string provider)
{
SendSecurityCodeModel model = new SendSecurityCodeModel() { SelectedProvider = provider,
await _accountAppService.SendSecurityCode(model);
}
then when I got the code by user I can't get true through Api call! ViewModel:
public async Task VerifySecurityCode(string provider,string code)
{
VerifySecurityCodeModel model = new VerifySecurityCodeModel() { Provider = provider,password= Password, tenancyName = _applicationContext.CurrentTenant.TenancyName, usernameOrEmailAddress = _userName, Code = code,UserId = _userId,TenantId = _applicationContext.CurrentTenant.TenantId };
var result = await _accountAppService.VerifySecurityCode(model);
}
Appservice:
[UnitOfWork]
public async Task<bool> VerifySecurityCode(VerifySecurityCodeModel model)
{
using (_unitOfWorkManager.Current.SetTenantId(model.TenantId))
{
var loginResult = await _logInManager.LoginAsync(model.usernameOrEmailAddress, model.password, model.tenancyName);
var signInResult = await _signInManager.SignInOrTwoFactorAsync(loginResult, false);
try
{
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
}
catch (Exception)
{
throw new UserFriendlyException(L(" var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();"));
}
var result = await _signInManager.TwoFactorSignInAsync(
model.Provider,
model.Code,
model.RememberMe = true,
model.RememberBrowser = true
);
return result.Succeeded;
}
}
when I call VerifySecurityCode, it always return false, but if call it by postman it return true only if I set bearer token for authorization tab.
so the issue when I call it through app and it returns false is it doesn't send the token because it is not logged in yet! I don't know what is the solution! please help me, it's while I can't resolve it.