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)
- {
-
- 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());
- }
-
- if (context.ClientId == null)
- {
- context.Validated();
- }
- return Task.FromResult<object>(null);
- }