protected override void RequestStartup(ILifetimeScope container, IPipelines pipelines, NancyContext context) { var tokenizer = container.Resolve <ITokenizer>(); var tokenConfiguration = new TokenAuthenticationConfiguration(tokenizer); TokenAuthentication.Enable(pipelines, tokenConfiguration); }
public void Should_throw_with_null_module_passed_to_enable_with_config() { // Given, When var result = Record.Exception(() => TokenAuthentication.Enable((INancyModule)null, null)); // Then result.ShouldBeOfType(typeof(ArgumentNullException)); }
public void Should_throw_with_null_config_passed_to_enable_with_application() { // Given, When var result = Record.Exception(() => TokenAuthentication.Enable(A.Fake <IPipelines>(), null)); // Then result.ShouldBeOfType(typeof(ArgumentNullException)); }
public void Should_add_both_token_and_requires_auth_pre_hook_in_module_when_enabled() { // Given var module = new FakeModule(); // When TokenAuthentication.Enable(module, this.config); // Then module.Before.PipelineDelegates.ShouldHaveCount(2); }
protected override void RequestStartup(IContainer requestContainer, IPipelines pipelines, NancyContext context) { // Enable token authentication TokenAuthentication.Enable(pipelines, new TokenAuthenticationConfiguration(requestContainer.GetInstance <ITokenizer>())); // Set up unit of work pipelines.BeforeRequest += UnitOfWorkPipeline.BeforeRequest(requestContainer); pipelines.AfterRequest += UnitOfWorkPipeline.AfterRequest(); // Set up validation exception handling pipelines.OnError += HttpBadRequestPipeline.OnHttpBadRequest; }
public void Should_add_a_pre_hook_in_application_when_enabled() { // Given var pipelines = A.Fake <IPipelines>(); // When TokenAuthentication.Enable(pipelines, this.config); // Then A.CallTo(() => pipelines.BeforeRequest.AddItemToStartOfPipeline(A <Func <NancyContext, Response> > .Ignored)) .MustHaveHappened(Repeated.Exactly.Once); }
protected override void RequestStartup(Autofac.ILifetimeScope container, Nancy.Bootstrapper.IPipelines pipelines, NancyContext context) { TokenAuthentication.Enable(pipelines, new TokenAuthenticationConfiguration(container.Resolve<ITokenizer>())); pipelines.AfterRequest.AddItemToEndOfPipeline(AddCorsHeaders()); pipelines.OnError.AddItemToEndOfPipeline((ctx, err) => HandleExceptions(err, ctx) ); base.RequestStartup(container, pipelines, context); }
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines) { var tokenizer = container.Resolve <ITokenizer>(); var cfg = new TokenAuthenticationConfiguration(tokenizer); TokenAuthentication.Enable(pipelines, cfg); pipelines.OnError.AddItemToStartOfPipeline((context, exception) => { _logger.Error(exception, "Error in HTTP pipeline."); return(null); }); }
protected override void RequestStartup(ILifetimeScope container, IPipelines pipelines, NancyContext context) { var tokenConfig = new TokenAuthenticationConfiguration(container.Resolve <ITokenizer>()); TokenAuthentication.Enable(pipelines, tokenConfig); pipelines.BeforeRequest.AddItemToEndOfPipeline(nancyContext => { _log.TraceFormat("{0} {1}", nancyContext.Request.Method.PadRight(5, ' '), nancyContext.Request.Url); return((Response)null); }); base.RequestStartup(container, pipelines, context); }
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context) { TokenAuthentication.Enable(pipelines, new TokenAuthenticationConfiguration(container.Resolve <ITokenizer>())); pipelines.BeforeRequest.AddItemToStartOfPipeline(c => { if (c.Request.Method != "OPTIONS") { return(null); } return(new Response { StatusCode = HttpStatusCode.NoContent } .WithHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, DELETE") .WithHeader("Access-Control-Allow-Headers", "Content-Type")); }); pipelines.AfterRequest.AddItemToEndOfPipeline(c => c.Response.WithHeader("Access-Control-Allow-Origin", "*") ); }
public void Should_set_user_in_context_with_valid_username_in_auth_header() { // Given var fakePipelines = new Pipelines(); var context = CreateContextWithHeader( "Authorization", new[] { "Token" + " " + "mytoken" }); var tokenizer = A.Fake <ITokenizer>(); var fakeUser = A.Fake <IUserIdentity>(); A.CallTo(() => tokenizer.Detokenize("mytoken", context, A <IUserIdentityResolver> .Ignored)).Returns(fakeUser); var cfg = new TokenAuthenticationConfiguration(tokenizer); TokenAuthentication.Enable(fakePipelines, cfg); // When fakePipelines.BeforeRequest.Invoke(context, new CancellationToken()); // Then context.CurrentUser.ShouldBeSameAs(fakeUser); }
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context) { TokenAuthentication.Enable(pipelines, new TokenAuthenticationConfiguration(container.Resolve <ITokenizer>())); }
public TokenAuthenticationFixture() { this.config = new TokenAuthenticationConfiguration(A.Fake <ITokenizer>()); this.hooks = new Pipelines(); TokenAuthentication.Enable(this.hooks, this.config); }
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context) { CustomErrorHandler.Enable(pipelines, container.Resolve <IResponseNegotiator>()); TokenAuthentication.Enable(pipelines, new TokenAuthenticationConfiguration(container.Resolve <ITokenizer>())); }