MVC

2015-01-09 7 views
5
में गूगल OAuth एपीआई से जन्म तिथि प्राप्त कर रहा है

मैं उपयोगकर्ताMVC

#region Google 
var googleAuthenticationOptions = new GoogleOAuth2AuthenticationOptions() 
     { 
      ClientId = ConfigurationManager.AppSettings["Google_AppID"], 
      ClientSecret = ConfigurationManager.AppSettings["Google_AppSecret"] 
     }; 
     googleAuthenticationOptions.Scope.Add("profile"); 
     googleAuthenticationOptions.Scope.Add("email"); 
googleAuthenticationOptions.Provider = new GoogleOAuth2AuthenticationProvider() 
     { 
      OnAuthenticated = async context => 
      { 
       //context.Identity.AddClaim(new Claim("birthday", context.User.GetValue("birthday").ToString())); 
       string claimType; 
       bool bAddClaim = false; 
       foreach (var claim in context.User) 
       { 

        claimType = string.Empty; 
        bAddClaim = false; 
        switch (claim.Key) 
        { 
         case "given_name": 
          claimType = "FirstName"; 
          bAddClaim = true; 
          break; 
         case "family_name": 
          claimType = "LastName"; 
          bAddClaim = true; 
          break; 
         case "gender": 
          claimType = "gender"; 
          bAddClaim = true; 
          break; 
        } 

        if (bAddClaim) 
        { 
         string claimValue = claim.Value.ToString(); 
         if (!context.Identity.HasClaim(claimType, claimValue)) 
          context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "Google")); 
        } 
       } 
      } 
     }; 

का डेटा एक्सेस करने निम्नलिखित स्कोप ब्रेकप्वाइंट मैं निम्नलिखित हो रही है डाल से कंधा मिलाकर foreach पाश में context.user पर डिबगिंग जबकि जोड़ लिया है सूचना

 
{ 
"sub": "101111724115925537597", 
"name": "Alok Nath", 
"given_name": "Alok", 
"family_name": "Nath", 
"profile": "https://plus.google.com/101111724115925537597", 
"picture":"https://lh3.googleusercontent.com/XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/ 
      photo.jpg", 
"email": "[email protected]", 
"email_verified": true, 
"gender": "male", 
"locale": "en" 
} 

तो "प्रोफ़ाइल" दायरा जोड़ने के बाद भी, मुझे वापसी मूल्य के हिस्से के रूप में जन्मदिन नहीं मिलता है। मैंने यह सुनिश्चित कर लिया है कि प्रोफाइल में जन्मदिन की दृश्यता जनता के लिए निर्धारित है यानी यह सभी के लिए दृश्यमान है। क्या Google से जन्मदिन पुनर्प्राप्त करने के लिए मुझे कोई विशिष्ट दायरा या विशिष्ट सेटिंग्स की आवश्यकता है?

या वहां इस समस्या को हल करने के लिए समाधान

+0

आप अपने प्रोजेक्ट को nuget पैकेज ** Google.Apis.OAuth2.v2 क्लाइंट लाइब्रेरी ** जोड़ने की कोशिश की? यह आपको तारों का उपयोग करने के बजाय आपके दायरे के लिए एक enum देता है, आप बस कह सकते हैं: 'स्कोप = {Oauth2Service.Scope.UserinfoProfile, Oauth2Service.Scope.UserinfoEmail} ' –

उत्तर

0

मुझे लगता है कि आप इस stackoverflow उपयोगकर्ता ने सुझाव दिया जन्म तिथि पाने के लिए https://www.googleapis.com/auth/plus.login लिए गुंजाइश निर्धारित करने की आवश्यकता पोस्ट करें किसी भी तरह से है:

Retrieving date of birth and marital status with Google OAuth API

अधिक जानकारी भी यहां पाया जा सकता: https://developers.google.com/+/api/oauth#plus.login