Created
November 13, 2015 04:43
-
-
Save zsims/f15b11de7b96c61f2ef5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NB: Assume this is hosted at
localhost:14869