2014-02-22 35 views
4

我有asp.net的indentity工作的罰款。然而,當一個用戶登錄時,谷歌會詢問用戶是否確定要提供以下信息:ASP.Net身份提供商請求太多信息

- 查看你的電子郵件地址
- 查看有關您的帳戶

問題的基本信息是,我不甚至不需要那些信息。我只想要一種獨特的方式來識別用戶(它提供的)。我不想讓用戶以爲我要去垃圾郵件他們,當他們登錄

在Startup.Auth.cs我用一個很香草谷歌設置:

app.UseGoogleAuthentication(); 

編輯:解

布羅克的回答讓我找到了正確的解決方案。關鍵是將「openid」添加到範圍中。

var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions 
     { 
      ClientId = "XXXX", 
      ClientSecret = "YYYY", 
      CallbackPath = new PathString("/Account/LoginCallback/"), 
     }; 

    googleOAuth2AuthenticationOptions.Scope.Add("openid"); //!Important 

    app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions); 
+0

這是因爲http://www.symbolsource.org/Public/Metadata/NuGet/Project/Microsoft.Owin.Security.Google/2.1.0-rc1/Release/.NETFramework,Version%3Dv4.5/ Microsoft.Owin.Security.Google/Microsoft.Owin.Security.Google/GoogleOAuth2AuthenticationHandler.cs?ImageName=Microsoft.Owin.Security.Google默認範圍是 範圍=「OpenID的個人資料的電子郵件」; –

+0

很好,googleOAuth2AuthenticationOptions.Scope.Add(「openid」)的作品。如果你只想要電子郵件許可。使用(「openid電子郵件」) –

回答

3

在武士刀V2中間件谷歌的支持是隻開放ID,它是硬編碼到請求的電子郵件。

在V2.1他們現在有OAuth2用戶的支持,這意味着GoogleAuthenticationOptions有一個作用域屬性,它允許你控制你從谷歌問。但這意味着您需要像設置其他OAuth2提供程序一樣設置您的客戶端應用程序(因此您需要註冊並獲取客戶端ID /密碼)。