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
Two Factor authentication in Web Api mvc
Apr 29 2021 5:08 AM
I want email or phonenumber login .in default Web Api have username authentication i don't know how to customize that.this is my mvc code.i just call web api here in https://localhost:44327/Token
[AllowAnonymous]
//[ValidateAntiForgeryToken]
[HttpPost]
public async Task<ActionResult> Login(Login model, string returnUrl)
{
/*This will depend totally on how you will get access to the identity provider and get your token, this is just a sample of how it would be done*/
/*Get Access Token Start*/
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("https://localhost:44327/Token");
var postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("Username", model.UserName));
postData.Add(new KeyValuePair<string, string>("Email", model.Email));
postData.Add(new KeyValuePair<string, string>("Password", model.Password));
postData.Add(new KeyValuePair<string, string>("grant_type", "password"));
HttpContent content = new FormUrlEncodedContent(postData);
HttpResponseMessage response = await httpClient.PostAsync("https://localhost:44327/Token", content);
// response.EnsureSuccessStatusCode();
string AccessToken = response.Content.ReadAsStringAsync().Result;
//string AccessToken = /*Newtonsoft.Json.*/JsonConvert.DeserializeObject<string>(result);
/*Get Access Token End*/
if (AccessToken.Length >= 200)
{
TempData["userid"] = "userid";
TempData["name"] = model.UserName;
return RedirectToAction("Home");
}
ModelState.AddModelError("Username", "Username and password is not valid");
return View(model);
}
Reply
Answers (
3
)
Compare in a single controller two models
I want both email and mobile phone authentication at the same time