예제 #1
0
        public override Task Invoke(IOwinContext context)
        {
            IDependencyResolver dependencyResolver = context.GetDependencyResolver();

            IRandomStringProvider randomStringProvider = dependencyResolver.Resolve <IRandomStringProvider>();

            IAppEnvironmentProvider appEnvironmentProvider = dependencyResolver.Resolve <IAppEnvironmentProvider>();

            AppEnvironment activEnvironment = appEnvironmentProvider.GetActiveAppEnvironment();

            if (_baseRedirectUri == null)
            {
                _baseRedirectUri = $"{activEnvironment.Security.SSOServerUrl}/connect/authorize?scope={string.Join(" ", activEnvironment.Security.Scopes)}&client_id={activEnvironment.Security.ClientName}&redirect_uri={activEnvironment.GetConfig("ClientHostBaseUri", context.Request.Host.Value)}{activEnvironment.GetConfig("ClientHostVirtualPath", "/")}SignIn&response_type=id_token token";
            }

            string pathname = activEnvironment.GetConfig("ClientHostVirtualPath", "/") + (context.Request.Path.HasValue ? context.Request.Path.Value.Substring(1) : string.Empty);

            string state = $@"{{""pathname"":""{pathname}""}}";

            string nonce = randomStringProvider.GetRandomNonSecureString(12);

            string redirectUrl = $"{_baseRedirectUri}&state={state}&nonce={nonce}";

            context.Response.Redirect(redirectUrl);

            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 override async Task Invoke(IOwinContext context)
        {
            IDependencyResolver dependencyResolver = context.GetDependencyResolver();

            IRandomStringProvider randomStringProvider = dependencyResolver.Resolve <IRandomStringProvider>();

            IContentFormatter contentFormatter = dependencyResolver.Resolve <IContentFormatter>();

            if (_baseRedirectUri == null)
            {
                IAppEnvironmentProvider appEnvironmentProvider = dependencyResolver
                                                                 .Resolve <IAppEnvironmentProvider>();

                AppEnvironment activEnvironment = appEnvironmentProvider.GetActiveAppEnvironment();

                _baseRedirectUri = $"{activEnvironment.Security.SSOServerUrl}/connect/authorize?scope={string.Join(" ", activEnvironment.Security.Scopes)}&client_id={activEnvironment.Security.ClientName}&redirect_uri={activEnvironment.GetConfig("ClientHostBaseUri", context.Request.Host.Value)}{activEnvironment.GetConfig("ClientHostVirtualPath", "/")}SignIn&response_type=id_token token";
            }

            string nonce = randomStringProvider.GetRandomNonSecureString(12);

            string stateArgs = string.Join(string.Empty, context.Request.Path.Value.SkipWhile(c => c == '/'));

            string redirectUrl = $"{_baseRedirectUri}&state={stateArgs}&nonce={nonce}";

            context.Response.Redirect(redirectUrl);
        }
예제 #4
0
        public override Task Invoke(IOwinContext 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);
        }
예제 #5
0
        public override async Task Invoke(IOwinContext context)
        {
            IDependencyResolver dependencyResolver = context.GetDependencyResolver();

            IRandomStringProvider randomStringProvider = dependencyResolver.Resolve <IRandomStringProvider>();

            IAppEnvironmentProvider appEnvironmentProvider = dependencyResolver.Resolve <IAppEnvironmentProvider>();

            AppEnvironment activeAppEnvironment = appEnvironmentProvider.GetActiveAppEnvironment();

            string redirectUriHost = $"{context.Request.Scheme}://{context.Request.Host.Value}{activeAppEnvironment.GetHostVirtualPath()}SignIn";
            string redirectUri     = $"{activeAppEnvironment.GetSsoUrl()}/connect/authorize?scope={string.Join(" ", activeAppEnvironment.Security.Scopes)}&client_id={activeAppEnvironment.Security.ClientId}&redirect_uri={redirectUriHost}&response_type=id_token token";

            string stateArgs = string.Join(string.Empty, context.Request.Path.Value.SkipWhile(c => c == '/'));

            string nonce = randomStringProvider.GetRandomNonSecureString(12);

            context.Response.Redirect($"{redirectUri}&state={stateArgs}&nonce={nonce}");
        }
예제 #6
0
        public async Task RedirectToSsoIfNotLoggedInOnRootUrl()
        {
            using (BitOwinTestEnvironment testEnvironment = new BitOwinTestEnvironment(new TestEnvironmentArgs
            {
                AdditionalDependencies = (manager, services) =>
                {
                    IRandomStringProvider randomStringProvider = A.Fake <IRandomStringProvider>();

                    A.CallTo(() => randomStringProvider.GetRandomString(12))
                    .Returns("RandomString");

                    manager.RegisterInstance(randomStringProvider);
                }
            }))
            {
                HttpResponseMessage getIndexPageResponse = await testEnvironment.Server.BuildHttpClient()
                                                           .GetAsync("/some-page", HttpCompletionOption.ResponseHeadersRead);

                Assert.AreEqual(HttpStatusCode.Redirect, getIndexPageResponse.StatusCode);

                Assert.AreEqual(@"/core/connect/authorize?scope=openid profile user_info&client_id=Test&redirect_uri=http://localhost/SignIn&response_type=id_token token&state={""pathname"":""/some-page""}&nonce=RandomString", getIndexPageResponse.Headers.Location.ToString());
            }
        }
        public override Task Invoke(IOwinContext context)
        {
            IDependencyResolver dependencyResolver = context.GetDependencyResolver();

            IRandomStringProvider randomStringProvider = dependencyResolver.Resolve <IRandomStringProvider>();

            IAppEnvironmentProvider appEnvironmentProvider = dependencyResolver.Resolve <IAppEnvironmentProvider>();

            AppEnvironment activeAppEnvironment = appEnvironmentProvider.GetActiveAppEnvironment();

            string redirectUriHost = $"{context.Request.Scheme}://{context.Request.Host.Value}{activeAppEnvironment.GetHostVirtualPath()}SignIn";
            string redirectUri     = $"{activeAppEnvironment.GetSsoUrl()}/connect/authorize?scope={string.Join(" ", activeAppEnvironment.Security.Scopes)}&client_id={activeAppEnvironment.Security.ClientId}&redirect_uri={redirectUriHost}&response_type=id_token token";

            string pathname = activeAppEnvironment.GetHostVirtualPath() + (context.Request.Path.HasValue ? context.Request.Path.Value.Substring(1) : string.Empty);

            string state = $@"{{""pathname"":""{pathname}""}}";

            string nonce = randomStringProvider.GetRandomNonSecureString(12);

            context.Response.Redirect($"{redirectUri}&state={state}&nonce={nonce}");

            return(Task.CompletedTask);
        }
예제 #8
0
 public ValuesController(IRandomStringProvider randomStringProvider)
 {
     _randomStringProvider = randomStringProvider;
 }
 public DataRefreshService(IRandomStringProvider randomStringProvider)
 {
     _randomStringProvider = randomStringProvider;
 }