0

シングル サインオン機能を提供するために、Shibboleth ベースの SAML IdP に接続する .net 4.5 MVC アプリケーションを構築しています。これを行うために、Kentor.AuthServices.Owin ミドルウェアを使用しています。

問題の IdP サービスでは、暗号化されたアサーションを使用する必要がありますが、これは Kentor.AuthServices の最新のビルドではサポートされていません。代わりに、ここで Raschmann-fork を使用する必要がありましたhttps://github.com/Raschmann/authservices/tree/78EncryptedAssertion (v0.8.1)、次に ..Raschmann/authservices/tree/Release (v0.10.1) を試しました。

(..Raschmann/authservices/tree/master (v0.12.1)、または KentorIT Kentor.AuthServices ビルドのいずれかを使用すると、ExternalLoginCallback 内で loginInfo が null になります。)

上記を使用すると、IdP 経由でアプリケーションにログイン/登録できます。ただし、ExternalLoginCallback が呼び出されると、loginInfo.ExternalIdentity 内の ExternalClaims または Claims オブジェクトにはクレームが含まれません。

IdP からの SAML 応答をキャプチャして復号化し、ログイン後に IdP が情報 (名、姓、DoB など) をアプリケーションに送り返していることを確認しました。

返された SAML データにアクセスするにはどうすればよいですか?

Startup.Auth.vb 内の ConfigureAuth:

Public Sub ConfigureAuth(app As IAppBuilder)
        ' Configure the db context, user manager and signin manager to use a single instance per request
        app.CreatePerOwinContext(AddressOf ApplicationDbContext.Create)
        app.CreatePerOwinContext(Of ApplicationUserManager)(AddressOf ApplicationUserManager.Create)
        app.CreatePerOwinContext(Of ApplicationSignInManager)(AddressOf ApplicationSignInManager.Create)

        app.UseCookieAuthentication(New CookieAuthenticationOptions() With {
            .AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            .Provider = New CookieAuthenticationProvider() With {
                .OnValidateIdentity = SecurityStampValidator.OnValidateIdentity(Of ApplicationUserManager, ApplicationUser)(
                    validateInterval:=TimeSpan.FromMinutes(30),
                    regenerateIdentity:=Function(manager, user) user.GenerateUserIdentityAsync(manager))},
            .LoginPath = New PathString("/Account/Login")})



app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie)
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5))
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie)

            app.UseKentorAuthServicesAuthentication(New KentorAuthServicesAuthenticationOptions(True))
            AntiForgeryConfig.UniqueClaimTypeIdentifier = Global.System.IdentityModel.Claims.ClaimTypes.NameIdentifier

 End Sub

AccountController.vb 内の ExternalLoginCallback:

<AllowAnonymous>
    Public Async Function ExternalLoginCallback(returnUrl As String) As Task(Of ActionResult)

        Dim loginInfo = Await AuthenticationManager.GetExternalLoginInfoAsync()

        If loginInfo Is Nothing Then
            Return RedirectToAction("Login")
        End If

        Dim externalIdentity = Await AuthenticationManager.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie)

        ' Sign in the user with this external login provider if the user already has a login
        Dim result = Await SignInManager.ExternalSignInAsync(loginInfo, isPersistent:=False)
        Select Case result
            Case SignInStatus.Success
                Dim user = Await UserManager.FindAsync(loginInfo.Login)
                If user IsNot Nothing Then
                    'user.FirstName = loginInfo.ExternalIdentity.FindFirst(ClaimTypes.Name).Value
                    'user.Email = loginInfo.ExternalIdentity.FindFirst(ClaimTypes.Email).Value
                    Await UserManager.UpdateAsync(user)
                End If
                Return RedirectToLocal(returnUrl)
            Case SignInStatus.LockedOut
                Return View("Lockout")
            Case SignInStatus.RequiresVerification
                Return RedirectToAction("SendCode", New With {
                    .ReturnUrl = returnUrl,
                    .RememberMe = False
                })
            Case Else
                ' If the user does not have an account, then prompt the user to create an account
                ViewBag.ReturnUrl = returnUrl
                ViewBag.LoginProvider = loginInfo.Login.LoginProvider
                Return View("ExternalLoginConfirmation", New ExternalLoginConfirmationViewModel() With {
                    .Email = loginInfo.Email
                })
        End Select
    End Function
4

1 に答える 1

0

owin パイプラインは非常に複雑です。これをデバッグするには、呼び出しの直前に小さなブレークポイント ミドルウェアを挿入することをお勧めしますUseKentorAuthServicesAuthentication()

app.Use(async (context, next) =>
{
  await next.Invoke();
});

C# を使用して申し訳ありませんが、同等の VB 構文が見つかると思います。

アプリケーションを実行して認証します。Idp をトリガーしてレスポンスを返信する直前に、上記のコード スニペットの閉じ括弧にブレークポイントを設定します。次に、context.Authentication.AuthenticationResponseGrant の内容を調べます。これが Kentor.AuthServices からの実際の出力です。そこにクレームは存在しますか?

そうでない場合は、AuthServices にバグがあります。GitHub イシュー トラッカーでイシューとして報告してください。確認します。

その時点でクレームが実際に存在していても、後で失われた場合は、オーウィン クッキー モンスターの犠牲者である可能性があります。

于 2015-05-29T06:46:28.880 に答える