コード例 #1
0
        public static void UseIdentityManager(this IAppBuilder app, IdentityManagerConfiguration config)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            config.Validate();

            if (config.SecurityMode == SecurityMode.LocalMachine)
            {
                var local = new LocalAuthenticationOptions(config.AdminRoleName);
                app.Use <LocalAuthenticationMiddleware>(local);
            }
            else if (config.SecurityMode == SecurityMode.OAuth2)
            {
                if (config.OAuth2Configuration.SigningCert != null)
                {
                    app.UseJsonWebToken(config.OAuth2Configuration.Issuer,
                                        config.OAuth2Configuration.Audience,
                                        config.OAuth2Configuration.SigningCert);
                }
                else
                {
                    app.UseJsonWebToken(config.OAuth2Configuration.Issuer,
                                        config.OAuth2Configuration.Audience,
                                        config.OAuth2Configuration.SigningKey);
                }
                app.Use(async(ctx, next) =>
                {
                    await next();
                });
            }

            if (!config.DisableUserInterface)
            {
                app.UseFileServer(new FileServerOptions
                {
                    RequestPath = new PathString("/assets"),
                    FileSystem  = new EmbeddedResourceFileSystem(typeof(AppBuilderExtensions).Assembly, "Thinktecture.IdentityManager.Assets")
                });
                app.UseFileServer(new FileServerOptions
                {
                    RequestPath = new PathString("/assets/libs/fonts"),
                    FileSystem  = new EmbeddedResourceFileSystem(typeof(AppBuilderExtensions).Assembly, "Thinktecture.IdentityManager.Assets.Content.fonts")
                });
                app.UseStageMarker(PipelineStage.MapHandler);
            }

            SignatureConversions.AddConversions(app);

            var httpConfig = new HttpConfiguration();

            WebApiConfig.Configure(httpConfig, config);
            app.UseWebApi(httpConfig);
            app.UseStageMarker(PipelineStage.MapHandler);
        }
コード例 #2
0
        public MetaController(IdentityManagerConfiguration config, IIdentityManagerService userManager)
        {
            if (config == null) throw new ArgumentNullException("config");
            if (userManager == null) throw new ArgumentNullException("userManager");

            this.config = config;
            this.userManager = userManager;
        }
コード例 #3
0
        public PageController(IdentityManagerConfiguration idmConfig)
        {
            if (idmConfig == null)
            {
                throw new ArgumentNullException("idmConfig");
            }

            this.idmConfig = idmConfig;
        }
コード例 #4
0
ファイル: Startup.cs プロジェクト: retslig/ANDP
        public void Configuration(IAppBuilder app)
        {
            var options = new IdentityManagerConfiguration()
            {
                UserManagerFactory = Thinktecture.IdentityManager.MembershipReboot.UserManagerFactory.Create
                                     //UserManagerFactory = Thinktecture.IdentityManager.AspNetIdentity.UserManagerFactory.Create
            };

            //Comment out when local for debugging
            app.Map("/IdentityManager", _ => { _.UseIdentityManager(options); });
            //Comment out when local for production
            //app.Map("", _ => { _.UseIdentityManager(options); });
        }
コード例 #5
0
        public MetaController(IdentityManagerConfiguration config, IIdentityManagerService userManager)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (userManager == null)
            {
                throw new ArgumentNullException("userManager");
            }

            this.config      = config;
            this.userManager = userManager;
        }
コード例 #6
0
        public static void UseIdentityManager(this IAppBuilder app, IdentityManagerConfiguration config)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            config.Validate();

            if (config.SecurityMode == SecurityMode.Local)
            {
                app.Use(async(ctx, next) =>
                {
                    var localAddresses = new string[] { "127.0.0.1", "::1", ctx.Request.LocalIpAddress };
                    if (localAddresses.Contains(ctx.Request.RemoteIpAddress))
                    {
                        await next();
                    }
                });
            }

            if (!config.DisableUserInterface)
            {
                app.UseFileServer(new FileServerOptions
                {
                    RequestPath = new PathString("/assets"),
                    FileSystem  = new EmbeddedResourceFileSystem(typeof(AppBuilderExtensions).Assembly, "Thinktecture.IdentityManager.Assets")
                });
                app.UseFileServer(new FileServerOptions
                {
                    RequestPath = new PathString("/assets/libs/fonts"),
                    FileSystem  = new EmbeddedResourceFileSystem(typeof(AppBuilderExtensions).Assembly, "Thinktecture.IdentityManager.Assets.Content.fonts")
                });
                app.UseStageMarker(PipelineStage.MapHandler);
            }

            //app.UseJsonWebToken();

            SignatureConversions.AddConversions(app);

            var httpConfig = new HttpConfiguration();

            WebApiConfig.Configure(httpConfig, config);
            app.UseWebApi(httpConfig);
            app.UseStageMarker(PipelineStage.MapHandler);
        }
コード例 #7
0
        public PageController(IdentityManagerConfiguration idmConfig)
        {
            if (idmConfig == null) throw new ArgumentNullException("idmConfig");

            this.idmConfig = idmConfig;
        }
        public static void UseIdentityManager(this IAppBuilder app, IdentityManagerConfiguration config)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            config.Validate();

            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary <string, string>();

            if (config.SecurityMode == SecurityMode.LocalMachine)
            {
                var local = new LocalAuthenticationOptions(config.AdminRoleName);
                app.Use <LocalAuthenticationMiddleware>(local);
            }
            else if (config.SecurityMode == SecurityMode.OAuth2)
            {
                var jwtParams = new System.IdentityModel.Tokens.TokenValidationParameters
                {
                    RoleClaimType = Constants.ClaimTypes.Role,
                    ValidAudience = config.OAuth2Configuration.Audience,
                    ValidIssuer   = config.OAuth2Configuration.Issuer,
                };
                if (config.OAuth2Configuration.SigningCert != null)
                {
                    jwtParams.IssuerSigningToken = new X509SecurityToken(config.OAuth2Configuration.SigningCert);
                }
                else
                {
                    var bytes = Convert.FromBase64String(config.OAuth2Configuration.SigningKey);
                    jwtParams.IssuerSigningToken = new BinarySecretSecurityToken(bytes);
                }

                app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions {
                    TokenValidationParameters = jwtParams
                });
                app.RequireScopes(new ScopeValidationOptions {
                    AllowAnonymousAccess = true,
                    Scopes = new string[] {
                        config.OAuth2Configuration.Scope
                    }
                });
            }

            if (!config.DisableUserInterface)
            {
                app.UseFileServer(new FileServerOptions
                {
                    RequestPath = new PathString("/assets"),
                    FileSystem  = new EmbeddedResourceFileSystem(typeof(IdentityManagerAppBuilderExtensions).Assembly, "Thinktecture.IdentityManager.Assets")
                });
                app.UseFileServer(new FileServerOptions
                {
                    RequestPath = new PathString("/assets/libs/fonts"),
                    FileSystem  = new EmbeddedResourceFileSystem(typeof(IdentityManagerAppBuilderExtensions).Assembly, "Thinktecture.IdentityManager.Assets.Content.fonts")
                });
                app.UseStageMarker(PipelineStage.MapHandler);
            }

            SignatureConversions.AddConversions(app);

            var httpConfig = new HttpConfiguration();

            WebApiConfig.Configure(httpConfig, config);
            app.UseWebApi(httpConfig);
            app.UseStageMarker(PipelineStage.MapHandler);
        }