Skip to content

Commit 0372a4c

Browse files
committed
Fix incorrect authenticate function signature.
1 parent e8455e3 commit 0372a4c

File tree

4 files changed

+78
-68
lines changed

4 files changed

+78
-68
lines changed

Satori/Source/SatoriBlueprints/Private/SatoriClientRequests.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
#include "SatoriClientRequests.h"
22
#include "SatoriUtils.h"
33

4-
USatoriClientAuthenticateCustom* USatoriClientAuthenticateCustom::AuthenticateCustom(
5-
USatoriClient* Client,
6-
const FString& UserID,
7-
const FString& Username,
8-
bool CreateAccount,
9-
const TMap<FString, FString>& Vars)
4+
USatoriClientAuthenticate* USatoriClientAuthenticate::Authenticate(
5+
USatoriClient* Client,
6+
const FString& ID,
7+
const TMap<FString, FString>& DefaultProperties,
8+
const TMap<FString, FString>& CustomProperties,
9+
const bool bNoSession)
1010
{
11-
USatoriClientAuthenticateCustom* Node = NewObject<USatoriClientAuthenticateCustom>();
11+
USatoriClientAuthenticate* Node = NewObject<USatoriClientAuthenticate>();
1212
Node->SatoriClient = Client;
13-
Node->UserID = UserID;
14-
Node->Username = Username;
15-
Node->bCreateAccount = CreateAccount;
16-
Node->Vars = Vars;
13+
Node->ID = ID;
14+
Node->DefaultProperties = DefaultProperties;
15+
Node->CustomProperties = CustomProperties;
16+
Node->bNoSession = bNoSession;
1717

1818
return Node;
1919
}
2020

21-
void USatoriClientAuthenticateCustom::Activate()
21+
void USatoriClientAuthenticate::Activate()
2222
{
2323
if (!SatoriClient)
2424
{
@@ -52,7 +52,7 @@ void USatoriClientAuthenticateCustom::Activate()
5252
SetReadyToDestroy();
5353
};
5454

55-
SatoriClient->AuthenticateCustom(UserID, Username, bCreateAccount, Vars, successCallback, errorCallback);
55+
SatoriClient->Authenticate(ID, DefaultProperties, CustomProperties, bNoSession, successCallback, errorCallback);
5656
}
5757

5858
USatoriClientAuthenticateRefresh* USatoriClientAuthenticateRefresh::AuthenticateRefresh(USatoriClient* Client, USatoriSession* Session)

Satori/Source/SatoriBlueprints/Public/SatoriClientRequests.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "SatoriClientRequests.generated.h"
1111

1212
// Delegates
13-
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnSatoriAuthenticateCustom, USatoriSession*, Session, FSatoriError, Error);
13+
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnSatoriAuthenticate, USatoriSession*, Session, FSatoriError, Error);
1414
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnSatoriAuthenticateRefresh, USatoriSession*, Session, FSatoriError, Error);
1515
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnSatoriAuthenticateLogout, FSatoriError, Error);
1616
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnSatoriIdentify, USatoriSession*, Session, FSatoriError, Error);
@@ -37,7 +37,7 @@ DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnSatoriDeleteMessage, FSatoriError
3737
*/
3838

