1

我正在尝试实现 Google OpenID 登录

我有以下问题:

  1. 我在哪里可以获得该行中变量 openidurl 的值

IAuthenticationRequest 请求 = openid.CreateRequest(openidurl);

2.. 我怎样才能只限制某个 Google Apps 域的登录?

代码如下:

    protected void Page_Load(object sender, EventArgs e)
    {
        OpenIdRelyingParty openid = new OpenIdRelyingParty();
        var response = openid.GetResponse();
        if (response != null)
        {
            switch (response.Status)
            {
                case AuthenticationStatus.Authenticated:

                    var fetch = response.GetExtension<FetchResponse>();
                    string email = string.Empty;
                    if (fetch != null)
                    {
                        email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
                    }

                    //FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier, false);
                    Session["email"] = email;
                    Response.Redirect("profile.aspx");
                    break;
            }
        }
    }

    protected void OpenLogin_Click(object src, CommandEventArgs e)
    {
        string openidurl = "https://www.google.com/accounts/o8/id?id=initial_id"; //auxiliary initial id. ??????
        //The Request
        using (OpenIdRelyingParty openid = new OpenIdRelyingParty())
        {
            IAuthenticationRequest request = openid.CreateRequest(openidurl);

            var fetch = new FetchRequest();
            fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
            request.AddExtension(fetch);

            // Send your visitor to their Provider for authentication.
            request.RedirectToProvider();
        }
    }
}

在此先感谢,这是我第一次使用 Google OpenID。

4

0 回答 0