Skip to content

Instantly share code, notes, and snippets.

@zsims
Created November 13, 2015 04:43
Show Gist options
  • Save zsims/f15b11de7b96c61f2ef5 to your computer and use it in GitHub Desktop.
Save zsims/f15b11de7b96c61f2ef5 to your computer and use it in GitHub Desktop.
using Microsoft.Owin;
using Owin;
using System.Web.Http;
using IdentityServer3.AccessTokenValidation;
using IdentityServer3.Core.Configuration;
using IdSrv;
[assembly: OwinStartup(typeof(Apis.Startup))]
namespace Apis
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Map("/identity", idsrvApp =>
{
var options = new IdentityServerOptions
{
Factory = new IdentityServerServiceFactory()
.UseInMemoryClients(Clients.Get())
.UseInMemoryScopes(Scopes.Get())
.UseInMemoryUsers(Users.Get()),
RequireSsl = false
};
app.UseIdentityServer(options);
});
// accept access tokens from identityserver and require a scope of 'api1'
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "http://localhost:14869/identity",
ValidationMode = ValidationMode.Local,
RequiredScopes = new[] { "api1" }
});
// configure web api
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
// require authentication for all controllers
config.Filters.Add(new AuthorizeAttribute());
app.UseWebApi(config);
}
}
}
@zsims
Copy link
Author

zsims commented Nov 13, 2015

NB: Assume this is hosted at localhost:14869

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment