本文介绍了Google客户端API-将oauth身份验证限制为我的域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人通过限制用户可以登录的域来使用Google Client API
对其域进行授权吗?
Has anyone had any experience of using the Google Client API
to authorise against their domain by restricting the domain a user can login with?
所需的titbit似乎是一个qs参数:hd='[Domain name]'
The titbit that is required appears to be a qs parameter: hd='[Domain name]'
但是OAuth2Parameters
参数对象没有类似之处
but there's nothing similar in the OAuth2Parameters
parameters object
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);
推荐答案
因此,实际上,我们所需要做的就是这样调整网址:
so,in fact, all we need is to adjust the url thus:
var authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(oap);
authorizationUrl += "&hd=" + "mydomain.com".UrlEncode();
return Redirect(authorizationUrl);
希望可以帮助某人.
这篇关于Google客户端API-将oauth身份验证限制为我的域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!