2017-04-19 48 views
0

我想打一個按鈕,在web表單的項目,會被重定向我登錄Google。用戶登錄後,我想從他的個人資料中獲取一些基本數據,例如電子郵件和姓名。整合谷歌登錄在web表單項目

我嘗試這樣做[Nemiro] [1]

[1]:asp.net webforms google login但是我有問題白衣它(甚至白衣其返回錯誤401的默認實例)。

我想這

var credentials = 
        GoogleWebAuthorizationBroker.AuthorizeAsync(
          new ClientSecrets { ClientId = "client-Id", ClientSecret = "client-secret" }, 
          new[] { "openid", "email" }, "user", CancellationToken.None,null); 

和它的作品,但僅限於本地主機。我不知道如何更改重定向URI也正因爲如此,我不認爲它會工作時,我會上傳它在服務器上。

此外,在YouTube上,我看到他們連接到谷歌白衣的IAppBuilder,但我不能在我的項目中使用它。

回答

0

你可能想從該網站刪除您的客戶端ID和祕密,而且在你的應用程序。以下解決方案適用於我:

var googleoptions = new GoogleOAuth2AuthenticationOptions 
     { 
      ClientId = ConfigurationManager.AppSettings["gid"], 
      ClientSecret = ConfigurationManager.AppSettings["gsecret"] 
     }; 
     googleoptions.Scope.Add("https://www.googleapis.com/auth/plus.me"); 
     googleoptions.Scope.Add("https://www.googleapis.com/auth/plus.login"); 
     googleoptions.Scope.Add("https://www.googleapis.com/auth/userinfo.email"); 
     googleoptions.Scope.Add("https://www.googleapis.com/auth/userinfo.profile"); 
     app.UseGoogleAuthentication(googleoptions); 

不要忘記將您的ID和祕密存儲在appsettings中。

爲了使它在localhost以外的地點工作,你需要的是URL添加到列表中Developersconsole of google

+0

一個問題。誰是「應用程序」,我如何將它與一個按鈕相關聯? –

+0

「應用程序」是IAppBuilder加入到啓動配置。 在文件夾「app_start」 - >「startup.auth.cs」 –

+0

我沒有它,我不能修改啓動 –