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
public static IEnumerable<Client> GetClients() | |
{ | |
return new List<Client> | |
{ | |
new Client | |
{ | |
ClientId = "mvc", | |
ClientName = "MVC Client", | |
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials, |
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
public static IEnumerable<IdentityResource> GetIdentityResources() | |
{ | |
return new List<IdentityResource> | |
{ | |
new IdentityResources.OpenId(), | |
new IdentityResources.Profile(), | |
}; | |
} |
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
public static IEnumerable<ApiResource> GetApiResources() | |
{ | |
return new List<ApiResource> | |
{ | |
new ApiResource("Api1", "Protected Api") | |
}; | |
} |
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
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc(); | |
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); | |
services.AddAuthentication(options => | |
{ | |
options.DefaultScheme = "Cookies"; | |
options.DefaultChallengeScheme = "oidc"; |
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
[Authorize("Founder")] | |
public IActionResult Secure() | |
{ | |
ViewData["Message"] = "Secure page."; | |
return View(); | |
} |
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
[Produces("application/json")] | |
public class IdentityController : Controller | |
{ | |
[HttpGet] | |
[Authorize("Founder")] | |
[Route("api/resource-with-policy")] | |
public IActionResult ResourceWithPolicy() | |
{ | |
return new JsonResult(new { ApiName = "Api1", AuthorizationType = "With Policy" }); | |
} |
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
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvcCore() | |
.AddAuthorization(options => options.AddPolicy("Founder", policy => policy.RequireClaim("Employee", "Mosalla"))) | |
.AddJsonFormatters(); | |
services.AddAuthentication("Bearer") | |
.AddIdentityServerAuthentication(options => | |
{ | |
options.Authority = "http://localhost:5000"; |
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
public static async Task<string> RequestWithResourceOwnerPasswordWithPolicy() | |
{ | |
async Task<string> GetAccessToken() | |
{ | |
var discoveryResponse = await DiscoveryClient.GetAsync("http://localhost:5000"); | |
// request token | |
var tokenClient = new TokenClient(discoveryResponse.TokenEndpoint, "ro.client1", "123654"); | |
var accessToken = await tokenClient.RequestResourceOwnerPasswordAsync("mosalla", "password", "Api1"); | |
if (accessToken.IsError) |
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
public static async Task<string> RequestWithClientCredentialsWithPolicy() | |
{ | |
async Task<string> GetAccessToken() | |
{ | |
var openIdConnectEndPoint = await DiscoveryClient.GetAsync("http://localhost:5000"); | |
var tokenClient = new TokenClient(openIdConnectEndPoint.TokenEndpoint, "client1", "123654"); | |
var accessToken = await tokenClient.RequestClientCredentialsAsync("Api1"); | |
if (accessToken.IsError) | |
{ |
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
public class ProfileService : IProfileService | |
{ | |
public Task GetProfileDataAsync(ProfileDataRequestContext context) | |
{ | |
context.IssuedClaims.AddRange(context.Subject.Claims); | |
return Task.FromResult(0); | |
} | |
public Task IsActiveAsync(IsActiveContext context) |