TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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
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
);
}
Reply
Answers (
5
)
OTP in Text Local
Create ASP.NET Core Web API with postgresql without using EF