Festlegen der Forderungen aus ASP.Net OpenID Connect OWIN-Komponenten?

Ich habe Fragen bei der Nutzung der neuen ASP.Net OpenID Connect-Rahmen, während das hinzufügen neuer Forderungen während der Authentifizierung pipeline wie im code gezeigt unten. Ich bin mir nicht sicher, wie viel "Magie" geschieht hinter den kulissen. Ich glaube, die meisten meiner Fragen drehen sich um, nicht zu wissen viel über OWIN Authentifizierungs-middleware im Gegensatz zu OpenID Connect.

Q1. Sollte ich die manuelle Einstellung HttpContext.Current.User und Thread.CurrentPrincipal aus OwinContext.Authentication.User?

Q2. Ich möchte die Möglichkeit zum hinzufügen von Objekt-Typen zu Behauptungen wie ich verwendet, um mit System.IdentityModel.Claims.Claim. Die neue System.Security.Claims.Claim Klasse akzeptiert nur string-Werte?

Q3. Brauche ich für die Nutzung der neuen SessionSecurityToken wrapper für meine ClaimsPrincipal im System.Security.Claims.CurrentPrincipal zum serialisieren in eine cookie - ich bin mit app.UseCookieAuthentication(new CookieAuthenticationOptions()); aber jetzt sicher, was das macht genau das, im Hinblick auf die Aufrechterhaltung weitergehende Ansprüche, die ich während der SecurityTokenValidated Veranstaltung?

    public void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
        app.UseCookieAuthentication(new CookieAuthenticationOptions());
        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = clientId,
                Authority = authority,
                PostLogoutRedirectUri = postLogoutRedirectUri,

                Notifications = new OpenIdConnectAuthenticationNotifications()
                {
                    SecurityTokenValidated = (context) =>
                    {
                        //retriever caller data from the incoming principal
                        var UPN = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.Name).Value;
                        var db = new SOSBIADPEntities();

                        var user = db.DomainUser.FirstOrDefault(b => (b.EntityName == UPN));

                        if (user == null)
                        {
                            //the caller was not a registered user - throw to block the authentication flow
                            throw new SecurityTokenValidationException();
                        }

                        var applicationUserIdentity = new ClaimsIdentity();
                        applicationUserIdentity.AddClaim(new Claim(ClaimTypes.Name, UPN, ""));
                        applicationUserIdentity.AddClaim(new Claim(ClaimTypes.Sid, user.ID.ToString(CultureInfo.InvariantCulture)));


                        var applications =
                            db.ApplicationUser
                            .Where(x => x.ApplicationChild != null && x.DomainUser.ID == user.ID)
                            .Select(x => x.ApplicationChild).OrderBy(x => x.SortOrder);

                        applications.ForEach(x =>
                            applicationUserIdentity.AddClaim(new Claim(ClaimTypes.System, x.ID.ToString(CultureInfo.InvariantCulture))));

                        context.OwinContext.Authentication.User.AddIdentity(applicationUserIdentity);

                        var hasOutlook = context.OwinContext.Authentication.User.HasClaim(ClaimTypes.System, "1");

                        hasOutlook = hasOutlook;

                        HttpContext.Current.User = context.OwinContext.Authentication.User;
                        Thread.CurrentPrincipal = context.OwinContext.Authentication.User;

                        var usr = HttpContext.Current.User;

                        var c =  System.Security.Claims.ClaimsPrincipal.Current.Claims.Count();


                        return Task.FromResult(0);
                    },
                }
            }
        );
    }
InformationsquelleAutor puri | 2014-11-28
Schreibe einen Kommentar