mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Entry list - Show icons
Workshop search - Show icons, update design
This commit is contained in:
1 parent
176a28761f
commit
77bed1bf94
13 files changed
+273
-76
No files matched your search
@@ -4,6 +4,7 @@ query SearchEntries($input: String! $type: EntryType) {
|
||||
name
|
||||
summary
|
||||
entryType
|
||||
author
|
||||
categories {
|
||||
id
|
||||
name
|
||||
|
||||
@@ -11,6 +11,7 @@ using Artemis.WebClient.Workshop.Repositories;
|
||||
using DynamicData;
|
||||
using IdentityModel;
|
||||
using IdentityModel.Client;
|
||||
using Serilog;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Services;
|
||||
|
||||
@@ -22,14 +23,16 @@ internal class AuthenticationService : CorePropertyChanged, IAuthenticationServi
|
||||
private readonly SourceList<Claim> _claims;
|
||||
|
||||
private readonly IDiscoveryCache _discoveryCache;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly BehaviorSubject<bool> _isLoggedInSubject = new(false);
|
||||
|
||||
private AuthenticationToken? _token;
|
||||
private bool _noStoredRefreshToken;
|
||||
|
||||
public AuthenticationService(IHttpClientFactory httpClientFactory, IDiscoveryCache discoveryCache, IAuthenticationRepository authenticationRepository)
|
||||
public AuthenticationService(ILogger logger, IHttpClientFactory httpClientFactory, IDiscoveryCache discoveryCache, IAuthenticationRepository authenticationRepository)
|
||||
{
|
||||
_logger = logger;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_discoveryCache = discoveryCache;
|
||||
_authenticationRepository = authenticationRepository;
|
||||
@@ -69,28 +72,37 @@ internal class AuthenticationService : CorePropertyChanged, IAuthenticationServi
|
||||
|
||||
private async Task<bool> UseRefreshToken(string refreshToken)
|
||||
{
|
||||
DiscoveryDocumentResponse disco = await GetDiscovery();
|
||||
HttpClient client = _httpClientFactory.CreateClient();
|
||||
TokenResponse response = await client.RequestRefreshTokenAsync(new RefreshTokenRequest
|
||||
try
|
||||
{
|
||||
Address = disco.TokenEndpoint,
|
||||
ClientId = CLIENT_ID,
|
||||
RefreshToken = refreshToken
|
||||
});
|
||||
|
||||
if (response.IsError)
|
||||
{
|
||||
if (response.Error is OidcConstants.TokenErrors.ExpiredToken or OidcConstants.TokenErrors.InvalidGrant)
|
||||
DiscoveryDocumentResponse disco = await GetDiscovery();
|
||||
HttpClient client = _httpClientFactory.CreateClient();
|
||||
TokenResponse response = await client.RequestRefreshTokenAsync(new RefreshTokenRequest
|
||||
{
|
||||
SetStoredRefreshToken(null);
|
||||
return false;
|
||||
Address = disco.TokenEndpoint,
|
||||
ClientId = CLIENT_ID,
|
||||
RefreshToken = refreshToken
|
||||
});
|
||||
|
||||
if (response.IsError)
|
||||
{
|
||||
if (response.Error is OidcConstants.TokenErrors.ExpiredToken or OidcConstants.TokenErrors.InvalidGrant)
|
||||
{
|
||||
SetStoredRefreshToken(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new ArtemisWebClientException("Failed to request refresh token: " + response.Error);
|
||||
}
|
||||
|
||||
throw new ArtemisWebClientException("Failed to request refresh token: " + response.Error);
|
||||
SetCurrentUser(response);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(e, "Failed to use refresh token");
|
||||
SetStoredRefreshToken(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
SetCurrentUser(response);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static byte[] HashSha256(string inputString)
|
||||
@@ -134,6 +146,11 @@ internal class AuthenticationService : CorePropertyChanged, IAuthenticationServi
|
||||
|
||||
return _token.AccessToken;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(e, "Failed to retrieve bearer token");
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_authLock.Release();
|
||||
|
||||
Reference in new issue
Block a user