使用ASP.Net中的弹出窗口进行DotNetOpenAuth OAuth授权

时间:2013-07-11 18:41:20

标签: asp.net google-api oauth-2.0 dotnetopenauth google-oauth

我需要使用弹出窗口进行Google OAuth身份验证。我正在使用DotNetOpenAuth库进行身份验证,它正在同一页面上工作。如何在弹出窗口中执行此操作。我通过谷歌搜索环顾四周,我发现很少,其中一个是“Specify request parameters in dotnetopenauth 4”但我使用这个库的方式我不知道在哪里可以设置弹出窗口。

这是我的代码。

私有字符串AccessToken     {             get {return(string)Session [“GoogleAccessToken”]; }             设置{Session [“GoogleAccessToken”] = value; }         }

    private static readonly GoogleClient googleClient = new GoogleClient
    {
        ClientIdentifier = ConfigurationManager.AppSettings["googleConsumerKey"],
        ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(ConfigurationManager.AppSettings["googleConsumerSecret"]),
    }; 

    protected void Page_Load(object sender, EventArgs e)
    {                        
        if (googleClient != null)
        {

            if (!IsPostBack)
            {
                var authorization = googleClient.ProcessUserAuthorization();
                if (authorization != null)
                {
                    this.AccessToken = authorization.AccessToken;
                }
                else if (this.AccessToken == null)
                {
                    googleClient.RequestUserAuthorization(scope: new[] { GoogleClient.Scopes.WebMaster.SiteVerification, GoogleClient.Scopes.WebMaster.WebMasterTools });

                }
            }
        } 
    }


private static readonly AuthorizationServerDescription GoogleDescription = new AuthorizationServerDescription {
    TokenEndpoint = new Uri("https://accounts.google.com/o/oauth2/token"),
    AuthorizationEndpoint = new Uri("https://accounts.google.com/o/oauth2/auth"),   
    ProtocolVersion = ProtocolVersion.V20,            
};

你能帮我解决这个问题吗(我是ASP.Net的新手)?感谢

1 个答案:

答案 0 :(得分:1)

如果您想要一个支持客户端检测的库,包括单击按钮打开弹出窗口,您可能需要查看javascript API:

https://developers.google.com/api-client-library/javascript/features/authentication