Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for IsAuthenticated in addition to Succeeded when calling AuthenticateAsync #1353

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/IdentityServer/Services/Default/DefaultUserSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected virtual async Task AuthenticateAsync()
}

var result = await handler.AuthenticateAsync();
if (result != null && result.Succeeded)
if (result != null && result.Succeeded && result.Principal.Identity.IsAuthenticated)
{
Principal = result.Principal;
Properties = result.Properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,23 @@ public async Task adding_client_should_set_item_in_cookie_properties()
}

[Fact]
public async Task when_authenticated_GetIdentityServerUserAsync_should_should_return_authenticated_user()
public async Task when_handler_successful_GetIdentityServerUserAsync_should_should_return_authenticated_user()
{
_mockAuthenticationHandler.Result = AuthenticateResult.Success(new AuthenticationTicket(_user, _props, "scheme"));

var user = await _subject.GetUserAsync();
user.GetSubjectId().Should().Be("123");
}

[Fact]
public async Task when_handler_successful_and_identity_is_anonymous_GetIdentityServerUserAsync_should_should_return_null()
{
var cp = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim("xoxo", "1") }));
_mockAuthenticationHandler.Result = AuthenticateResult.Success(new AuthenticationTicket(cp, _props, "scheme"));

var user = await _subject.GetUserAsync();
user.Should().BeNull();
}

[Fact]
public async Task when_anonymous_GetIdentityServerUserAsync_should_should_return_null()
Expand Down