我一直在四处寻找解决问题的正确方法,我有一个asp.net Webapi,并向用户名和密码/token
发送 POST 请求(其中{ {1}})以获取令牌
grant_type=password
问题是,如果用户使用外部身份验证提供商(例如Google)进行了注册,那么我对POST /token HTTP/1.1
Host: localhost:00000
Content-Type: application/x-www-form-urlencoded
grant_type=password&username=myuser&password=mypassword
的POST请求在下面的RestSharp代码(例如邮递员)中会如何?
/token
在这种情况下,当用户使用Google登录时,由于public static bool ClaimAuthentication_API(LoginViewModel UserLogin)
{
try
{
var client = new RestClient( KeyVault.Environmental_Variables_Application.API_CON + "/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("undefined", "grant_type=password&username=" + UserLogin.Email + "&password=" + UserLogin.Password, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
string JSONResponse = response.Content.ToString();
dynamic data = JObject.Parse(JSONResponse);
string AUTH_TOKEN = data.access_token
return true;
}
catch (Exception)
{
return false;
}
}
如下所示,我没有LoginViewModel
携带我发送给/token
的密码< / p>
ExternalLoginCallback
使用“ ExternalLogin”(例如Google)时,如何向public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false });
case SignInStatus.Failure:
default:
ViewBag.ReturnUrl = returnUrl;
ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email, FullName = loginInfo.DefaultUserName, ProfileImage = profilePicURL});
}
}
发送POST请求。