Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public virtual async Task<UserSessionSearchResult> SearchAsync(UserSessionSearch

var tokens = await _tokenManager.FindBySubjectAsync(criteria.UserId)
.OfType<VirtoOpenIddictEntityFrameworkCoreToken>()
.Where(x => x.Type == "refresh_token")
.Where(x => x.Status == "valid")
.Where(x => x.Type == OpenIddictConstants.TokenTypeIdentifiers.RefreshToken)
.Where(x => x.Status == OpenIddictConstants.Statuses.Valid)
.OrderByDescending(x => x.CreationDate)
.ToListAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public virtual async Task TerminateUserSession(string sessionId)
{
var validSessionsCount = await _tokenManager.FindByAuthorizationIdAsync(authorizationId)
.OfType<VirtoOpenIddictEntityFrameworkCoreToken>()
.Where(x => x.Type == "refresh_token")
.Where(x => x.Status == "valid")
.Where(x => x.Type == OpenIddictConstants.TokenTypeIdentifiers.RefreshToken)
.Where(x => x.Status == OpenIddictConstants.Statuses.Valid)
.CountAsync();

if (validSessionsCount == 0)
Expand Down
7 changes: 5 additions & 2 deletions src/VirtoCommerce.Platform.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,6 @@ public void ConfigureServices(IServiceCollection services)
services.AddOptions<Core.Security.AuthorizationOptions>().Bind(Configuration.GetSection("Authorization")).ValidateDataAnnotations();
var authorizationOptions = Configuration.GetSection("Authorization").Get<Core.Security.AuthorizationOptions>();

services.AddScoped<IOpenIddictTokenStore<VirtoOpenIddictEntityFrameworkCoreToken>, VirtoOpenIddictEntityFrameworkCoreTokenStore>();

// Register the OpenIddict services.
// Note: use the generic overload if you need
// to replace the default OpenIddict entities.
Expand Down Expand Up @@ -453,6 +451,11 @@ public void ConfigureServices(IServiceCollection services)
});
});

// Override the default OpenIddict EF Core token store with our custom implementation
// that captures IpAddress and UserAgent during token creation.
// Must be registered AFTER AddOpenIddict() so it overrides the default store.
services.AddScoped<IOpenIddictTokenStore<VirtoOpenIddictEntityFrameworkCoreToken>, VirtoOpenIddictEntityFrameworkCoreTokenStore>();

services.AddSingleton<Func<IOpenIddictTokenManager>>(provider =>
() => provider.CreateScope().ServiceProvider.GetRequiredService<IOpenIddictTokenManager>());

Expand Down
Loading