public async Task ReceiveAsync(AuthenticationTokenReceiveContext context) { var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin"); context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin }); string hashedTokenId = context.Token.GetHash(); using(UnitOfWork uow = new UnitOfWork()) { using (RefreshTokenRepository _repo = new RefreshTokenRepository(uow)) { var refreshToken = await _repo.FindRefreshToken(hashedTokenId); if (refreshToken != null) { //Get protectedTicket from refreshToken class context.DeserializeTicket(refreshToken.ProtectedTicket); var result = await _repo.RemoveRefreshToken(hashedTokenId); } } } }
public async Task CreateAsync(AuthenticationTokenCreateContext context) { var clientid = context.Ticket.Properties.Dictionary["as:client_id"]; if (string.IsNullOrEmpty(clientid)) { return; } var refreshTokenId = Guid.NewGuid().ToString("n"); using (UnitOfWork _uow = new UnitOfWork()) { var refreshTokenLifeTime = context.OwinContext.Get<string>("as:clientRefreshTokenLifeTime"); var token = new RefreshToken() { Id = refreshTokenId.GetHash(), ClientId = clientid, Subject = context.Ticket.Identity.Name, IssuedUtc = DateTime.UtcNow, ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime)) }; context.Ticket.Properties.IssuedUtc = token.IssuedUtc; context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc; token.ProtectedTicket = context.SerializeTicket(); using (RefreshTokenRepository _repo = new RefreshTokenRepository(_uow)) { _repo.AddRefreshToken(token); await _uow.SaveAsync(); } context.SetToken(refreshTokenId); } }
// Pour plus d’informations sur le regroupement, rendez-vous sur http://go.microsoft.com/fwlink/?LinkId=301862 public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js")); // Utilisez la version de développement de Modernizr pour développer et apprendre. Puis, lorsque vous êtes // prêt pour la production, utilisez l’outil de génération sur http://modernizr.com pour sélectionner uniquement les tests dont vous avez besoin. bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( "~/Scripts/modernizr-*")); bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( "~/Scripts/bootstrap.js", "~/Scripts/gridster-bootstrap.min.js", "~/Scripts/respond.js")); bundles.Add(new ScriptBundle("~/bundles/tinymce").Include( "~/Scripts/tinymce.min.js" )); bundles.Add(new ScriptBundle("~/bundles/underscore").Include( "~/Scripts/underscore-min.js")); bundles.Add(new ScriptBundle("~/bundles/angular").Include( "~/Scripts/angular.min.js", "~/Scripts/angular-animate.min.js", "~/Scripts/angular-translate.min.js", "~/Scripts/angular-sanitize.min.js", "~/Scripts/angular-translate-loader-url.min.js", "~/Scripts/angular-local-storage.min.js", "~/Scripts/angular-resource.min.js", "~/Scripts/angular-gridster.min.js", "~/Scripts/angular-tinymce.js", "~/Scripts/angular-gridster.min.js", "~/Scripts/angular-touch.min.js", "~/Scripts/angular-simple-logger.min.js", "~/Scripts/angular-google-maps.min.js", "~/Scripts/ui-bootstrap-tpls-0.14.3.min.js", "~/Scripts/angular-route.min.js", "~/Scripts/ng-file-upload.min.js", "~/Scripts/select-ui.min.js", "~/Scripts/angular-navbar.js", "~/Scripts/angular-dynamic-locale.min.js", "~/Scripts/moment.min.js", "~/Scripts/bootstrap-colorpicker-module.min.js")); bundles.Add(new ScriptBundle("~/bundles/scripts").Include( "~/Scripts/app/modules/app.settings.js", "~/Scripts/app/modules/App.js", "~/Scripts/app/modules/app.menu.js", "~/Scripts/app/modules/app.dashboard.js", "~/Scripts/app/modules/app.image.picker.js", "~/Scripts/app/modules/app.spinner.js", "~/Scripts/app/directives/TopMenu.js", "~/Scripts/app/directives/ewDashboard.js", "~/Scripts/app/directives/ewStaticDashboard.js", "~/Scripts/app/directives/ewImagePicker.js", "~/Scripts/app/directives/ModuleUrl.js", "~/Scripts/app/directives/dynamic.js", "~/Scripts/app/directives/ewNewsPage.js", "~/Scripts/app/directives/ewSingleNewsPage.js", "~/Scripts/app/directives/ewFooter.js", "~/Scripts/app/directives/ewModuleNews.js", "~/Scripts/app/directives/ewTextfield.js", "~/Scripts/app/directives/Spinner.js", "~/Scripts/app/controllers/HomePage.js", "~/Scripts/app/controllers/LoginPage.js", "~/Scripts/app/controllers/AdminPage.js", "~/Scripts/app/controllers/TopMenu.js", "~/Scripts/app/controllers/ContentController.js", "~/Scripts/app/controllers/AdminContentController.js", "~/Scripts/app/controllers/ModalInstanceController.js", "~/Scripts/app/controllers/AdminModuleController.js", "~/Scripts/app/controllers/ModalContentTextController.js", "~/Scripts/app/controllers/ModalContentTitleController.js", "~/Scripts/app/controllers/ModalContentCardController.js", "~/Scripts/app/controllers/ModalContentWidgetController.js", "~/Scripts/app/controllers/ModalContentCarouselController.js", "~/Scripts/app/controllers/ModalContentMapController.js", "~/Scripts/app/controllers/ModalContentImageController.js", "~/Scripts/app/controllers/ModalContentModuleController.js", "~/Scripts/app/controllers/ImagePickerController.js", "~/Scripts/app/controllers/NewsPageController.js", "~/Scripts/app/controllers/SingleNewsPageController.js", "~/Scripts/app/controllers/ModuleNewsController.js", "~/Scripts/app/controllers/SpinnerController.js", "~/Scripts/app/controllers/FooterController.js", "~/Scripts/app/controllers/TextfieldController.js", "~/Scripts/app/controllers/ErrorController.js", "~/Scripts/app/filters/newsDate.js", "~/Scripts/app/services/AuthService.js", "~/Scripts/app/services/RoutingHelper.js", "~/Scripts/app/services/TopMenuHelper.js", "~/Scripts/app/services/ModuleHelper.js", "~/Scripts/app/services/ModuleContentHelper.js", "~/Scripts/app/services/ModuleTypeHelper.js", "~/Scripts/app/services/ModuleContentTypeHelper.js", "~/Scripts/app/services/ModuleUrlHelper.js", "~/Scripts/app/services/WebsiteFileHelper.js", "~/Scripts/app/services/ImagePickerHelper.js", "~/Scripts/app/services/NewsHelper.js", "~/Scripts/app/services/UserHelper.js", "~/Scripts/app/services/LanguageHelper.js", "~/Scripts/app/services/SettingsHelper.js", "~/Scripts/app/services/PermissionHelper.js", "~/Scripts/app/services/NavbarHelper.js", "~/Scripts/app/services/SpinnerHelper.js", "~/Scripts/app/services/ErrorEmailHelper.js", "~/Scripts/app/services/AuthInterceptorService.js")); bundles.Add(new StyleBundle("~/Content/css").Include( "~/Content/bootstrap.min.css", "~/Content/spinner.css", "~/Content/angular-gridster.min.css", "~/Content/content.min.css", "~/Content/colorpicker.css", "~/Content/select-ui.min.css", "~/Content/select2.css", "~/Content/angular-navbar.css", "~/Content/wfmi-style.css", "~/Content/site.css")); UnitOfWork UnitOfWork = new UnitOfWork(); using(SiteSettingsRepository _repo = new SiteSettingsRepository(UnitOfWork)) { var cssTheme = _repo.All.FirstOrDefault(s => s.Key == "theme"); if(cssTheme != null) { bundles.Add(new StyleBundle("~/Content/theme").Include( string.Format("~/Content/{0}.css", cssTheme.Value) )); } } }
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context) { string clientId = string.Empty; string clientSecret = string.Empty; Client client = null; if (!context.TryGetBasicCredentials(out clientId, out clientSecret)) { context.TryGetFormCredentials(out clientId, out clientSecret); } if (context.ClientId == null) { //Remove the comments from the below line context.SetError, and invalidate context //if you want to force sending clientId/secrects once obtain access tokens. context.Validated(); //context.SetError("invalid_clientId", "ClientId should be sent."); return Task.FromResult<object>(null); } using(UnitOfWork uow = new UnitOfWork()) { using (ClientRepository _repo = new ClientRepository(uow)) { client = _repo.Find(context.ClientId); } } if (client == null) { context.SetError("invalid_clientId", string.Format("Client '{0}' is not registered in the system.", context.ClientId)); return Task.FromResult<object>(null); } if (client.ApplicationType == ApplicationTypes.NativeConfidential) { if (string.IsNullOrWhiteSpace(clientSecret)) { context.SetError("invalid_clientId", "Client secret should be sent."); return Task.FromResult<object>(null); } else { if (client.Secret != clientSecret.GetHash()) { context.SetError("invalid_clientId", "Client secret is invalid."); return Task.FromResult<object>(null); } } } if (!client.Active) { context.SetError("invalid_clientId", "Client is inactive."); return Task.FromResult<object>(null); } context.OwinContext.Set<string>("as:clientAllowedOrigin", client.AllowedOrigin); context.OwinContext.Set<string>("as:clientRefreshTokenLifeTime", client.RefreshTokenLifeTime.ToString()); context.Validated(); return Task.FromResult<object>(null); }