views:

110

answers:

1

I have the following code:

protected void Page_Load(object sender, EventArgs e)
{
    var openId = new OpenIdRelyingParty();
    HttpContext httpContext = HttpContext.Current;

    var headers = new WebHeaderCollection();
    foreach (string header in httpContext.Request.Headers)
    {
        headers.Add(header, httpContext.Request.Headers[header]);
    }

    string requestUrl = string.Format("http://localhost:12345/Login/{0}",
                                       httpContext.Request.Url.Query);

    var requestInfo = new HttpRequestInfo(httpContext.Request.HttpMethod,
                                            new Uri(requestUrl),
                                            httpContext.Request.RawUrl, headers,
                                            httpContext.Request.InputStream);

    var response = openId.GetResponse(requestInfo);

    if (response != null)
    {
        ClaimsResponse claimResponse = response.GetExtension<ClaimsResponse>();
        lblUser.Text = claimResponse.FullName;
        if (response.Exception != null)
        {
            lblError.Text = response.Exception.Message;
        }
    }
}

protected void btnTest_Click(object sender, EventArgs e)
{
    try
    {
        using (OpenIdRelyingParty openId = new OpenIdRelyingParty())
        {
            string identifier = @"https://www.google.com/accounts/o8/id";


            var request = openId.CreateRequest(identifier,
                                                new Realm("http://localhost:12345/"),
                                                new Uri("http://localhost:12345/Login/"));

            request.AddExtension(new ClaimsRequest
                                        {
                                            Email = DemandLevel.Require
                                        });

            request.RedirectToProvider();
        }
    }
    catch (Exception ex)
    {
        // TODO: log exception
        throw;
    }
}

When I execute the code, user is authenticated but ClaimsResponse is null.
Code works fine with MyOpenId.

Any help would be appreciated.

A: 

The information here is useful: http://stackoverflow.com/questions/1387438/retrieve-openid-user-information-claims-across-providers

The gold nugget you are likely missing in your app is the AXFetchAsSregTransform.

Andrew Arnott
Can't get it to work :(Could you edit my code and add missing part?
šljaker
No. Nothing is wrong with your code from what I can tell. The "gold nugget" link I gave you takes you to a web page with a snippet to add to your web.config file. Did you try that?
Andrew Arnott
it worked after editing web.config. Thank you.
šljaker