selvi jp

selvi jp

  • NA
  • 323
  • 77.3k

I want to login with email and phone number oauth

May 13 2021 9:43 AM
I want to login with email or phone number in oauth
 
email is default here ,but i want to compare email and phone number from Database
  1. public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)  
  2. {  
  3.     var identity = new ClaimsIdentity(context.Options.AuthenticationType);  
  4.     string Email = context.OwinContext.Get<string>("Email");  
  5.     if (Email == "[email protected]" && context.Password == "admin")  
  6.     {  
  7.         identity.AddClaim(new Claim(ClaimTypes.Role, "admin"));  
  8.         identity.AddClaim(new Claim("username""admin"));  
  9.         identity.AddClaim(new Claim(ClaimTypes.Name, "Hi Admin"));  
  10.         context.Validated(identity);  
  11.     }  
  12.     else if (context.UserName == "user" && context.Password == "user")  
  13.     {  
  14.         identity.AddClaim(new Claim(ClaimTypes.Role, "user"));  
  15.         identity.AddClaim(new Claim("username""user"));  
  16.         identity.AddClaim(new Claim(ClaimTypes.Name, "Hi User"));  
  17.         context.Validated(identity);  
  18.     }  
  19.     else  
  20.     {  
  21.         context.SetError("invalid_grant""Provided username and password is incorrect");  
  22.         return;  
  23.     }  
  24. }  
  25.   
  26. public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)  
  27. {  
  28.     //Here we get the Custom Field sent in /Token      
  29.     var Email = context.Parameters.Where(x => x.Key == "Email").Select(x => x.Value).FirstOrDefault();  
  30.     if (Email.Length > 0 && Email[0].Trim().Length > 0)  
  31.     {  
  32.         context.OwinContext.Set<string>("Email", Email[0].Trim());  
  33.     }  
  34.     // Resource owner password credentials does not provide a client ID.      
  35.     if (context.ClientId == null)  
  36.     {  
  37.         context.Validated();  
  38.     }  
  39.     return Task.FromResult<object>(null);  
  40. }  

Answers (5)