Last active
November 12, 2016 15:11
-
-
Save wmeints/d445f3cde1f9d09b3d90e68a65a9ccfa to your computer and use it in GitHub Desktop.
IdentityServer4 configuration
This file contains hidden or 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
public class Clients | |
{ | |
public static IEnumerable<Client> All => new[] | |
{ | |
new Client() | |
{ | |
AccessTokenType = AccessTokenType.Jwt, | |
ClientId = "9c328f06-01c7-4429-9870-7e55a73e2870", | |
RedirectUris = new List<string> | |
{ | |
"http://localhost:24042/auth_callback" | |
}, | |
ClientUri = "http://localhost:24042/", | |
AllowedCorsOrigins = new List<string> | |
{ | |
"http://localhost:24042/" | |
}, | |
AllowedGrantTypes = GrantTypes.Implicit, | |
AllowAccessTokensViaBrowser = true, | |
AllowedScopes = new[] { "stories.read", "stories.write", "openid", "profile" } | |
} | |
}; | |
} |
This file contains hidden or 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
public class Scopes | |
{ | |
public static IEnumerable<Scope> All => new[] | |
{ | |
// These two standard scopes are required for users to be able | |
// to logon to your application. | |
StandardScopes.OpenId, | |
StandardScopes.Profile, | |
// These two scopes are custom. You can define as many | |
// as you want and name them whatever you like. | |
new Scope | |
{ | |
Description = "Find stories of you and other users", | |
Name = "stories.read", | |
DisplayName = "Read stories" | |
}, | |
new Scope | |
{ | |
Description = "Manage your own story", | |
Name = "stories.write", | |
DisplayName = "Write stories" | |
} | |
}; | |
} |
This file contains hidden or 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
public class Startup | |
{ | |
/// <summary> | |
/// Gets invokes to setup the services for your web application | |
/// </summary> | |
/// <param name="services"></param> | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
// This bit of configuration ensures that your authorization | |
// API is available to browser clients coming from another | |
// domain. | |
services.AddCors(options => | |
{ | |
options.AddPolicy("DefaultCorsPolicy", builder => | |
{ | |
builder.AllowAnyHeader(); | |
builder.AllowAnyMethod(); | |
builder.AllowAnyOrigin(); | |
}); | |
}); | |
// This configures the identityserver services | |
// Please use a proper signing credential such as a certificate | |
// in production. This setup however is pretty useful for development. | |
services.AddIdentityServer() | |
.AddTemporarySigningCredential() | |
.AddInMemoryScopes(Scopes.All) | |
.AddInMemoryUsers(Users.All) | |
.AddInMemoryClients(Clients.All); | |
} | |
/// <summary> | |
/// Configures the request pipeline for the application | |
/// </summary> | |
/// <param name="app"></param> | |
/// <param name="env"></param> | |
/// <param name="loggerFactory"></param> | |
public void Configure(IApplicationBuilder app, IHostingEnvironment env, | |
ILoggerFactory loggerFactory) | |
{ | |
loggerFactory.AddConsole(); | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.UseCors("DefaultCorsPolicy"); | |
// Hook up the identity server middleware and you're up and going :-) | |
app.UseIdentityServer(); | |
} | |
} |
This file contains hidden or 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
public class Users | |
{ | |
public static List<InMemoryUser> All => new List<InMemoryUser> | |
{ | |
new InMemoryUser | |
{ | |
Username = "admin", | |
Password = "SomePassword1", | |
Subject = "admin@localhost" | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment