6
6
7
7
using System ;
8
8
using System . IdentityModel . Tokens . Jwt ;
9
- using System . Security . Claims ;
10
9
using System . Threading . Tasks ;
11
- using AspNet . Security . OAuth . SuperOffice ;
12
10
using Microsoft . AspNetCore . Authentication ;
13
- using Microsoft . AspNetCore . Http ;
14
11
using Microsoft . Extensions . DependencyInjection ;
15
12
using Microsoft . IdentityModel . Tokens ;
13
+ using Shouldly ;
16
14
using Xunit ;
17
15
using Xunit . Abstractions ;
18
16
@@ -29,9 +27,14 @@ public SuperOfficeTests(ITestOutputHelper outputHelper)
29
27
30
28
protected internal override void RegisterAuthentication ( AuthenticationBuilder builder )
31
29
{
30
+ Microsoft . IdentityModel . Logging . IdentityModelEventSource . ShowPII = true ;
31
+
32
32
builder . AddSuperOffice ( options =>
33
33
{
34
34
ConfigureDefaults ( builder , options ) ;
35
+
36
+ options . ClientId = "gg454918d75b1b53101065c16ee51123" ;
37
+ options . TokenValidationParameters . ValidAudience = options . ClientId ;
35
38
} ) ;
36
39
}
37
40
@@ -52,13 +55,7 @@ public async Task Can_Sign_In_Using_SuperOffice(string claimType, string claimVa
52
55
// Arrange
53
56
static void ConfigureServices ( IServiceCollection services )
54
57
{
55
- Microsoft . IdentityModel . Logging . IdentityModelEventSource . ShowPII = true ;
56
- services . AddSingleton < JwtSecurityTokenHandler , MockJwtSecurityTokenHandler > ( ) ;
57
- services . PostConfigureAll < SuperOfficeAuthenticationOptions > ( ( options ) =>
58
- {
59
- options . ClientId = "gg454918d75b1b53101065c16ee51123" ;
60
- options . TokenValidationParameters . ValidAudience = options . ClientId ;
61
- } ) ;
58
+ services . AddSingleton < JwtSecurityTokenHandler , FrozenJwtSecurityTokenHandler > ( ) ;
62
59
}
63
60
64
61
using var server = CreateTestServer ( ConfigureServices ) ;
@@ -79,12 +76,9 @@ public async Task Can_Sign_In_Using_SuperOffice_With_FunctionRights(string claim
79
76
// Arrange
80
77
static void ConfigureServices ( IServiceCollection services )
81
78
{
82
- Microsoft . IdentityModel . Logging . IdentityModelEventSource . ShowPII = true ;
83
- services . AddSingleton < JwtSecurityTokenHandler , MockJwtSecurityTokenHandler > ( ) ;
79
+ services . AddSingleton < JwtSecurityTokenHandler , FrozenJwtSecurityTokenHandler > ( ) ;
84
80
services . PostConfigureAll < SuperOfficeAuthenticationOptions > ( ( options ) =>
85
81
{
86
- options . ClientId = "gg454918d75b1b53101065c16ee51123" ;
87
- options . TokenValidationParameters . ValidAudience = options . ClientId ;
88
82
options . IncludeFunctionalRightsAsClaims = true ;
89
83
} ) ;
90
84
}
@@ -97,13 +91,5 @@ static void ConfigureServices(IServiceCollection services)
97
91
// Assert
98
92
AssertClaim ( claims , claimType , claimValue ) ;
99
93
}
100
-
101
- private sealed class MockJwtSecurityTokenHandler : JwtSecurityTokenHandler
102
- {
103
- protected override void ValidateLifetime ( DateTime ? notBefore , DateTime ? expires , JwtSecurityToken jwtToken , TokenValidationParameters validationParameters )
104
- {
105
- // Do not validate the lifetime as the test token has expired
106
- }
107
- }
108
94
}
109
95
}
0 commit comments