Example #1
0
        public void Configuration(IAppBuilder app)
        {
            var kernel = NinjectWebCommon.CreateKernel();
            var config = new HttpConfiguration();

            AddVersioning(kernel, config);
            WebApiConfig.Register(config);
            config.AddCustomBindings();

            var scopes =
                new Dictionary <string, string>
            {
                { "interaction-routing", "Route interactions" }
            };

            var requiredScopes =
                new[]
            {
                "interaction-routing"
            };

            var supportedVersion = new List <int> {
                1
            };

            app
            .UseLog4Net()
            .UseSwaggerUi(typeof(Startup).Assembly, "/", scopes, supportedVersion)
            .UseOAuthAuthentication(requiredScopes)
            .UseNinjectMiddleware(() => kernel)
            .UseNinjectWebApi(config)
            .UseCors(CorsOptions.AllowAll);
        }
        protected void Application_Start()
        {
            NinjectWebCommon.CreateKernel();

            Trace.Listeners.Add(new MvcListener(GlobalConfiguration.Configuration));
            WebApiConfig.Register(GlobalConfiguration.Configuration);
        }
        public void Configuration(IAppBuilder app)
        {
            // configuracao WebApi
            var config = new HttpConfiguration();

            var kernel = NinjectWebCommon.CreateKernel();

            config.DependencyResolver = new NinjectResolver(kernel);


            // configurando rotas
            config.MapHttpAttributeRoutes();


            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );


            config.Formatters.XmlFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

            // ativando cors
            app.UseCors(CorsOptions.AllowAll);

            // ativando tokens de acesso
            AtivandoAccessTokens(app);

            // ativando configuraĆ§Ć£o WebApi
            app.UseWebApi(config);
        }
Example #4
0
        public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            return(Task.Factory.StartNew(() =>
            {
                var userName = context.UserName;
                var password = context.Password;
                var userService = NinjectWebCommon.CreateKernel().Get <IUserService>();
                var user = userService.ValidateUser(userName, password);
                if (user != null)
                {
                    var claims = new List <Claim>()
                    {
                        new Claim(ClaimTypes.Sid, Convert.ToString(user.Id)),
                        new Claim(ClaimTypes.Name, user.Name),
                        new Claim(ClaimTypes.Email, user.Email)
                    };
                    ClaimsIdentity oAuthIdentity = new ClaimsIdentity(claims,
                                                                      Startup.OAuthOptions.AuthenticationType);

                    var properties = CreateProperties(user.Name);
                    var ticket = new AuthenticationTicket(oAuthIdentity, properties);
                    context.Validated(ticket);
                }
                else
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect");
                }
            }));
        }
        public void TestSetUp()
        {
            kernel = NinjectWebCommon.CreateKernel();
            IBetterReadsDbContext dbContext = kernel.Get <IBetterReadsDbContext>();

            dbContext.Ratings.Add(rating);

            dbContext.SaveChanges();
        }
Example #6
0
        public SimpleBusinessServiceTest()
        {
            _kernel = NinjectWebCommon.CreateKernel();


            //_kernel = new MoqMockingKernel();
            //_kernel.Bind<IUnitOfWork>().To<NeutrinoUnitOfWork>();
            //_kernel.Bind<IDataRepository>().To<RepositoryBase>();
            //_kernel.Bind<IBusinessActionResult>().To<BusinessActionResult>();
            //_kernel.Bind(typeof(ISimpleBusinessService<>)).ToMock(typeof(SimpleBusinessService<>));
        }
        public void TestSetUp()
        {
            kernel = NinjectWebCommon.CreateKernel();
            IBetterReadsDbContext dbContext = kernel.Get <IBetterReadsDbContext>();

            foreach (User user in users)
            {
                dbContext.Users.Add(user);
            }

            dbContext.SaveChanges();
        }
Example #8
0
        public void TestSetUp()
        {
            kernel = NinjectWebCommon.CreateKernel();
            IBetterReadsDbContext dbContext = kernel.Get <IBetterReadsDbContext>();

            foreach (Genre genre in genres)
            {
                dbContext.Genres.Add(genre);
            }

            dbContext.SaveChanges();
        }
