OpenId implementation in VB.NET(gmail)

Posted by Balajikcp8 under VB.NET category on | Points: 40 | Views : 7295
Simple example for OpenId implementation in

This code is used to validate gmail username and password..You can use gmail id as openid for your site to authenticate users

in .aspx page

<form id="form1" runat="server">

<div id="openid" runat="server">
<asp:Button ID="btnLoginToGoogle" Runat="server" Text="Google Login" OnCommand="OpenLogin_Click"
Font-Bold="True" Font-Italic="True" Width="162px" />
<br />

<br />
<asp:Label ID="lblMessage" runat="server" Text="Label"></asp:Label>


in .vb

Imports DotNetOpenAuth.OpenId
Imports DotNetOpenAuth.OpenId.RelyingParty
Imports DotNetOpenAuth.OpenId.Extensions.AttributeExchange
Imports System
Partial Class demobooking_open
Inherits System.Web.UI.Page

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim OIDRP As New OpenIdRelyingParty()
Dim str = OIDRP.GetResponse()

If str IsNot Nothing Then
Select Case str.Status
Case AuthenticationStatus.Authenticated

Dim fetch As FetchResponse = str.GetExtension(Of FetchResponse)()
Session("GoogleIdentifier") = str.ClaimedIdentifier.ToString()
lblMessage.Text = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email) -->display email id of user
Exit Select

Case AuthenticationStatus.Canceled
lblMessage.Text = "Cancelled."
Exit Select

Case AuthenticationStatus.Failed
lblMessage.Text = "Login Failed."
Exit Select
End Select
End If
End Sub

Protected Sub OpenLogin_Click(sender As Object, e As System.Web.UI.WebControls.CommandEventArgs) Handles btnLoginToGoogle.Command
Dim str As String = e.CommandArgument.ToString()
Dim openid As New OpenIdRelyingParty()
Dim b = New UriBuilder(Request.Url) With {.Query = ""}
Dim req = openid.CreateRequest(str, b.Uri, b.Uri)
Dim fetch As New FetchRequest()
fetch.Attributes.Add(New AttributeRequest(WellKnownAttributes.Contact.Email, True))

End Sub
End Class

Comments or Responses

Posted by: Saisindura on: 8/12/2013 Level:Starter | Status: [Member] | Points: 10
Hello sir,
could you please tell me,
is openid is free?
how to openid and how to integrate openid into website?
what are config changes?

Login to post response