c# - Integration testing ASP.NET WebAPI controllers that use bearer authentication with identityserver3 -


i'm trying integration test web api controllers. application uses jwts authenticate users against resource server.

to spool application, i'm using testserver found in microsoft.owin.testing.

i can obtain valid jwt performing login browser do. proceed add jwt request follows:

request.addheader("authorization", "bearer " + accesstoken.rawdata); 

that header arrives in owin pipeline. however, controllers protected [authorize]-attribute return 401 unauthorized when invoked.

the api protected using identityserver3 thinktecture, relevant section looks this:

var authority = "http://localhost:8080/idsrv/"; var parameters = new tokenvalidationparameters() { validaudiences = new[] { "implicitclient" } };  var options = new identityserverbearertokenauthenticationoptions                     {                         authority = authority,                          tokenvalidationparameters = parameters                     };  app.useidentityserverbearertokenauthentication(options);  var configuration = new webapiconfiguration(this.container); configuration.configuration(app); 

i don't know pointers problem, appreciated.

do want test token middleware? mean - not testing token middleware - controller logic based on authentication outcomes.

just write small inline middleware sets context.authentication.user claimsprincipal want test with.

app.use(async (ctx, next) => { ctx.authentication.user = someprincipal; await next() };


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -