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
- public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
- {
- var identity = new ClaimsIdentity(context.Options.AuthenticationType);
- string Email = context.OwinContext.Get<string>("Email");
- if (Email == "[email protected]" && context.Password == "admin")
- {
- identity.AddClaim(new Claim(ClaimTypes.Role, "admin"));
- identity.AddClaim(new Claim("username", "admin"));
- identity.AddClaim(new Claim(ClaimTypes.Name, "Hi Admin"));
- context.Validated(identity);
- }
- else if (context.UserName == "user" && context.Password == "user")
- {
- identity.AddClaim(new Claim(ClaimTypes.Role, "user"));
- identity.AddClaim(new Claim("username", "user"));
- identity.AddClaim(new Claim(ClaimTypes.Name, "Hi User"));
- context.Validated(identity);
- }
- else
- {
- context.SetError("invalid_grant", "Provided username and password is incorrect");
- return;
- }
- }
- public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
- {
- //Here we get the Custom Field sent in /Token
- var Email = context.Parameters.Where(x => x.Key == "Email").Select(x => x.Value).FirstOrDefault();
- if (Email.Length > 0 && Email[0].Trim().Length > 0)
- {
- context.OwinContext.Set<string>("Email", Email[0].Trim());
- }
- // Resource owner password credentials does not provide a client ID.
- if (context.ClientId == null)
- {
- context.Validated();
- }
- return Task.FromResult<object>(null);
- }

Sachin SinghRank #66 · 26.2K reputationPosted May 13, 2021, 8:42 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted May 13, 2021, 8:12 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted May 13, 2021, 10:15 AM EDT
selvi jpRank #4,123 · 364 reputationPosted May 13, 2021, 8:37 AM EDT
selvi jpRank #4,123 · 364 reputationPosted May 13, 2021, 9:56 AM EDT