Beispiel #1
0
        public static IIdentityServerBuilder AddAspNetIdentity(
            this IIdentityServerBuilder builder,
            AbpIdentityServerBuilderOptions options = null)
        {
            if (options == null)
            {
                options = new AbpIdentityServerBuilderOptions();
            }

            //TODO: AspNet Identity integration lines. Can be extracted to a extension method
            if (options.IntegrateToAspNetIdentity)
            {
                builder.AddAspNetIdentity <IdentityUser>();
                builder.AddProfileService <AbpProfileService>();
                builder.AddResourceOwnerValidator <AbpResourceOwnerPasswordValidator>();
            }

            return(builder);
        }
    public static IIdentityServerBuilder AddAbpIdentityServer(
        this IIdentityServerBuilder builder,
        AbpIdentityServerBuilderOptions options = null)
    {
        if (options == null)
        {
            options = new AbpIdentityServerBuilderOptions();
        }

        //TODO: AspNet Identity integration lines. Can be extracted to a extension method
        if (options.IntegrateToAspNetIdentity)
        {
            builder.AddAspNetIdentity <IdentityUser>();
            builder.AddProfileService <AbpProfileService>();
            builder.AddResourceOwnerValidator <AbpResourceOwnerPasswordValidator>();

            builder.Services.Remove(builder.Services.LastOrDefault(x => x.ServiceType == typeof(IUserClaimsPrincipalFactory <IdentityUser>)));
            builder.Services.AddTransient <IUserClaimsPrincipalFactory <IdentityUser>, AbpUserClaimsFactory <IdentityUser> >();
            builder.Services.AddTransient <IObjectAccessor <IUserClaimsPrincipalFactory <IdentityUser> >, ObjectAccessor <AbpUserClaimsPrincipalFactory> >();
        }

        builder.Services.Replace(ServiceDescriptor.Transient <IClaimsService, AbpClaimsService>());

        if (options.UpdateAbpClaimTypes)
        {
            AbpClaimTypes.UserId   = JwtClaimTypes.Subject;
            AbpClaimTypes.UserName = JwtClaimTypes.Name;
            AbpClaimTypes.Role     = JwtClaimTypes.Role;
            AbpClaimTypes.Email    = JwtClaimTypes.Email;
        }

        if (options.UpdateJwtSecurityTokenHandlerDefaultInboundClaimTypeMap)
        {
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.UserId]   = AbpClaimTypes.UserId;
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.UserName] = AbpClaimTypes.UserName;
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.Role]     = AbpClaimTypes.Role;
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.Email]    = AbpClaimTypes.Email;
        }

        return(builder);
    }