Skip to content

Commit c08d603

Browse files
RolandGuijtRoland Guijt
andauthored
Configuration samples now use the common SimpleApi (#280)
Co-authored-by: Roland Guijt <roland.guijt@duendesoftware.com>
1 parent 366482a commit c08d603

File tree

35 files changed

+58
-435
lines changed

35 files changed

+58
-435
lines changed

IdentityServer/v7/Apis/SimpleApi/Program.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
builder.Services.AddControllers();
2323

24-
// this API will accept any access token from the authority
24+
// Attention: This API will accept any access token from the authority in this configuration
2525
builder.Services.AddAuthentication("token")
2626
.AddJwtBearer("token", options =>
2727
{
@@ -32,12 +32,19 @@
3232
options.MapInboundClaims = false;
3333
});
3434

35+
// To require a scope, use a policy like this and apply it
36+
builder.Services.AddAuthorization(options =>
37+
{
38+
options.AddPolicy("SimpleApi", p => p.RequireClaim("scope", "SimpleApi"));
39+
});
40+
3541
var app = builder.Build();
3642

3743
app.UseRouting();
3844
app.UseAuthentication();
3945
app.UseAuthorization();
4046

4147
app.MapControllers().RequireAuthorization();
48+
//app.MapControllers().RequireAuthorization("SimpleApi");
4249

4350
app.Run();

IdentityServer/v7/Configuration/IdentityServerHost/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"profiles": {
3-
"Self": {
3+
"SelfHost": {
44
"commandName": "Project",
55
"launchBrowser": true,
66
"environmentVariables": {

IdentityServer/v7/Configuration/Permissions/Configuration/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"commandName": "Project",
55
"dotnetRunMessages": true,
66
"launchBrowser": false,
7-
"applicationUrl": "https://localhost:5002",
7+
"applicationUrl": "https://localhost:5003",
88
"environmentVariables": {
99
"ASPNETCORE_ENVIRONMENT": "Development"
1010
}

IdentityServer/v7/Configuration/Permissions/ConsoleDcrClient/Constants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ namespace ConsoleDcrClient;
66
public class Constants
77
{
88
public const string Authority = "https://localhost:5001";
9-
public const string SimpleApi = "https://localhost:6001/";
9+
public const string SimpleApi = "https://localhost:5002/";
10+
public const string ConfigurationApi = "https://localhost:5003";
1011
}

IdentityServer/v7/Configuration/Permissions/ConsoleDcrClient/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static async Task<DynamicClientRegistrationResponse> RegisterClient(string acces
4949

5050
var request = new DynamicClientRegistrationRequest
5151
{
52-
Address = "https://localhost:5002/connect/dcr",
52+
Address = $"{Constants.ConfigurationApi}/connect/dcr",
5353
Document = new DynamicClientRegistrationDocument
5454
{
5555

@@ -77,7 +77,7 @@ static async Task<TokenResponse> RequestTokenAsync(string clientId = "client", s
7777
{
7878
var client = new HttpClient();
7979

80-
var disco = await client.GetDiscoveryDocumentAsync("https://localhost:5001");
80+
var disco = await client.GetDiscoveryDocumentAsync(Constants.Authority);
8181
if (disco.IsError) throw new Exception(disco.Error);
8282

8383
var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest

IdentityServer/v7/Configuration/Permissions/Permissions.sln

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Configuration", "Configurat
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDcrClient", "ConsoleDcrClient\ConsoleDcrClient.csproj", "{D134466E-58AE-4787-984B-FB6F95EEA969}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleApi", "SimpleApi\SimpleApi.csproj", "{CCAA779F-8528-4351-8333-80B60A7C4FAC}"
11-
EndProject
1210
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityServer", "..\IdentityServerHost\IdentityServer.csproj", "{075FD8FE-6A12-4121-9163-F2A48001F37B}"
1311
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleApi", "..\..\Apis\SimpleApi\SimpleApi.csproj", "{52E6BB46-1B26-431D-B13E-D58734BFF1B2}"
13+
EndProject
1414
Global
1515
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1616
Debug|Any CPU = Debug|Any CPU
@@ -28,13 +28,13 @@ Global
2828
{D134466E-58AE-4787-984B-FB6F95EEA969}.Debug|Any CPU.Build.0 = Debug|Any CPU
2929
{D134466E-58AE-4787-984B-FB6F95EEA969}.Release|Any CPU.ActiveCfg = Release|Any CPU
3030
{D134466E-58AE-4787-984B-FB6F95EEA969}.Release|Any CPU.Build.0 = Release|Any CPU
31-
{CCAA779F-8528-4351-8333-80B60A7C4FAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32-
{CCAA779F-8528-4351-8333-80B60A7C4FAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
33-
{CCAA779F-8528-4351-8333-80B60A7C4FAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
34-
{CCAA779F-8528-4351-8333-80B60A7C4FAC}.Release|Any CPU.Build.0 = Release|Any CPU
3531
{075FD8FE-6A12-4121-9163-F2A48001F37B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3632
{075FD8FE-6A12-4121-9163-F2A48001F37B}.Debug|Any CPU.Build.0 = Debug|Any CPU
3733
{075FD8FE-6A12-4121-9163-F2A48001F37B}.Release|Any CPU.ActiveCfg = Release|Any CPU
3834
{075FD8FE-6A12-4121-9163-F2A48001F37B}.Release|Any CPU.Build.0 = Release|Any CPU
35+
{52E6BB46-1B26-431D-B13E-D58734BFF1B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{52E6BB46-1B26-431D-B13E-D58734BFF1B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{52E6BB46-1B26-431D-B13E-D58734BFF1B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
38+
{52E6BB46-1B26-431D-B13E-D58734BFF1B2}.Release|Any CPU.Build.0 = Release|Any CPU
3939
EndGlobalSection
4040
EndGlobal

IdentityServer/v7/Configuration/Permissions/SimpleApi/IdentityController.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

IdentityServer/v7/Configuration/Permissions/SimpleApi/Program.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

IdentityServer/v7/Configuration/Permissions/SimpleApi/Properties/launchSettings.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

IdentityServer/v7/Configuration/Permissions/SimpleApi/SimpleApi.csproj

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)