1

I am using dotnetopenid in my asp.net 2.0 and VS 2005.I have done only this work and a succeful authentication is done by me.I have a login page and after authentication it goes to food.aspx.I only want to display the email address of user on food.aspx after authentication from google.I have done only following work for the openid nothing else please tell me which code i have to write in login.aspx or food.aspx to display the email address of user.

<%@ Register Assembly="DotNetOpenAuth" Namespace="DotNetOpenAuth.OpenId.RelyingParty" TagPrefix="rp" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"    Namespace="System.Web.UI" TagPrefix="asp" %>

<rp:OpenIdLogin ID="OID" runat=server Identifier="https://www.google.com/accounts/o8/id" ></rp:OpenIdLogin>

Update I have wrote this code in page load event of login.aspx

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As OpenIdEventArgs)
        Dim openid As New OpenIdRelyingParty()
        Dim request As IAuthenticationRequest = openid.CreateRequest("https://www.google.com/accounts/o8/id")
        Dim fetch As New FetchRequest()
        fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email)
        request.AddExtension(fetch)
        request.RedirectToProvider()
   End Sub

And Page Load Evemt of Food.aspx Write the follwoing code

  Dim openid As OpenIdRelyingParty = New OpenIdRelyingParty
        Dim response = openid.GetResponse
        If (Not (response) Is Nothing) Then
            Select Case (response.Status)
                Case AuthenticationStatus.Authenticated
                    Dim fetch = response.GetExtension
                    Dim email As String = String.Empty
                    If (Not (fetch) Is Nothing) Then
                        email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email)
                    End If
                    FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier, False)
            End Select
        End If

But still getting error of in login.aspx page load event in this line

fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email)

Error is

AddRequired is not a member of System.Collections.ObjectModel.KeyedCollection
(Of DotNetOpenAuth.OpenId.Extensions.AttributeExchange.AttributeRequest

what can i do for this

Umesh Awasthi
  • 22,642
  • 37
  • 122
  • 198
Adeel Aslam
  • 1,246
  • 10
  • 33
  • 61

1 Answers1

0

When your user will Authenticate himself st Google, he will be redirected back to your web-page. Since you are using open Id you can use Attribute exchange to get user email and Full name when user is being redirected back to Your web-page.

Now all you need to do is to extract the email and Name of the user from the response and display/store them as per you need.

Here is the detail how to get this using above library

openid-trying-to-get-email-address-from-google-op

Community
  • 1
  • 1
Umesh Awasthi
  • 22,642
  • 37
  • 122
  • 198
  • Sir I am usingvb.net not c# so and i also convert that code to vb.net but there are compilation errors in this code and also tell me won which event that code i have to write or any thing else this code i have to write in my web app – Adeel Aslam Dec 21 '11 at 06:28
  • i only know about java but you need to write that code at 2 steps 1.when user is being redirected to the login page 2) when user came back to your page after authentication.I believe you can figure our the compilation issue as they must be some language syntax error – Umesh Awasthi Dec 21 '11 at 06:30
  • http://stackoverflow.com/questions/8575088/display-open-id-email-on-web-page this is one more refrence for you – Umesh Awasthi Dec 21 '11 at 06:32
  • @user1109140: either you can start new question showing what you have done what error you are facing else you can mark question as unaccepted else it will give impression that your problem has been solved.My suggestion is to start new question and tag with vb.net – Umesh Awasthi Dec 21 '11 at 06:52
  • I have posted a new question with my complete coding in c# please check here and help me http://stackoverflow.com/questions/8587401/open-id-code-errors-in-my-web-app – Adeel Aslam Dec 21 '11 at 09:25