您好我使用默认MVC Google身份验证使用Google登录我已登录但我也要导入Gmail联系人列表
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "<<Client Id>>",
ClientSecret = "<<Client Secret>>",
});
我尝试了很多方法,比如我尝试下面但是没有成功
var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
{
ClientId = "<<Client Id>>",
ClientSecret = "<<Client Secret>>",
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnAuthenticated = async context =>
{
//context.Identity.AddClaim(new Claim("picture", context.User.GetValue("picture").ToString()));
//context.Identity.AddClaim(new Claim("profile", context.User.GetValue("profile").ToString()));
//context.Identity.AddClaim(new Claim("contacts", context.User.GetValue("contacts").ToString()));
var userDetail = context.User;
context.Identity.AddClaim(new Claim(ClaimTypes.Name, context.Identity.FindFirstValue(ClaimTypes.Name)));
context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Identity.FindFirstValue(ClaimTypes.Email)));
var gender = userDetail.Value<string>("gender");
context.Identity.AddClaim(new Claim(ClaimTypes.Gender, gender));
var picture = userDetail.Value<string>("picture");
context.Identity.AddClaim(new Claim("picture", picture));
//return Task.FromResult(0);
}
}
};
//googleOAuth2AuthenticationOptions.Scope.Add("email");
googleOAuth2AuthenticationOptions.Scope.Add("https://www.googleapis.com/auth/plus.login");
googleOAuth2AuthenticationOptions.Scope.Add("https://www.googleapis.com/auth/userinfo.email");
app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);
有没有办法在使用此app.UseGoogleAuthentication()函数的Owin中间件中使用Google Apis,如Google.Contacts,Google.GData.Client和Google.GData.Extensions?