Skip to content

Commit 5f02227

Browse files
committed
Validate token expiration is in range
1 parent 21d62d3 commit 5f02227

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Components/Blazor/testassets/Wasm.Authentication.Client/Pages/User.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
@if (AccessToken != null)
2525
{
26-
<h2>Current time: @DateTimeOffset.Now</h2>
2726
<h2>Access token expires</h2>
28-
<p>@AccessToken.Expires</p>
27+
<p>Current time: <span id="current-time">@DateTimeOffset.Now</span></p>
28+
<p id="access-token-expires">@AccessToken.Expires</p>
2929

3030
<h2>Access token granted scopes (as reported by the API)</h2>
3131
@foreach (var scope in AccessToken.GrantedScopes)

src/Components/test/E2ETest/Tests/WebAssemblyAuthenticationTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ public void AuthenticatedUser_ProfileIncludesDetails_And_AccessToken()
158158
"Wasm.Authentication.ServerAPI"
159159
},
160160
payload.Scopes);
161+
162+
var currentTime = DateTimeOffset.Parse(Browser.Exists(By.Id("current-time")).Text);
163+
var tokenExpiration = DateTimeOffset.Parse(Browser.Exists(By.Id("access-token-expires")).Text);
164+
Assert.True(currentTime.AddMinutes(50) < tokenExpiration);
165+
Assert.True(currentTime.AddMinutes(60) >= tokenExpiration);
161166
}
162167

163168
[Fact]

0 commit comments

Comments
 (0)