Example #9
0
        public void TestInit()
        {
            kernel = NinjectWebCommon.CreateKernel();
            SofiaDayAndNightDbContext dbContext = kernel.Get <SofiaDayAndNightDbContext>();

            var userManager = new UserManager <User>(new UserStore <User>(dbContext));

            dbIndividual.ProfileImage = dbimage;
            dbIndividual.User         = dbUser;
            dbUser.Individual         = dbIndividual;
            dbContext.Users.Add(dbUser);
            dbContext.SaveChanges();
        }
Example #10
0
        public void Configuration(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

            ConfigureOAuth(app);

            //CORS
            WebApiConfig.Register(config);
            app.UseCors(CorsOptions.AllowAll);

            //Ninject
            var kernel = NinjectWebCommon.CreateKernel();

            app.UseNinjectMiddleware(() => kernel);
            app.UseNinjectWebApi(config);
        }
Example #11
0
        public void TestInit()
        {
            kernel = NinjectWebCommon.CreateKernel();
            LiveDemoEfDbContext dbContext = kernel.Get <LiveDemoEfDbContext>();

            dbContext.Categories.Add(dbCategory);
            dbContext.SaveChanges();

            var category = dbContext.Categories.Single();

            dbBook.CategoryId = category.Id;
            dbBook.Category   = category;

            dbContext.Books.Add(dbBook);
            dbContext.SaveChanges();
        }
        public void ConfigureOAuth(IAppBuilder app)
        {
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            IKernel kernel = NinjectWebCommon.CreateKernel();

            var oAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp         = true,
                TokenEndpointPath         = new PathString("/api/account/login"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                Provider = new AuthProvider(kernel.Get <IUsersService>()),
            };

            app.UseOAuthAuthorizationServer(oAuthServerOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
        }
Example #13
0
        public void TestInit()
        {
            kernel = NinjectWebCommon.CreateKernel();
            AirTicketEfDbContext dbContext = kernel.Get <AirTicketEfDbContext>();

            dbContext.Airlines.Add(dbAirline);
            dbContext.SaveChanges();

            dbContext.Airports.Add(dbAirport);
            dbContext.SaveChanges();

            //var airline = dbContext.Airlines.FirstOrDefault();
            //dbFlight.AirlineId = airline.Id;
            //dbFlight.Airline = airline;

            dbContext.Flights.Add(dbFlight);
            dbContext.SaveChanges();
        }
        public void Configuration(IAppBuilder app)
        {
            //--------------Cors
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            //--------------DI
            kernel = NinjectWebCommon.CreateKernel();
            app.UseNinjectMiddleware(() => kernel);

            //--------------Service
            app.CreatePerOwinContext <IMainService>(() => kernel.Get <IMainService>());

            //-------------Auth with Token
            app.UseCookieAuthentication(new CookieAuthenticationOptions());
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
            PublicClientId = "self";
            OAuthOptions   = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath         = new PathString("/Token"),
                Provider                  = new ApplicationOAuthProvider(PublicClientId),
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(10),
                // In production mode set AllowInsecureHttp = false
                AllowInsecureHttp = true
            };
            // Enable the application to use bearer tokens to authenticate users
            app.UseOAuthBearerTokens(OAuthOptions);

            //-------------HttpConfig for WebAPI
            HTTP_Config = new HttpConfiguration();
            WebApiConfig.Register(HTTP_Config);
            app.UseWebApi(HTTP_Config);

            //-----------Test OWIN
            //app.UseWelcomePage();

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Example #15
0
        private bool ValidateUserToken(string operationName, object input)
        {
            TokenServiceRequest tokenRequest = input as TokenServiceRequest;

            if (tokenRequest == null)
            {
                // if this is not TokenServiceRequest, nothing to validate
                return(true);
            }

            if (string.IsNullOrEmpty(tokenRequest.UserToken) || string.IsNullOrEmpty(tokenRequest.AppVersion))
            {
                throw new FaultException(string.Format("[{0}]: Invalid empty webservice request", operationName));
            }

            IKernel kernel  = NinjectWebCommon.CreateKernel();
            var     service = kernel.Get <IWebServiceDiagnosticService>();

            //tokenRequest.ValidatedUserId = validationResult.UserID;

            return(true);
        }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

            using (AuthRepository _repo = new AuthRepository())
            {
                IdentityUser user = await _repo.FindUser(context.UserName, context.Password);

                if (user == null)
                {
                    context.SetError("invalid_grant", "User name or password is incorrect.");
                    return;
                }
            }


            userLogic = NinjectWebCommon.CreateKernel().Get <UserLogic>();

            CommonResponse response = userLogic.GetByName(context.UserName);

            if (response.ErrorThrown)
            {
                context.SetError(response.ResponseDescription);
                return;
            }

            User theUser = (User)response.Result;

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);

            identity.AddClaim(new Claim("role", theUser.Role ?? ""));
            identity.AddClaim(new Claim("userID", theUser.id.ToString()));
            identity.AddClaim(new Claim("userName", theUser.UserName));
            identity.AddClaim(new Claim("email", theUser.Email ?? ""));
            identity.AddClaim(new Claim("displayName", theUser.Value ?? ""));
            identity.AddClaim(new Claim("DepartmentKey", theUser.DepartmentKey.ToString()));

            context.Validated(identity);
        }
        public static HttpConfiguration Register()
        {
            // Web API configuration and services
            var config = new HttpConfiguration();

            config.Formatters.Remove(config.Formatters.XmlFormatter);
            config.DependencyResolver = new NinjectDependencyResolver(NinjectWebCommon.CreateKernel());
            // Web API routes
            config.MapHttpAttributeRoutes();

            config.EnableCors(new EnableCorsAttribute("http://localhost:61565/, http://localhost:37045, http://localhost:37046", "accept, authorization", "GET", "WWW-Authenticate"));



            config.DependencyResolver = new NinjectDependencyResolver(NinjectWebCommon.CreateKernel());
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            return(config);
        }
