我正在學習如何使用VS 2015中的默認MVC模板使用OWIN外部驗證。我啓用了Facebook驗證並添加了範圍「電子郵件」,期望用戶的電子郵件由Facebook返回在用戶通過認證後(根據this)。不過,上下文中沒有電子郵件。用戶JSON對象和上下文。電子郵件也是空的。正在檢索OWIN登錄用戶的Facebook電子郵件
這在Startup.Auth.cs
var facebookOptions = new FacebookAuthenticationOptions
{
AppId = "XXXXXX",
AppSecret = "XXXXXX",
Provider = new FacebookAuthenticationProvider
{
OnAuthenticated = context =>
{
// Retrieve the OAuth access token to store for subsequent API calls
var accessToken = context.AccessToken;
// Retrieve the username
var facebookUserName = context.UserName;
// WHY IS IT EMPTY?
var facebookEmail = context.Email;
// You can even retrieve the full JSON-serialized user
var serializedUser = context.User;
return Task.FromResult(0);
}
}
};
facebookOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookOptions);
任何想法相關的代碼缺少什麼?爲什麼Facebook電子郵件地址不被退回?
可能有用的信息在這裏:HTTP: //stackoverflow.com/a/32636149/3130094 –
謝謝@JamieDunstan - 這是有幫助的! – Andrey