From be1dea73cc3f1fa23fdeed8e2b41833faaa4e145 Mon Sep 17 00:00:00 2001 From: Harrison Hough Date: Thu, 10 Oct 2024 14:40:39 +0300 Subject: [PATCH] chore: fix failed dev re-auth --- .../Private/Auth/DeveloperTokenAuthStrategy.cpp | 9 +++------ .../DeveloperAccounts/DeveloperAccountApi.cpp | 14 +++++++++----- .../Private/UI/SRpmDeveloperLoginWidget.cpp | 16 +++++++++++++--- .../Public/Auth/DeveloperTokenAuthStrategy.h | 4 ++-- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Source/RpmNextGenEditor/Private/Auth/DeveloperTokenAuthStrategy.cpp b/Source/RpmNextGenEditor/Private/Auth/DeveloperTokenAuthStrategy.cpp index 7020d4f..7e00f8c 100644 --- a/Source/RpmNextGenEditor/Private/Auth/DeveloperTokenAuthStrategy.cpp +++ b/Source/RpmNextGenEditor/Private/Auth/DeveloperTokenAuthStrategy.cpp @@ -1,5 +1,4 @@ #include "Auth/DeveloperTokenAuthStrategy.h" - #include "RpmNextGen.h" #include "Auth/DevAuthTokenCache.h" #include "Api/Auth/Models/RefreshTokenRequest.h" @@ -27,12 +26,12 @@ void DeveloperTokenAuthStrategy::AddAuthToRequest(TSharedPtr ApiReq ApiRequest->Headers.Remove(Key); } ApiRequest->Headers.Add(Key, FString::Printf(TEXT("Bearer %s"), *Token)); - OnAuthComplete.ExecuteIfBound(ApiRequest, true); } void DeveloperTokenAuthStrategy::TryRefresh(TSharedPtr ApiRequest) { + ApiRequestToRetry = ApiRequest; FRefreshTokenRequest RefreshRequest; RefreshRequest.Data.Token = FDevAuthTokenCache::GetAuthData().Token; RefreshRequest.Data.RefreshToken = FDevAuthTokenCache::GetAuthData().RefreshToken; @@ -47,14 +46,12 @@ void DeveloperTokenAuthStrategy::OnRefreshTokenResponse(TSharedPtr DeveloperAuth.Token = Response.Data.Token; DeveloperAuth.RefreshToken = Response.Data.RefreshToken; FDevAuthTokenCache::SetAuthData(DeveloperAuth); - OnTokenRefreshed.ExecuteIfBound(Request, Response.Data, true); + OnTokenRefreshed.ExecuteIfBound(ApiRequestToRetry, Response.Data, true); return; } - UE_LOG(LogReadyPlayerMe, Error, TEXT("Failed to refresh token")); - OnTokenRefreshed.ExecuteIfBound(Request, Response.Data, false); + OnTokenRefreshed.ExecuteIfBound(ApiRequestToRetry, Response.Data, false); } - void DeveloperTokenAuthStrategy::RefreshTokenAsync(const FRefreshTokenRequest& Request) { AuthApi->RefreshToken(Request); diff --git a/Source/RpmNextGenEditor/Private/DeveloperAccounts/DeveloperAccountApi.cpp b/Source/RpmNextGenEditor/Private/DeveloperAccounts/DeveloperAccountApi.cpp index 966a1da..a77703d 100644 --- a/Source/RpmNextGenEditor/Private/DeveloperAccounts/DeveloperAccountApi.cpp +++ b/Source/RpmNextGenEditor/Private/DeveloperAccounts/DeveloperAccountApi.cpp @@ -1,4 +1,4 @@ -#include "DeveloperAccounts/DeveloperAccountApi.h" +#include "DeveloperAccounts/DeveloperAccountApi.h" #include "JsonObjectConverter.h" #include "DeveloperAccounts/Models/ApplicationListRequest.h" #include "DeveloperAccounts/Models/ApplicationListResponse.h" @@ -57,12 +57,16 @@ void FDeveloperAccountApi::HandleAppListResponse(TSharedPtr ApiRequ void FDeveloperAccountApi::HandleOrgListResponse(TSharedPtr ApiRequest, FHttpResponsePtr Response, bool bWasSuccessful) { FOrganizationListResponse OrganizationListResponse; - FString Data = Response->GetContentAsString(); - if (bWasSuccessful && !Data.IsEmpty() && FJsonObjectConverter::JsonObjectStringToUStruct(Data, &OrganizationListResponse, 0, 0)) + if(Response.IsValid()) { - OnOrganizationResponse.ExecuteIfBound(OrganizationListResponse, true); - return; + FString Data = Response->GetContentAsString(); + if (bWasSuccessful && !Data.IsEmpty() && FJsonObjectConverter::JsonObjectStringToUStruct(Data, &OrganizationListResponse, 0, 0)) + { + OnOrganizationResponse.ExecuteIfBound(OrganizationListResponse, true); + return; + } } + OnOrganizationResponse.ExecuteIfBound(OrganizationListResponse, false); } diff --git a/Source/RpmNextGenEditor/Private/UI/SRpmDeveloperLoginWidget.cpp b/Source/RpmNextGenEditor/Private/UI/SRpmDeveloperLoginWidget.cpp index 4df4186..1cf83b3 100644 --- a/Source/RpmNextGenEditor/Private/UI/SRpmDeveloperLoginWidget.cpp +++ b/Source/RpmNextGenEditor/Private/UI/SRpmDeveloperLoginWidget.cpp @@ -27,9 +27,19 @@ BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION void SRpmDeveloperLoginWidget::Construct(const FArguments& InArgs) { FDeveloperAuth AuthData = FDevAuthTokenCache::GetAuthData(); - FDevAuthTokenCache::SetAuthData(AuthData); - bIsLoggedIn = AuthData.IsValid(); - UserName = AuthData.Name; + + bIsLoggedIn = false; + if(AuthData.IsValid()) + { + FDevAuthTokenCache::SetAuthData(AuthData); + bIsLoggedIn = AuthData.IsValid(); + UserName = AuthData.Name; + } + else + { + UserName = "User"; + FDevAuthTokenCache::ClearAuthData(); + } ChildSlot [ diff --git a/Source/RpmNextGenEditor/Public/Auth/DeveloperTokenAuthStrategy.h b/Source/RpmNextGenEditor/Public/Auth/DeveloperTokenAuthStrategy.h index 0fe693d..ee8d857 100644 --- a/Source/RpmNextGenEditor/Public/Auth/DeveloperTokenAuthStrategy.h +++ b/Source/RpmNextGenEditor/Public/Auth/DeveloperTokenAuthStrategy.h @@ -17,6 +17,6 @@ class RPMNEXTGENEDITOR_API DeveloperTokenAuthStrategy : public IAuthenticationSt private: TSharedPtr AuthApi; - - void RefreshTokenAsync(const FRefreshTokenRequest& Request); + TSharedPtr ApiRequestToRetry; + void RefreshTokenAsync(const FRefreshTokenRequest& RefreshRequest); };