public override Task Invoke(IOwinContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } IDependencyResolver dependencyResolver = context.GetDependencyResolver(); if (_App == null) { _App = dependencyResolver.Resolve <AppEnvironment>(); } string afterLogoutRedirect_uri = context.Request.Query["redirect_uri"] ?? $"{context.Request.Scheme}://{context.Request.Host.Value}{_App.GetHostVirtualPath()}SignOut"; string ssoRedirectUri = $"{_App.GetSsoUrl()}/connect/endsession?post_logout_redirect_uri={afterLogoutRedirect_uri}"; string stateArgs = context.Request.Query["state"] ?? "{}"; context.Response.Redirect($"{ssoRedirectUri}&id_token_hint={(context.Request.Query["id_token"])}&state={stateArgs}"); context.Authentication.SignOut("custom", "Bearer"); return(Task.CompletedTask); }
public override Task Invoke(IOwinContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } IDependencyResolver dependencyResolver = context.GetDependencyResolver(); if (_App == null) { _App = dependencyResolver.Resolve <AppEnvironment>(); } IRandomStringProvider randomStringProvider = dependencyResolver.Resolve <IRandomStringProvider>(); string redirectUriHost = $"{context.Request.Scheme}://{context.Request.Host.Value}{_App.GetHostVirtualPath()}SignIn"; string redirectUri = $"{_App.GetSsoUrl()}/connect/authorize?scope={string.Join(" ", _App.Security.Scopes)}&client_id={_App.GetSsoDefaultClientId()}&redirect_uri={redirectUriHost}&response_type=id_token token"; string pathname = _App.GetHostVirtualPath() + (context.Request.Path != null ? context.Request.Path.Value.Substring(1) : string.Empty); string state = $@"{{""pathname"":""{pathname}""}}"; string nonce = randomStringProvider.GetRandomString(12); context.Response.Redirect($"{redirectUri}&state={state}&nonce={nonce}"); return(Task.CompletedTask); }
public async Task <AppEnvironment> Value() { if (value == null) { anonClient.Load(); var user = await userContext.User(); var requesterKey = anonClient.RequesterKey; if (string.IsNullOrWhiteSpace(requesterKey)) { requesterKey = Guid.NewGuid().ToString("N"); } var userAgent = httpContextAccessor.HttpContext?.Request.Headers["User-Agent"].ToString() ?? ""; var remoteAddress = httpContextAccessor.HttpContext?.Connection.RemoteIpAddress?.ToString() ?? ""; value = new AppEnvironment ( user.UserName().Value, requesterKey, remoteAddress, userAgent, AppType.Values.WebApp.DisplayText ); } return(value); }
public override Task Invoke(IOwinContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } IDependencyResolver dependencyResolver = context.GetDependencyResolver(); if (_App == null) { _App = dependencyResolver.Resolve <AppEnvironment>(); } string defaultPath = _App.GetHostVirtualPath(); string defaultPathWithoutEndingSlashIfIsNotRoot = defaultPath == "/" ? defaultPath : defaultPath.Substring(0, defaultPath.Length - 1); string signInPage = $@" <html> <head> <title>Signing in... Please wait</title> <script type='application/javascript'> var parts = location.hash.replace('#','').split('&'); var expiresTimeInSeconds = Number(parts[3].split('=')[1]); var expiresDate = new Date(); expiresDate.setTime(expiresDate.getTime() + (expiresTimeInSeconds * 1000)); var expiresDateAsUTCString = expiresDate.toUTCString(); for (var i = 0; i < parts.length; i++) {{ var partStr = parts[i]; var keyValue = partStr.split('='); var key = keyValue[0]; var value = keyValue[1]; if (key == 'access_token' || key == 'token_type'){{ document.cookie = partStr + ';expires=' + expiresDateAsUTCString + ';path={defaultPathWithoutEndingSlashIfIsNotRoot}'; }} localStorage['{defaultPath}' + key] = value; }} localStorage['{defaultPath}login_date'] = new Date(); var state = JSON.parse(decodeURIComponent(localStorage['{defaultPath}state'].replace(/\+/g, ' '))); localStorage['{defaultPath}state'] = JSON.stringify(state); if(state.AutoClose == null || state.AutoClose == false) {{ location = state.pathname || '{defaultPath}'; }} else {{ window.close(); }} </script> </head> <body> <h1>Signing in... Please wait</h1> </body> </html> "; context.Response.ContentType = "text/html; charset=utf-8"; return(context.Response.WriteAsync(signInPage, context.Request.CallCancelled)); }
public virtual (bool success, string?message) TryGetActiveAppEnvironment(out AppEnvironment?activeAppEnvironment) { try { activeAppEnvironment = _appEnvironmentsProvider.GetActiveAppEnvironment(); _appEnvCustomizer?.Invoke(activeAppEnvironment); return(true, null); } catch (Exception exp) { activeAppEnvironment = null; return(false, exp.Message); } }
public override Task Invoke(IOwinContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } IDependencyResolver dependencyResolver = context.GetDependencyResolver(); if (_App == null) { _App = dependencyResolver.Resolve <AppEnvironment>(); } IRandomStringProvider randomStringProvider = dependencyResolver.Resolve <IRandomStringProvider>(); string client_Id = context.Request.Query["client_id"] ?? _App.GetSsoDefaultClientId(); string afterLoginRedirect_uri = context.Request.Query["redirect_uri"] ?? $"{context.Request.Scheme}://{context.Request.Host.Value}{_App.GetHostVirtualPath()}SignIn"; string ssoRedirectUri = $"{_App.GetSsoUrl()}/connect/authorize?scope={string.Join(" ", _App.Security.Scopes)}&client_id={client_Id}&redirect_uri={afterLoginRedirect_uri}&response_type=id_token token"; string stateArgs = context.Request.Query["state"] ?? "{}"; string nonce = randomStringProvider.GetRandomString(12); string url = $"{ssoRedirectUri}&state={stateArgs}&nonce={nonce}"; if (context.Request.Query["acr_values"] != null) { url += $"&acr_values={context.Request.Query["acr_values"]}"; } context.Response.Redirect(url); return(Task.CompletedTask); }
public virtual void Init() { List <EnvironmentConfig> configs = new List <EnvironmentConfig> { }; void TryReadConfig <T>(IConfiguration configuration, string key) { if (configuration != null && configuration[key] != null) { configs.Add(new EnvironmentConfig { Key = key, Value = configuration.GetValue <T>(key) }); } } void TryReadConnectionString(string key) { if (configs.Any(c => c.Key == key)) { return; } string connectionString = Configuration.GetConnectionString(key); if (connectionString != null) { configs.Add(new EnvironmentConfig { Key = key, Value = connectionString }); } } TryReadConfig <string>(Configuration, AppEnvironment.KeyValues.HostVirtualPath); TryReadConfig <string>(Configuration, AppEnvironment.KeyValues.IndexPagePath); TryReadConfig <string>(Configuration, AppEnvironment.KeyValues.StaticFilesRelativePath); TryReadConfig <string>(Configuration, AppEnvironment.KeyValues.IdentityCertificatePassword); TryReadConfig <string>(Configuration, AppEnvironment.KeyValues.IdentityServerCertificatePath); TryReadConfig <string>(Configuration, AppEnvironment.KeyValues.IdentityClientPublicKey); TryReadConfig <bool>(Configuration, AppEnvironment.KeyValues.RequireSsl); TryReadConfig <long>(Configuration, AppEnvironment.KeyValues.EventLogId); IConfiguration?data = Configuration.GetChildren().ExtendedSingleOrDefault("Finding data config", c => c.Key == nameof(AppEnvironment.KeyValues.Data)); if (data != null) { TryReadConfig <string>(data, AppEnvironment.KeyValues.Data.DbIsolationLevel); TryReadConfig <string>(data, AppEnvironment.KeyValues.Data.LogDbConnectionstring); } IConfiguration?signalr = Configuration.GetChildren().ExtendedSingleOrDefault("Finding signalr config", c => c.Key == nameof(AppEnvironment.KeyValues.Signalr)); if (signalr != null) { TryReadConfig <string>(signalr, AppEnvironment.KeyValues.Signalr.SignalRAzureServiceBusConnectionString); TryReadConfig <string>(signalr, AppEnvironment.KeyValues.Signalr.SignalRSqlServerConnectionString); TryReadConfig <int>(signalr, AppEnvironment.KeyValues.Signalr.SignalRSqlServerTableCount); } IConfiguration?identityServer = Configuration.GetChildren().ExtendedSingleOrDefault("Finding identityServer config", c => c.Key == nameof(AppEnvironment.KeyValues.IdentityServer)); if (identityServer != null) { TryReadConfig <string>(identityServer, AppEnvironment.KeyValues.IdentityServer.IdentityServerSiteName); TryReadConfig <string>(identityServer, AppEnvironment.KeyValues.IdentityServer.ActiveDirectoryName); TryReadConfig <string>(identityServer, AppEnvironment.KeyValues.IdentityServer.LoginPagePath); TryReadConfig <string>(identityServer, AppEnvironment.KeyValues.IdentityServer.FacebookClientId); TryReadConfig <string>(identityServer, AppEnvironment.KeyValues.IdentityServer.FacebookSecret); TryReadConfig <string>(identityServer, AppEnvironment.KeyValues.IdentityServer.GoogleClientId); TryReadConfig <string>(identityServer, AppEnvironment.KeyValues.IdentityServer.GoogleSecret); TryReadConfig <string>(identityServer, AppEnvironment.KeyValues.IdentityServer.TwitterClientId); TryReadConfig <string>(identityServer, AppEnvironment.KeyValues.IdentityServer.TwitterSecret); TryReadConfig <string>(identityServer, AppEnvironment.KeyValues.IdentityServer.LinkedInClientId); TryReadConfig <string>(identityServer, AppEnvironment.KeyValues.IdentityServer.LinkedInSecret); TryReadConfig <string>(identityServer, AppEnvironment.KeyValues.IdentityServer.MicrosoftClientId); TryReadConfig <string>(identityServer, AppEnvironment.KeyValues.IdentityServer.MicrosoftSecret); } IConfiguration?hangfire = Configuration.GetChildren().ExtendedSingleOrDefault("Finding hangfire config", c => c.Key == nameof(AppEnvironment.KeyValues.Hangfire)); if (hangfire != null) { TryReadConfig <string>(hangfire, AppEnvironment.KeyValues.Hangfire.JobSchedulerDbConnectionString); } TryReadConnectionString(AppEnvironment.KeyValues.Signalr.SignalRAzureServiceBusConnectionString); TryReadConnectionString(AppEnvironment.KeyValues.Signalr.SignalRSqlServerConnectionString); TryReadConnectionString(AppEnvironment.KeyValues.Hangfire.JobSchedulerDbConnectionString); TryReadConnectionString(AppEnvironment.KeyValues.Data.LogDbConnectionstring); IConfiguration?appInfo = Configuration.GetChildren().ExtendedSingleOrDefault("Finding appInfo config", c => c.Key == nameof(AppEnvironment.AppInfo)); _appEnvironment = new AppEnvironment { Name = WebHostEnvironment.EnvironmentName, IsActive = true, DebugMode = WebHostEnvironment.IsDevelopment(), AppInfo = new EnvironmentAppInfo { Name = WebHostEnvironment.ApplicationName, Version = (Assembly.GetCallingAssembly().GetCustomAttribute <AssemblyFileVersionAttribute>() !).Version, DefaultTimeZone = appInfo?.GetValue <string?>(nameof(EnvironmentAppInfo.DefaultTimeZone), defaultValue: null) },