我一直在使用DoNetOpenAuth库并遵循示例here
身份验证正在运行,但即使我需要电子邮件,claimresponse也为null。 事实上,我要求的并不重要,声明响应始终为空。不确定我做错了什么,我很感激你的帮助。
提前致谢。
这是我的登录按钮代码
protected void btnSubmit_Click( object sender, EventArgs e )
{
//Login button has been pushed. Add an extension and redirect
using (OpenIdRelyingParty openId = new OpenIdRelyingParty())
{
IAuthenticationRequest request = openId.CreateRequest( txtOpenID.Text );
request.AddExtension( new ClaimsRequest
{
Email = DemandLevel.Require,
Country = DemandLevel.Request,
TimeZone = DemandLevel.Request
} );
request.RedirectToProvider();
}
}
这是页面加载代码。 ClaimsResponse变量总是为null。
protected void Page_Load( object sender, EventArgs e )
{
OpenIdRelyingParty openId = new OpenIdRelyingParty();
var response = openId.GetResponse();
//check if we're processing a request
if(response != null)
{
switch ( response.Status )
{
case AuthenticationStatus.Authenticated:
//authentication worked. grab our required fields
var claimsResponse = response.GetExtension<ClaimsResponse>();
//TODO enter required fields into the database
break;
case AuthenticationStatus.Canceled:
//TODO handle cancel
break;
case AuthenticationStatus.Failed:
//TODO handle failed
break;
}
}
}
答案 0 :(得分:4)
最后: 问题出在web.config
中添加
<configuration> <configSections> <section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true"/> </configSections> </configuration> <dotNetOpenAuth> <openid> <relyingParty> <behaviors> <add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth"/> </behaviors> </relyingParty> </openid> </dotNetOpenAuth>
这是真的,它应该有用。
答案 1 :(得分:2)
我同样面对雅虎和雅虎的问题。谷歌。 但是这个MVC示例在这个示例中很有用working Sample ....当我尝试将此解决方案转换为普通的ASP.NET 2时,我遇到了这个问题
protected void Page_Load(object sender, EventArgs e)
{
if (this.Request.HttpMethod == "POST")
{
var openid = new OpenIdRelyingParty();
string openid_identifier = this.openid_identifier.Text;
IAuthenticationRequest request = Openid.CreateRequest(Identifier.Parse(openid_identifier));
var fields = new ClaimsRequest();
fields.Email = DemandLevel.Require;
fields.FullName = DemandLevel.Require;
request.AddExtension(fields);
this.Response.ContentType = "text/html";
request.RedirectingResponse.Send();
return;
}
else
{
OpenIdRelyingParty openid = new OpenIdRelyingParty();
IAuthenticationResponse response = openid.GetResponse();
if (Request.Params["ReturnUrl"] != null)
Session["ReturnUrl"] = Request.Params["ReturnUrl"];
if (response != null && response.Status == AuthenticationStatus.Authenticated)
{
var claimUntrusted = response.GetUntrustedExtension<ClaimsResponse>();
var claim = response.GetExtension<ClaimsResponse>();
UserData userData = null;
if (claim != null)
{
userData = new UserData();
userData.Email = claim.Email;
userData.FullName = claim.FullName;
}
//now store Forms Authorisation cookie
IssueAuthTicket(userData, true);
//store ClaimedIdentifier it in Session
//(this would more than likely be something you would store in a database I guess
Session["ClaimedIdentifierMessage"] = response.ClaimedIdentifier;
//If we have a ReturnUrl we MUST be using forms authentication,
//so redirect to the original ReturnUrl
if (Session["ReturnUrl"] != null)
{
string url = Session["ReturnUrl"].ToString();
this.Response.Redirect(url,true);
return;
}
//This should not happen if all controllers have [Authorise] used on them
else
throw new InvalidOperationException("There is no ReturnUrl");
}
}
}
答案 2 :(得分:1)
Scott Hanselman最近有podcast on DoNetOpenAuth。在播客中,DotNetOpenAuth的作者Scott Arnott声称Google的OAuth实现不符合规范,并表示它应该失败而不是返回null。
答案 3 :(得分:0)
原来,Google不会发回您要求的任何信息。他们会进行身份验证,但就是这样。希望这可以帮助其他人解决这个问题。