3939
UCLASS()
40-
class SATORIBLUEPRINTS_API USatoriClientAuthenticateCustom : public UBlueprintAsyncActionBase
40+
class SATORIBLUEPRINTS_API USatoriClientAuthenticate : public UBlueprintAsyncActionBase
4141
{
4242
GENERATED_BODY()
4343

@@ -47,36 +47,36 @@ class SATORIBLUEPRINTS_API USatoriClientAuthenticateCustom : public UBlueprintAs
4747
TObjectPtr<USatoriClient> SatoriClient;
4848

4949
UPROPERTY(BlueprintAssignable)
50-
FOnSatoriAuthenticateCustom OnSuccess;
50+
FOnSatoriAuthenticate OnSuccess;
5151

5252
UPROPERTY(BlueprintAssignable)
53-
FOnSatoriAuthenticateCustom OnError;
53+
FOnSatoriAuthenticate OnError;
5454

5555
/**
56-
* Authenticate a user with a custom id.
57-
* @param Client The Client to use.
58-
* @param UserID A custom identifier usually obtained from an external authentication service.
59-
* @param Username A username used to create the user.
60-
* @param CreateAccount True if the user should be created when authenticated.
61-
* @param Vars Extra information that will be bundled in the session token.
56+
* Authenticate to get a satori session.
57+
* @param ID Must be between eight and 128 characters (inclusive). Must be an alphanumeric string with only underscores and hyphens allowed.
58+
* @param DefaultProperties Optional default properties to update with this call. If not set, properties are left as they are on the server.
59+
* @param CustomProperties Optional custom properties to update with this call. If not set, properties are left as they are on the server.
60+
* @param bNoSession Modifies the request to only create/update an identity without creating a new session. If set to 'true' the response won't include a token and a refresh token.
61+
* @param Success Delegate called upon successful authentication, providing the user session.
62+
* @param Error Delegate called on authentication failure with error details.
6263
*/
6364
UFUNCTION(BlueprintCallable, Category = "Satori|Authentication", meta = (BlueprintInternalUseOnly = "true", AutoCreateRefTerm = "Vars"))
64-
static USatoriClientAuthenticateCustom* AuthenticateCustom(
65+
static USatoriClientAuthenticate* Authenticate(
6566
USatoriClient *Client,
66-
const FString& UserID,
67-
const FString& Username,
68-
bool CreateAccount,
69-
const TMap<FString, FString>& Vars);
67+
const FString& ID,
68+
const TMap<FString, FString>& DefaultProperties,
69+
const TMap<FString, FString>& CustomProperties,
70+
const bool bNoSession);
7071

7172
virtual void Activate() override;
7273

7374
private:
7475

75-
FString UserID;
76-
FString Username;
77-
bool bCreateAccount;
78-
TMap<FString, FString> Vars;
79-
76+
FString ID;
77+
TMap<FString, FString> DefaultProperties;
78+
TMap<FString, FString> CustomProperties;
79+
bool bNoSession;
8080
};
8181

8282

Satori/Source/SatoriUnreal/Private/SatoriClient.cpp

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ USatoriClient* USatoriClient::CreateDefaultClient(
100100
return NewClient;
101101
}
102102

103-
void USatoriClient::AuthenticateCustom(
104-
const FString& UserID,
105-
const FString& Username,
106-
bool CreateAccount,
107-
const TMap<FString, FString>& Vars,
103+
void USatoriClient::Authenticate(
104+
const FString& ID,
105+
const TMap<FString, FString>& DefaultProperties,
106+
const TMap<FString, FString>& CustomProperties,
107+
const bool bNoSession,
108108
FOnSatoriAuthUpdate Success,
109109
FOnSatoriError Error)
110110
{
@@ -127,29 +127,39 @@ void USatoriClient::AuthenticateCustom(
127127
// A custom identifier must contain alphanumeric
128128
// characters with dashesand be between 6 and 128 bytes.
129129

130-
AuthenticateCustom(UserID, Username, CreateAccount, Vars, successCallback, errorCallback);
130+
Authenticate(ID, DefaultProperties, CustomProperties, bNoSession, successCallback, errorCallback);
131131
}
132132

133-
void USatoriClient::AuthenticateCustom(
134-
const FString& CustomId,
135-
const FString& Username,
136-
bool bCreate,
137-
const TMap<FString, FString>& Vars,
133+
void USatoriClient::Authenticate(
134+
const FString& ID,
135+
const TMap<FString, FString>& DefaultProperties,
136+
const TMap<FString, FString>& CustomProperties,
137+
const bool bNoSession,
138138
TFunction<void(USatoriSession* UserSession)> SuccessCallback,
139139
TFunction<void(const FSatoriError& Error)> ErrorCallback)
140140
{
141141
// Setup the endpoint
142142
const FString Endpoint = TEXT("/v1/authenticate");
143143

144-
// Setup the query parameters
145-
TMultiMap<FString, FString> QueryParams;
146-
QueryParams.Add(TEXT("create"), FSatoriUtils::BoolToString(bCreate));
147-
QueryParams.Add(TEXT("username"), FGenericPlatformHttp::UrlEncode(Username));
148-
149144
// Setup the request content
150145
const TSharedPtr<FJsonObject> ContentJson = MakeShared<FJsonObject>();
151-
ContentJson->SetStringField(TEXT("id"), CustomId);
152-
FSatoriUtils::AddVarsToJson(ContentJson, Vars);
146+
147+
ContentJson->SetStringField(TEXT("id"), ID);
148+
ContentJson->SetBoolField(TEXT("no_session"), bNoSession);
149+
150+
TSharedPtr<FJsonObject> DefaultPropertiesJson = MakeShared<FJsonObject>();
151+
for (const TPair<FString, FString>& Pair : DefaultProperties)
152+
{
153+
DefaultPropertiesJson->SetStringField(Pair.Key, Pair.Value);
154+
}
155+
ContentJson->SetObjectField(TEXT("default"), DefaultPropertiesJson);
156+
157+
TSharedPtr<FJsonObject> CustomPropertiesJson = MakeShared<FJsonObject>();
158+
for (const TPair<FString, FString>& Pair : DefaultProperties)
159+
{
160+
CustomPropertiesJson->SetStringField(Pair.Key, Pair.Value);
161+
}
162+
ContentJson->SetObjectField(TEXT("custom"), CustomPropertiesJson);
153163

154164
// Serialize the request content
155165
FString Content;
@@ -161,7 +171,7 @@ void USatoriClient::AuthenticateCustom(
161171
}
162172

163173
// Make the request
164-
const auto HttpRequest = MakeRequest(Endpoint, Content, ESatoriRequestMethod::POST, QueryParams, "");
174+
const auto HttpRequest = MakeRequest(Endpoint, Content, ESatoriRequestMethod::POST, TMultiMap<FString, FString>(), "");
165175

166176
// Set the basic authorization header
167177
FSatoriUtils::SetBasicAuthorizationHeader(HttpRequest, ServerKey);
@@ -347,7 +357,7 @@ void USatoriClient::AuthenticateRefresh(
347357
// Remove the HttpRequest from ActiveRequests
348358
ActiveRequests.Remove(Request);
349359
}
350-
});
360+
});
351361

