Exemplo n.º 1
0
        public void Configuration(IAppBuilder app)
        {
            ConfigureOAuth(app);

            HttpConfiguration config = new HttpConfiguration();

            // The "HttpConfiguration" object is used to configure API routes,
            // so we’ll pass this object to method "Register" in "WebApiConfig" class.
            WebApiConfig.Register(config);

            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            // "UseWebApi" will be responsible to wire up ASP.NET Web API to our Owin server pipeline.
            app.UseWebApi(config);
        }
Exemplo n.º 2
0
        public void Configuration(IAppBuilder app)
        {
            var config = new HttpConfiguration();

            WebApiConfig.Register(config);
            app.UseWebApi(config);

            PublicClientId = "self";

            UserManagerFactory = () => new UserManager <IdentityUser>(new UserStore <IdentityUser>());

            OAuthOptions = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath         = new PathString("/Token"),
                Provider                  = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
                AuthorizeEndpointPath     = new PathString("/api/Account/ExternalLogin"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
                AllowInsecureHttp         = true
            };

            app.UseOAuthBearerTokens(OAuthOptions);

            ConfigureAuth(app);
        }
Exemplo n.º 3
0
        public void Configuration(IAppBuilder app)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <MongoContext>().AsImplementedInterfaces <MongoContext, ConcreteReflectionActivatorData>().SingleInstance();

            builder.RegisterType <AuthRepository>().SingleInstance();
            builder.RegisterType <CalculatorRepository>().SingleInstance();
            //builder.RegisterType<CalculatorRepository>()
            //    .WithParameters(new Parameter[]
            //    {
            //        new ResolvedParameter((info, context) => info.Name == "mongoContext",
            //            (info, context) => context.Resolve<IMongoContext>()),
            //        new ResolvedParameter((info, context) => info.Name == "userManager",
            //            (info, context) => context.Resolve<ApplicationUserManager>())
            //    }).SingleInstance();

            builder.RegisterType <ApplicationIdentityContext>()
            .SingleInstance();

            builder.RegisterType <UserStore <User> >()
            .AsImplementedInterfaces <IUserStore <User>, ConcreteReflectionActivatorData>()
            .SingleInstance();

            builder.RegisterType <RoleStore <Role> >()
            .AsImplementedInterfaces <IRoleStore <Role>, ConcreteReflectionActivatorData>()
            .SingleInstance();

            builder.RegisterType <ApplicationUserManager>()
            .SingleInstance();

            builder.RegisterType <ApplicationRoleManager>()
            .SingleInstance();

            builder.RegisterType <SimpleAuthorizationServerProvider>()
            .AsImplementedInterfaces <IOAuthAuthorizationServerProvider, ConcreteReflectionActivatorData>().SingleInstance();

            builder.RegisterType <SimpleRefreshTokenProvider>()
            .AsImplementedInterfaces <IAuthenticationTokenProvider, ConcreteReflectionActivatorData>().SingleInstance();

            //builder.RegisterType<SimpleAuthorizationServerProvider>()
            //    .AsImplementedInterfaces<IOAuthAuthorizationServerProvider, ConcreteReflectionActivatorData>()
            //    .WithParameters(new Parameter[]
            //    {
            //        new NamedParameter("publicClientId", "self"),
            //        new ResolvedParameter((info, context) => info.Name == "userManager",
            //            (info, context) => context.Resolve<ApplicationUserManager>())
            //    });

            builder.RegisterApiControllers(typeof(Startup).Assembly);

            var container = builder.Build();

            app.UseAutofacMiddleware(container);

            var webApiDependencyResolver = new AutofacWebApiDependencyResolver(container);

            var configuration = new HttpConfiguration
            {
                DependencyResolver = webApiDependencyResolver
            };

            ConfigureOAuth(app, container);

            WebApiConfig.Register(configuration);

            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            app.UseWebApi(configuration);

            app.UseAutofacWebApi(configuration);

            InitializeData(container);
        }