public void Initialize(string basePath = null)
        {
            var builder = new WebHostBuilder();

            builder.ConfigureServices(ConfigureServices);
            builder.Configure(app =>
            {
                if (basePath != null)
                {
                    app.Map(basePath, map =>
                    {
                        ConfigureApp(map);
                    });
                }
                else
                {
                    ConfigureApp(app);
                }
            });

            Server  = new TestServer(builder);
            Handler = Server.CreateHandler();

            BrowserClient = new BrowserClient(new BrowserHandler(Handler));
            Client        = new HttpClient(Handler);
        }
示例#2
0
        public void Initialize(string basePath = null, bool enableLogging = false)
        {
            var builder = new WebHostBuilder();

            builder.ConfigureServices(ConfigureServices);
            builder.Configure(app =>
            {
                if (basePath != null)
                {
                    app.Map(basePath, map =>
                    {
                        ConfigureApp(map);
                    });
                }
                else
                {
                    ConfigureApp(app);
                }
            });

            if (enableLogging)
            {
                builder.ConfigureLogging((ctx, b) => b.AddConsole());
            }

            Server  = new TestServer(builder);
            Handler = Server.CreateHandler();

            BrowserClient     = new BrowserClient(new BrowserHandler(Handler));
            BackChannelClient = new HttpClient(Handler);
        }
        /* helpers */
        public async Task LoginAsync(ClaimsPrincipal subject)
        {
            var old = BrowserClient.AllowAutoRedirect;

            BrowserClient.AllowAutoRedirect = false;

            Subject = subject;
            await BrowserClient.GetAsync(LoginPage);

            BrowserClient.AllowAutoRedirect = old;
        }
        public async Task <AuthorizeResponse> RequestAuthorizationEndpointAsync(
            string clientId,
            string responseType,
            string scope               = null,
            string redirectUri         = null,
            string state               = null,
            string nonce               = null,
            string loginHint           = null,
            string acrValues           = null,
            string responseMode        = null,
            string codeChallenge       = null,
            string codeChallengeMethod = null,
            object extra               = null)
        {
            var old = BrowserClient.AllowAutoRedirect;

            BrowserClient.AllowAutoRedirect = false;

            var url    = CreateAuthorizeUrl(clientId, responseType, scope, redirectUri, state, nonce, loginHint, acrValues, responseMode, codeChallenge, codeChallengeMethod, extra);
            var result = await BrowserClient.GetAsync(url);

            result.StatusCode.Should().Be(HttpStatusCode.Found);

            BrowserClient.AllowAutoRedirect = old;

            var redirect = result.Headers.Location.ToString();

            if (redirect.StartsWith(IdentityServerPipeline.ErrorPage))
            {
                // request error page in pipeline so we can get error info
                await BrowserClient.GetAsync(redirect);

                // no redirect to client
                return(null);
            }

            return(new AuthorizeResponse(redirect));
        }
 public Cookie GetSessionCookie()
 {
     return(BrowserClient.GetCookie(BaseUrl, IdentityServerConstants.DefaultCheckSessionCookieName));
 }
 public void RemoveSessionCookie()
 {
     BrowserClient.RemoveCookie(BaseUrl, IdentityServerConstants.DefaultCheckSessionCookieName);
 }
 public void RemoveLoginCookie()
 {
     BrowserClient.RemoveCookie(BaseUrl, IdentityServerConstants.DefaultCookieAuthenticationScheme);
 }
 public Cookie GetSessionCookie()
 {
     return(BrowserClient.GetCookie("https://server/", $"{Options.AuthenticationOptions.EffectiveAuthenticationScheme}.session"));
 }
 public void RemoveSessionCookie()
 {
     BrowserClient.RemoveCookie("https://server/", $"{Options.AuthenticationOptions.EffectiveAuthenticationScheme}.session");
 }
 public void RemoveLoginCookie()
 {
     BrowserClient.RemoveCookie("https://server/", ".AspNetCore.cookie_authn");
 }
 public Cookie GetSessionCookie()
 {
     return(BrowserClient.GetCookie("https://server/", "idsvr.session"));
 }
 public void RemoveSessionCookie()
 {
     BrowserClient.RemoveCookie("https://server/", "idsvr.session");
 }
 public Cookie GetSessionCookie()
 {
     return(BrowserClient.GetCookie("https://server/", IdentityServerConstants.DefaultCheckSessionCookieName));
 }
 public void RemoveSessionCookie()
 {
     BrowserClient.RemoveCookie("https://server/", IdentityServerConstants.DefaultCheckSessionCookieName);
 }