1
我想註冊一個用戶,通過外部供應商(如Facebook),爲了得到我需要的信息,我配置FacebookProvider如下如何獲取Facebook的用戶信息的ASP.NET Web API 2
var options = new FacebookAuthenticationOptions {
AppId = "***",
AppSecret = "***",
Scope = { "email" },
Provider = new FacebookAuthenticationProvider {
OnAuthenticated = (context) => {
foreach (var x in context.User)
{
var claimType = string.Format("urn:facebook:{0}", x.Key);
string claimValue = x.Value.ToString();
if (!context.Identity.HasClaim(claimType, claimValue))
context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, XmlSchemaString, "Facebook"));
}
return Task.FromResult(0);
}
}
};
options.Fields.Add("id");
options.Fields.Add("name");
options.Fields.Add("email");
options.SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalBearer;
app.UseFacebookAuthentication(options);
在OnAuthenticated調試時我看到所有的必填字段,但是當我打電話RegisterExternal從郵遞員如下PIC
GetExternalLoginInfoAsync返回null
var info = await Authentication.GetExternalLoginInfoAsync();
if (info == null)
{
return InternalServerError();
}
那麼如何檢索郵件等查詢字段?我認爲所有必要的信息都存儲在cookie中,但是如何將它們傳輸到服務器並提取Identity實例?
所有的nuget包已經更新到最新版本
p.s.我計劃從iOS應用程序使用API