Skip to content

Commit 2006c23

Browse files
committed
Add license headers
1 parent bcefe98 commit 2006c23

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

Scenarios/Authentication/Minimal-machine-to-machine-using-JWT/Client/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System.Net;
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Net;
25
using System.ServiceModel;
36
using System.ServiceModel.Channels;
47
using IdentityModel.Client;

Scenarios/Authentication/Minimal-machine-to-machine-using-JWT/Service/ISecuredService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace Service;
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Service;
25

36
[ServiceContract]
47
public interface ISecuredService

Scenarios/Authentication/Minimal-machine-to-machine-using-JWT/Service/Program.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Microsoft.AspNetCore.Authentication.JwtBearer;
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.AspNetCore.Authentication.JwtBearer;
25
using Microsoft.AspNetCore.Authorization;
36

47
var builder = WebApplication.CreateBuilder();
@@ -13,7 +16,12 @@
1316
{
1417
options.DefaultPolicy = new AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme)
1518
.RequireAuthenticatedUser()
16-
.RequireClaim("scope", "api")
19+
.RequireAssertion(context =>
20+
{
21+
string[] scopes = context.User.FindFirst("scope")?.Value.Split(' ', StringSplitOptions.RemoveEmptyEntries)
22+
?? Array.Empty<string>();
23+
return scopes.Any(x => string.Equals(x, "api", StringComparison.Ordinal));
24+
})
1725
.Build();
1826
});
1927
builder.Services.AddTransient<SecuredService>();

Scenarios/Authentication/Minimal-machine-to-machine-using-JWT/Service/SecuredService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Microsoft.AspNetCore.Authorization;
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.AspNetCore.Authorization;
25
using Microsoft.AspNetCore.Mvc;
36

47
namespace Service

0 commit comments

Comments
 (0)