2013-01-15 25 views
1

有沒有人有任何使用Google Client API來通過限制用戶可以登錄的域來授權他們的域名的經驗?Google客戶端API - 將oauth身份驗證限制到我的域名

所需的珍品似乎是一個QS參數:hd='[Domain name]'

但沒有什麼相似的OAuth2Parameters參數對象

var oap = new OAuth2Parameters 
{ 
     AccessToken = Current == null ? null : Current.AccessToken, 
     RefreshToken = Current == null ? null : Current.RefreshToken, 
     ClientId = GoogleClientId, 
     ClientSecret = GoogleClientSecret, 
     Scope = "https://spreadsheets.google.com/feeds https://docs.google.com/feeds https://www.googleapis.com/auth/userinfo.email", 
     RedirectUri = HttpContext.Current.Request.Url.Scheme.Concatenate("://", HttpContext.Current.Request.Url.Authority,                    "/Builder/Authentication/Receive"), 
     AccessType = "offline" //ensures a refresh token (tho not currently working), 
     *HD = //Hmm if only... :(((* 

    }; 
var authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(oap); 

return Redirect(authorizationUrl); 

回答

3

因此,事實上,我們需要的是調整網址因此:

var authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(oap); 
authorizationUrl += "&hd=" + "mydomain.com".UrlEncode(); 
return Redirect(authorizationUrl); 

希望可以幫助某人下線。

+0

哈哈,你馬上回答你自己的問題嗎?不妨將其標記爲已接受。 :-P –

+0

用戶不能只修改重定向網址,並添加自己的域名? – Tyguy7

0

使用高清參數。

Google documentation

警告:此標記在的OAuth 1.0 API參考記載。在版本2中沒有記錄,但工作。

重要提示:OAuth 1.0已經正式棄用4月20日,2012年 將繼續按照我們的棄用政策的工作,但我們建議您儘快遷移至OAuth 2.0。