问题
i am trying to setup DotNetOpenAuth using the OpenIdAjaxTextBox but i have two problems
i want to be able to get the users email address and i think that is done in the loggedin event (right?) but that event is never called, i have tried to setup a breakpoint there but i never get to it.
when I type in the openid provider in the OpenIdAjaxTextBox (lets say Gmail), I get the login button in the textbox so I click on it a new windows pops up and displayes the Gmail login form but after that i type my username and password and click on login that popup window refresh and my own website loads in that popup window, i would expect the pop up window to close after I login not redirect me to my site.
here is the code I using
<%@ Register Assembly="DotNetOpenAuth" Namespace="DotNetOpenAuth.OpenId.RelyingParty"
TagPrefix="openid" %>
<openid:OpenIdAjaxTextBox ID="OpenIdAjaxTextBox1" runat="server"
OnLoggingIn="openIdtxtbx_LoggingIn"
OnLoggedIn="openIdtxtbx_LoggedIn"
OnClientAssertionReceived="onauthenticated(sender)"
OnUnconfirmedPositiveAssertion="openIdtxtbx_UnconfirmedPositiveAssertion" />
Protected Sub openIdtxtbx_LoggedIn(ByVal sender As Object, ByVal e As OpenIdEventArgs)
' Do something here
Dim claimedId As String = e.Response.Status
End Sub
Protected Sub openIdtxtbx_LoggingIn(ByVal sender As Object, ByVal e As OpenIdEventArgs)
' Retrieve the email address of the user
Dim c As New ClaimsRequest
c.Email = DemandLevel.Require
e.Request.AddExtension(c)
End Sub
Protected Sub openIdtxtbx_UnconfirmedPositiveAssertion(ByVal sender As Object, ByVal e As OpenIdEventArgs)
' This is where we register extensions that we want to have available in javascript
' on the browser.
OpenIdAjaxTextBox1.RegisterClientScriptExtension(Of ClaimsResponse)("sreg")
End Sub
回答1:
The OpenIdAjaxTextBox.LoggedIn
event isn't fired until a postback from the web page -- a submit button of some sort. The Login button on the text box itself is not a postback, so you need to add some other submit button to your page.
e.Response.Status
is not a claimed identifier. You should change your LoggedIn event handler to read:
Dim claimedId As String = e.ClaimedIdentifier
You won't get an email address from Google using ClaimsRequest
unless you are using the AXFetchAsSregTransform behavior.
updated:
Finally regarding the popup window not disappearing at the end of login... it should work the way you think it should. But there's a "bug" that the OpenIdAjaxTextBox
doesn't support POST responses, which is what you get when you ask for attributes due to the size of the response payload. v3.3 fixes this, but it isn't released yet. Sorry about that.
来源:https://stackoverflow.com/questions/1539671/dotnetopenauth-get-email-and-redirect-problem