Example #18
0
        public void Configuration(IAppBuilder app)
        {
            AutoMapperConfig.RegisterMappings(Assembly.Load(Assembly.GetExecutingAssembly().FullName));

            HttpConfiguration config = new HttpConfiguration();


            WebApiConfig.Register(config);
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            var ninjectKernel = NinjectWebCommon.CreateKernel();

            config.DependencyResolver = new NinjectResolver(ninjectKernel);

            SwaggerConfig.Register(config);

            ConfigureOAuth(app, ninjectKernel.Get <IBearerTokenExpirationTask>());

            app.UseWebApi(config);

            ConfigureSignalR(app);

            ConfigureBackgroundTasks(app, ninjectKernel);
        }
Example #19
0
 static NinjectHelper()
 {
     _kernel = NinjectWebCommon.CreateKernel();
 }
Example #20
0
 public static void Register(HttpConfiguration config) {
     var kernel = NinjectWebCommon.CreateKernel();
     // Web API configuration and services
     config.Filters.Add(kernel.Get<BasicAuthenticationAttribute>());
 public void Setup()
 {
     kernel = NinjectWebCommon.CreateKernel();
 }
Example #22
0
 protected virtual IKernel CreateKernel()
 {
     return(NinjectWebCommon.CreateKernel());
 }
Example #23
0
        public void StudentTestInitialize()
        {
            IKernel kernel = NinjectWebCommon.CreateKernel();

            _service = kernel.Get <IStudentAppService>();
        }
Example #24
0
        public void Init()
        {
            var kernel = NinjectWebCommon.CreateKernel();

            _concursoService = (IConcursoService)kernel.GetService(typeof(ConcursoService));
        }
 public void CreateAnInstanceOfIKernel()
 {
     // Arrange, Act, Assert
     Assert.IsInstanceOf <IKernel>(NinjectWebCommon.CreateKernel());
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     NinjectWebCommon.CreateKernel().Inject(MyServerControl1);
 }