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); }