VB.Net中的OpenRasta基本身份验证

时间:2012-02-15 14:59:54

标签: vb.net basic-authentication openrasta

要问的问题是回答它。

我在VB.Net中寻找OpenRasta代码示例,但找不到我想要的内容。基于C#代码和Scott Littlewood https://github.com/scottlittlewood/OpenRastaAuthSample的优秀基本身份验证示例,我创建了一个示例VB.Net应用程序,它直接在httplistener上运行OpenRasta并实现基本身份验证。

要实现基本身份验证,请继承IBasicAuthenticator并实现Authenticate and Realm:

Public Class YourBasicAuthenticator : Implements IBasicAuthenticator

    Public Function Authenticate(header As OpenRasta.Authentication.Basic.BasicAuthRequestHeader) As OpenRasta.Authentication.AuthenticationResult Implements OpenRasta.Authentication.Basic.IBasicAuthenticator.Authenticate

        If header.Username = "usernamehere" AndAlso _
            header.Password = "passwordhere" Then

            Return New AuthenticationResult.Success("usernamehere")

        Else

            Return New AuthenticationResult.Failed

        End If
    End Function

    Public ReadOnly Property Realm As String Implements OpenRasta.Authentication.Basic.IBasicAuthenticator.Realm
        Get

            Return "Realm"

        End Get
    End Property

End Class

将自定义依赖项添加到资源空间:

ResourceSpace.Uses.CustomDependency(Of OpenRasta.Authentication.IAuthenticationScheme, OpenRasta.Authentication.Basic.BasicAuthenticationScheme)(OpenRasta.DI.DependencyLifetime.Singleton)

ResourceSpace.Uses.CustomDependency(Of OpenRasta.Authentication.Basic.IBasicAuthenticator, YourBasicAuthenticator)(OpenRasta.DI.DependencyLifetime.Transient)

装饰你的处理程序:

<RequiresAuthentication()> _

通过bitbucket示例VS2010示例应用程序:https://bitbucket.org/starlogicsh/openrasta-vbsample/wiki/Home

0 个答案:

没有答案