DotNetOpenID程序化登录

时间:2009-03-08 12:22:44

标签: asp.net dotnetopenauth

我使用Dotnetopenid作为我的openid解决方案,使用内置用户控件时一切正常,但是当我想以programmaticaly实现它时,如下面的代码,

openid.Response.GetExtension<DotNetOpenId.Extensions.SimpleRegistration.ClaimsResponse>();

始终为null。 任何想法?

    OpenIdRelyingParty openid = createRelyingParty();
    if (openid.Response != null) {
        switch (openid.Response.Status) {
            case AuthenticationStatus.Authenticated:
                // This is where you would look for any OpenID extension responses included
                // in the authentication assertion.
                // var extension = openid.Response.GetExtension<SomeExtensionResponseType>();

                // Use FormsAuthentication to tell ASP.NET that the user is now logged in,
                // with the OpenID Claimed Identifier as their username.
                State.ProfileFields = openid.Response.GetExtension<DotNetOpenId.Extensions.SimpleRegistration.ClaimsResponse>();
                FormsAuthentication.RedirectFromLoginPage(openid.Response.ClaimedIdentifier, false);
                break;

2 个答案:

答案 0 :(得分:3)

Andrew

获取帮助

在重定向到提供商之前,我错过了为我的请求添加扩展程序。 (此步骤未在示例文件中编码)

要做到这一点,在创建请求对象后,请执行以下操作:

  Dim request As IAuthenticationRequest = openid.CreateRequest(openid_identifier.Text)
        ' This is where you would add any OpenID extensions you wanted
        ' to include in the authentication request.
        ' request.AddExtension(someExtensionRequestInstance);
        Dim myclaim As New ClaimsRequest

        With myclaim
            .BirthDate = DemandLevel.Request
            .Country = DemandLevel.Request
            .Email = DemandLevel.Request
            .FullName = DemandLevel.Request
            .Gender = DemandLevel.Request
            .Language = DemandLevel.Request
            .Nickname = DemandLevel.Request
            .PostalCode = DemandLevel.Request
            .TimeZone = DemandLevel.Request

        End With


        request.AddExtension(myclaim)









        ' Send your visitor to their Provider for authentication.
        request.RedirectToProvider()

代码在vb.net中

答案 1 :(得分:0)

注意在下一版本中修复并更清楚。