当google / facebook身份验证登录=>
时,我从角度6 @localhost:4200向服务器发出了发布请求signupExternalUser(accesstoken) {
const httpOptions = {
headers: new HttpHeaders({
'content-type': 'application/JSON',
'Authorization': 'Bearer ' + accesstoken
})
};
this.http.post<any>('http://localhost:57310/api/Account/RegisterExternal',{}, httpOptions)
.subscribe((response: any) => {//do this;},(err: HttpErrorResponse) => { alert(err); })};
在WebAPI中,我的响应为=>
// POST api/Account/RegisterExternal
[OverrideAuthentication]
[HostAuthentication(DefaultAuthenticationTypes.ExternalBearer)]
[Route("RegisterExternal")]
public async Task<IHttpActionResult> RegisterExternal()
{
var info = await Authentication.GetExternalLoginInfoAsync();
if (info == null)
{
return InternalServerError();
}
var user = new ApplicationUser() { UserName = info.Email, Email = info.Email };
IdentityResult result = await UserManager.CreateAsync(user);
if (!result.Succeeded)
{
return GetErrorResult(result);
}
result = await UserManager.AddLoginAsync(user.Id, info.Login);
if (!result.Succeeded)
{
return GetErrorResult(result);
}
return Ok();
}
现在,我在这里 http://localhost:57310
用于我的服务器,尽管facebook不支持非https uri,但google身份验证工作正常。因此,这不是错误。
但是,我将服务器更改为 https://localhost:44305
,并且两次登录均返回错误。
错误是await Authentication.GetExternalLoginInfoAsync();
返回null。
我在个人用户帐户中使用owin中间件来使用asp.net身份