Skip to content

Commit b9f7ebc

Browse files
committed
update UI to use resource indicators
1 parent 1b2107f commit b9f7ebc

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

samples/Web/Controllers/HomeController.cs

+28
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ public async Task<IActionResult> CallApiAsUserFactoryTyped([FromServices] TypedU
6969
return View("CallApi");
7070
}
7171

72+
[AllowAnonymous]
73+
public async Task<IActionResult> CallApiAsUserResourceIndicator()
74+
{
75+
var token = await HttpContext.GetUserAccessTokenAsync(new UserTokenRequestParameters { Resource = "urn:resource1" });
76+
var client = _httpClientFactory.CreateClient();
77+
client.SetToken(token.AccessTokenType!, token.AccessToken!);
78+
79+
var response = await client.GetStringAsync("https://demo.duendesoftware.com/api/test");
80+
81+
ViewBag.Json = PrettyPrint(response);
82+
return View("CallApi");
83+
}
84+
85+
7286
[AllowAnonymous]
7387
public async Task<IActionResult> CallApiAsClientExtensionMethod()
7488
{
@@ -81,7 +95,21 @@ public async Task<IActionResult> CallApiAsClientExtensionMethod()
8195
ViewBag.Json = PrettyPrint(response);
8296
return View("CallApi");
8397
}
98+
99+
[AllowAnonymous]
100+
public async Task<IActionResult> CallApiAsClientResourceIndicator()
101+
{
102+
var token = await HttpContext.GetClientAccessTokenAsync(new UserTokenRequestParameters { Resource = "urn:resource1" });
103+
var client = _httpClientFactory.CreateClient();
104+
client.SetToken(token.AccessTokenType!, token.AccessToken!);
105+
106+
var response = await client.GetStringAsync("https://demo.duendesoftware.com/api/test");
107+
108+
ViewBag.Json = PrettyPrint(response);
109+
return View("CallApi");
110+
}
84111

112+
85113
[AllowAnonymous]
86114
public async Task<IActionResult> CallApiAsClientFactory()
87115
{

samples/Web/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"Web": {
44
"commandName": "Project",
55
"launchBrowser": true,
6-
"applicationUrl": "https://localhost:5001;http://localhost:5000",
6+
"applicationUrl": "https://localhost:5002",
77
"environmentVariables": {
88
"ASPNETCORE_ENVIRONMENT": "Development"
99
}

samples/Web/Startup.cs

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Security.Cryptography;
66
using System.Text.Json;
7+
using System.Threading.Tasks;
78
using Microsoft.AspNetCore.Authentication;
89
using Microsoft.AspNetCore.Builder;
910
using Microsoft.Extensions.DependencyInjection;
@@ -33,6 +34,7 @@ internal static WebApplication ConfigureServices(this WebApplicationBuilder buil
3334
.AddOpenIdConnect("oidc", options =>
3435
{
3536
options.Authority = "https://demo.duendesoftware.com";
37+
//options.Authority = "https://localhost:5001";
3638

3739
options.ClientId = "interactive.confidential.short";
3840
options.ClientSecret = "secret";
@@ -46,6 +48,7 @@ internal static WebApplication ConfigureServices(this WebApplicationBuilder buil
4648
options.Scope.Add("email");
4749
options.Scope.Add("offline_access");
4850
options.Scope.Add("api");
51+
options.Scope.Add("resource1.scope1");
4952

5053
options.GetClaimsFromUserInfoEndpoint = true;
5154
options.SaveTokens = true;
@@ -56,6 +59,12 @@ internal static WebApplication ConfigureServices(this WebApplicationBuilder buil
5659
NameClaimType = "name",
5760
RoleClaimType = "role"
5861
};
62+
63+
options.Events.OnRedirectToIdentityProvider = ctx =>
64+
{
65+
ctx.ProtocolMessage.Resource = "urn:resource1";
66+
return Task.CompletedTask;
67+
};
5968
});
6069

6170
var rsaKey = new RsaSecurityKey(RSA.Create(2048));

samples/Web/Views/Home/Index.cshtml

+2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
<a href="./home/CallApiAsClientFactory">HTTP client factory</a>
1010
|
1111
<a href="./home/CallApiAsClientFactoryTyped">HTTP client factory (typed)</a>
12+
|
13+
<a href="./home/CallApiAsClientResourceIndicator">Use resource indicator</a>
1214

1315

samples/Web/Views/Home/Secure.cshtml

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<a href="./CallApiAsUserFactory">HTTP client factory</a>
1010
|
1111
<a href="./CallApiAsUserFactoryTyped">HTTP client factory (typed)</a>
12+
|
13+
<a href="./CallApiAsUserResourceIndicator">Use resource indicator</a>
1214

1315
<h3>Call API as Client</h3>
1416

@@ -17,7 +19,8 @@
1719
<a href="./CallApiAsClientFactory">HTTP client factory</a>
1820
|
1921
<a href="./CallApiAsClientFactoryTypes">HTTP client factory (typed)</a>
20-
22+
|
23+
<a href="./CallApiAsClientResourceIndicator">Use resource indicator</a>
2124

2225
<h2>Claims</h2>
2326

0 commit comments

Comments
 (0)