Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /* helpers */
        public async Task LoginAsync(ClaimsPrincipal subject)
        {
            var old = BrowserClient.AllowAutoRedirect;

            BrowserClient.AllowAutoRedirect = false;

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

            BrowserClient.AllowAutoRedirect = old;
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
 public Cookie GetSessionCookie()
 {
     return(BrowserClient.GetCookie(BaseUrl, IdentityServerConstants.DefaultCheckSessionCookieName));
 }
Ejemplo n.º 5
0
 public void RemoveSessionCookie()
 {
     BrowserClient.RemoveCookie(BaseUrl, IdentityServerConstants.DefaultCheckSessionCookieName);
 }
Ejemplo n.º 6
0
 public void RemoveLoginCookie()
 {
     BrowserClient.RemoveCookie(BaseUrl, IdentityServerConstants.DefaultCookieAuthenticationScheme);
 }