Skip to content

Commit

Permalink
chore: fix failed dev re-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
HarrisonHough committed Oct 10, 2024
1 parent cb1924c commit be1dea7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "Auth/DeveloperTokenAuthStrategy.h"

#include "RpmNextGen.h"
#include "Auth/DevAuthTokenCache.h"
#include "Api/Auth/Models/RefreshTokenRequest.h"
Expand Down Expand Up @@ -27,12 +26,12 @@ void DeveloperTokenAuthStrategy::AddAuthToRequest(TSharedPtr<FApiRequest> ApiReq
ApiRequest->Headers.Remove(Key);
}
ApiRequest->Headers.Add(Key, FString::Printf(TEXT("Bearer %s"), *Token));

OnAuthComplete.ExecuteIfBound(ApiRequest, true);
}

void DeveloperTokenAuthStrategy::TryRefresh(TSharedPtr<FApiRequest> ApiRequest)
{
ApiRequestToRetry = ApiRequest;
FRefreshTokenRequest RefreshRequest;
RefreshRequest.Data.Token = FDevAuthTokenCache::GetAuthData().Token;
RefreshRequest.Data.RefreshToken = FDevAuthTokenCache::GetAuthData().RefreshToken;
Expand All @@ -47,14 +46,12 @@ void DeveloperTokenAuthStrategy::OnRefreshTokenResponse(TSharedPtr<FApiRequest>
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -57,12 +57,16 @@ void FDeveloperAccountApi::HandleAppListResponse(TSharedPtr<FApiRequest> ApiRequ
void FDeveloperAccountApi::HandleOrgListResponse(TSharedPtr<FApiRequest> 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);
}

Expand Down
16 changes: 13 additions & 3 deletions Source/RpmNextGenEditor/Private/UI/SRpmDeveloperLoginWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class RPMNEXTGENEDITOR_API DeveloperTokenAuthStrategy : public IAuthenticationSt

private:
TSharedPtr<FAuthApi> AuthApi;

void RefreshTokenAsync(const FRefreshTokenRequest& Request);
TSharedPtr<FApiRequest> ApiRequestToRetry;
void RefreshTokenAsync(const FRefreshTokenRequest& RefreshRequest);
};

0 comments on commit be1dea7

Please sign in to comment.