Skip to content

Commit 6230626

Browse files
committed
OnTokenValidated extension MIW 2.0
1 parent ab25e19 commit 6230626

File tree

1 file changed

+16
-13
lines changed
  • 4-WebApp-your-API/4-3-AnyOrg/TodoListService

1 file changed

+16
-13
lines changed

4-WebApp-your-API/4-3-AnyOrg/TodoListService/Startup.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,23 @@ public void ConfigureServices(IServiceCollection services)
3333

3434
// Comment above lines of code and uncomment this section if you would like to validate ID tokens for allowed tenantIds
3535
//services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
36-
// .AddProtectedWebApi(options => {
37-
// Configuration.Bind("AzureAd", options);
38-
// options.Events = new JwtBearerEvents();
39-
// options.Events.OnTokenValidated = async context=>{
40-
// string[] allowedTenants = { /* list of tenant IDs */ };
41-
// string tenantId = context.Principal.Claims.FirstOrDefault(x => x.Type == "tid" || x.Type == "http://schemas.microsoft.com/identity/claims/tenantid")?.Value;
36+
// .AddMicrosoftWebApi(options =>
37+
//{
38+
// Configuration.Bind("AzureAd", options);
39+
// options.Events = new JwtBearerEvents();
40+
// options.Events.OnTokenValidated = async context =>
41+
// {
42+
// string[] allowedTenants = {/* list of tenant IDs */ };
43+
// string tenantId = context.Principal.Claims.FirstOrDefault(x => x.Type == "tid" || x.Type == "http://schemas.microsoft.com/identity/claims/tenantid")?.Value;
4244

43-
// if (!allowedTenants.Contains(tenantId))
44-
// {
45-
// throw new Exception("This tenant is not authorized");
46-
// }
47-
// };
48-
// },
49-
// options => { Configuration.Bind("AzureAd", options); });
45+
// if (!allowedTenants.Contains(tenantId))
46+
// {
47+
// throw new Exception("This tenant is not authorized");
48+
// }
49+
// };
50+
//}, options => { Configuration.Bind("AzureAd", options); })
51+
// .AddMicrosoftWebApiCallsWebApi(Configuration)
52+
// .AddInMemoryTokenCaches();
5053

5154
// Creating policies that wraps the authorization requirements
5255
services.AddAuthorization();

0 commit comments

Comments
 (0)