352362
// Process the request
353363
HttpRequest->ProcessRequest();

Satori/Source/SatoriUnreal/Public/SatoriClient.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,31 @@ class SATORIUNREAL_API USatoriClient : public UObject
130130
// --- Authentication --- //
131131

132132
/**
133-
* Authenticate a user with a custom id.
133+
* Authenticate to get a satori session.
134134
*
135-
* @param UserID A custom identifier usually obtained from an external authentication service.
136-
* @param Username A username used to create the user.
137-
* @param CreateAccount True if the user should be created when authenticated.
138-
* @param Vars Extra information that will be bundled in the session token.
135+
* @param ID Must be between eight and 128 characters (inclusive). Must be an alphanumeric string with only underscores and hyphens allowed.
136+
* @param DefaultProperties Optional default properties to update with this call. If not set, properties are left as they are on the server.
137+
* @param CustomProperties Optional custom properties to update with this call. If not set, properties are left as they are on the server.
138+
* @param bNoSession Modifies the request to only create/update an identity without creating a new session. If set to 'true' the response won't include a token and a refresh token.
139139
* @param Success Delegate called upon successful authentication, providing the user session.
140140
* @param Error Delegate called on authentication failure with error details.
141141
*/
142142

143143
UFUNCTION(Category = "Satori|Authentication")
144-
void AuthenticateCustom(
145-
const FString& UserID,
146-
const FString& Username,
147-
bool CreateAccount,
148-
const TMap<FString, FString>& Vars,
144+
void Authenticate(
145+
const FString& ID,
146+
const TMap<FString, FString>& DefaultProperties,
147+
const TMap<FString, FString>& CustomProperties,
148+
const bool bNoSession,
149149
FOnSatoriAuthUpdate Success,
150150
FOnSatoriError Error
151151
);
152152

153-
void AuthenticateCustom(
154-
const FString& UserID,
155-
const FString& Username,
156-
bool bCreate,
157-
const TMap<FString, FString>& Vars,
153+
void Authenticate(
154+
const FString& ID,
155+
const TMap<FString, FString>& DefaultProperties,
156+
const TMap<FString, FString>& CustomProperties,
157+
const bool bNoSession,
158158
TFunction<void(USatoriSession* UserSession)> SuccessCallback,
159159
TFunction<void(const FSatoriError& Error)> ErrorCallback
160160
);

0 commit comments

Comments
 (0)