Skip to content

Commit 7dc96f8

Browse files
Merge pull request #246 from 0xsequence/jd/playfab_session_tickets
session tickets
2 parents 195fd07 + 2defb69 commit 7dc96f8

7 files changed

Lines changed: 91 additions & 42 deletions

File tree

Plugins/SequencePlugin/Source/SequencePlugin/Private/Integrators/SequenceSessionsBP.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,7 @@ void USequenceSessionsBP::PlayFabLoginAsync(const FString& UsernameIn, const FSt
141141
{
142142
const TSuccessCallback<FString> OnSuccess = [this](const FString& SessionTicket)
143143
{
144-
const TSuccessCallback<FCredentials_BE> OnOpenSuccess = [this](const FCredentials_BE& Credentials)
145-
{
146-
this->StartSession(Credentials);
147-
};
148-
149-
const FFailureCallback OnOpenFailure = [this](const FSequenceError& Error)
150-
{
151-
SEQ_LOG(Error, TEXT("Error: %s"), *Error.Message);
152-
this->CallSessionCreationFailure();
153-
};
154-
155-
const TFunction<void (FFederationSupportData)> OnFederationRequired = [this](const FFederationSupportData& FederationData)
156-
{
157-
SEQ_LOG(Error, TEXT("Account Force Create Or Federation Required"));
158-
this->CallFederationRequired(FederationData);
159-
};
160-
161-
this->ClearSession();
162-
this->RPCManager->OpenPlayFabSession(SessionTicket, true, OnOpenSuccess, OnOpenFailure, OnFederationRequired);
144+
PlayfabAuthenticateWithSessionTicketAsync(SessionTicket);
163145
};
164146

165147
const FFailureCallback OnFailure = [this](const FSequenceError& Error)
@@ -184,6 +166,29 @@ void USequenceSessionsBP::PlayFabLoginAsync(const FString& UsernameIn, const FSt
184166
this->PlayFabLoginRpcAsync(UsernameIn, PasswordIn, OnSuccess, OnFailure);
185167
}
186168

169+
void USequenceSessionsBP::PlayfabAuthenticateWithSessionTicketAsync(const FString& SessionTicket)
170+
{
171+
const TSuccessCallback<FCredentials_BE> OnOpenSuccess = [this](const FCredentials_BE& Credentials)
172+
{
173+
this->StartSession(Credentials);
174+
};
175+
176+
const FFailureCallback OnOpenFailure = [this](const FSequenceError& Error)
177+
{
178+
SEQ_LOG(Error, TEXT("Error: %s"), *Error.Message);
179+
this->CallSessionCreationFailure();
180+
};
181+
182+
const TFunction<void (FFederationSupportData)> OnFederationRequired = [this](const FFederationSupportData& FederationData)
183+
{
184+
SEQ_LOG(Error, TEXT("Account Force Create Or Federation Required"));
185+
this->CallFederationRequired(FederationData);
186+
};
187+
188+
this->ClearSession();
189+
this->RPCManager->OpenPlayFabSession(SessionTicket, true, OnOpenSuccess, OnOpenFailure, OnFederationRequired);
190+
}
191+
187192
void USequenceSessionsBP::StartGuestSessionAsync()
188193
{
189194
const TSuccessCallback<FCredentials_BE> OnSuccess = [this](const FCredentials_BE& Credentials)

Plugins/SequencePlugin/Source/SequencePlugin/Private/SequenceAuthenticator.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,31 @@ void USequenceAuthenticator::CheckAndFederateSessionInUse()
153153
}
154154
}
155155

156+
void USequenceAuthenticator::AuthenticateUsingPlayfabSessionTicket(const FString& SessionTicket, const bool ForceCreateAccountIn)
157+
{
158+
const TSuccessCallback<FCredentials_BE> OnOpenSuccess = [this](const FCredentials_BE& Credentials)
159+
{
160+
this->InitializeSequence(Credentials);
161+
this->CheckAndFederateSessionInUse();
162+
};
163+
164+
const FFailureCallback OnOpenFailure = [this](const FSequenceError& Error)
165+
{
166+
UE_LOG(LogTemp, Warning, TEXT("Error: %s"), *Error.Message);
167+
this->ResetFederateSessionInUse();
168+
this->CallAuthFailure(Error.Message);
169+
};
170+
171+
const TFunction<void (FFederationSupportData)> OnFederationRequired = [this](const FFederationSupportData& FederationData)
172+
{
173+
UE_LOG(LogTemp, Warning, TEXT("Account Force Create Or Federation Required"));
174+
this->SetIsFederatingSessionInUse();
175+
this->CallFederateOrForce(FederationData);
176+
};
177+
178+
this->SequenceRPCManager->OpenPlayFabSession(SessionTicket,ForceCreateAccountIn, OnOpenSuccess, OnOpenFailure, OnFederationRequired);
179+
}
180+
156181
void USequenceAuthenticator::ResetFederateSessionInUse()
157182
{
158183
this->IsFederatingSessionInUse = false;
@@ -480,27 +505,7 @@ void USequenceAuthenticator::PlayFabLogin(const FString& UsernameIn, const FStri
480505

481506
const TSuccessCallback<FString> OnSuccess = [this, ForceCreateAccountIn](const FString& SessionTicket)
482507
{
483-
const TSuccessCallback<FCredentials_BE> OnOpenSuccess = [this](const FCredentials_BE& Credentials)
484-
{
485-
this->InitializeSequence(Credentials);
486-
this->CheckAndFederateSessionInUse();
487-
};
488-
489-
const FFailureCallback OnOpenFailure = [this](const FSequenceError& Error)
490-
{
491-
UE_LOG(LogTemp, Warning, TEXT("Error: %s"), *Error.Message);
492-
this->ResetFederateSessionInUse();
493-
this->CallAuthFailure(Error.Message);
494-
};
495-
496-
const TFunction<void (FFederationSupportData)> OnFederationRequired = [this](const FFederationSupportData& FederationData)
497-
{
498-
UE_LOG(LogTemp, Warning, TEXT("Account Force Create Or Federation Required"));
499-
this->SetIsFederatingSessionInUse();
500-
this->CallFederateOrForce(FederationData);
501-
};
502-
503-
this->SequenceRPCManager->OpenPlayFabSession(SessionTicket,ForceCreateAccountIn, OnOpenSuccess, OnOpenFailure, OnFederationRequired);
508+
this->AuthenticateUsingPlayfabSessionTicket(SessionTicket, ForceCreateAccountIn);
504509
};
505510

506511
const FFailureCallback OnFailure = [this](const FSequenceError& Error)
@@ -512,6 +517,11 @@ void USequenceAuthenticator::PlayFabLogin(const FString& UsernameIn, const FStri
512517
this->PlayFabLoginRPC(UsernameIn, PasswordIn, OnSuccess, OnFailure);
513518
}
514519

520+
void USequenceAuthenticator::PlayFabAuthenticateWithSessionTicket(const FString& SessionTicket)
521+
{
522+
AuthenticateUsingPlayfabSessionTicket(SessionTicket, false);
523+
}
524+
515525
FString USequenceAuthenticator::GenerateRedirectURL(const ESocialSigninType& Type) const
516526
{
517527
FString RedirectUrl = this->BuildRedirectPrefix() + "&scope=openid+email&state=" + UrlScheme + "---" + this->StateToken + UEnum::GetValueAsString(Type);

Plugins/SequencePlugin/Source/SequencePlugin/Private/SequenceBackendManager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ void ASequenceBackendManager::PlayFabRegisterAndLogin(const FString& UsernameIn,
166166
}
167167
}
168168

169+
void ASequenceBackendManager::PlayfabAuthenticateWithSessionTicket(const FString& SessionTicket)
170+
{
171+
if (this->Authenticator)
172+
{
173+
this->Authenticator->PlayFabAuthenticateWithSessionTicket(SessionTicket);
174+
}
175+
}
176+
169177
void ASequenceBackendManager::FederateEmail(const FString& EmailIn) const
170178
{
171179
if (this->Authenticator)

Plugins/SequencePlugin/Source/SequencePlugin/Private/SequenceBackendManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class SEQUENCEPLUGIN_API ASequenceBackendManager : public AActor
9696

9797
UFUNCTION(BlueprintCallable, CATEGORY = "Login")
9898
void PlayFabRegisterAndLogin(const FString& UsernameIn, const FString& EmailIn, const FString& PasswordIn, const bool ForceCreateAccountIn);
99+
100+
UFUNCTION(BlueprintCallable, Category = "Login")
101+
void PlayfabAuthenticateWithSessionTicket(const FString& SessionTicket);
99102

100103
UFUNCTION(BlueprintCallable, CATEGORY = "Federation")
101104
void FederateEmail(const FString& EmailIn) const;

Plugins/SequencePlugin/Source/SequencePlugin/Public/Integrators/SequenceSessionsBP.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class SEQUENCEPLUGIN_API USequenceSessionsBP : public UGameInstanceSubsystem, pu
7575
UFUNCTION(BlueprintCallable, Category="0xSequence SDK - Functions")
7676
void PlayFabLoginAsync(const FString& UsernameIn, const FString& PasswordIn);
7777

78+
UFUNCTION(BlueprintCallable, Category="0xSequence SDK - Functions")
79+
void PlayfabAuthenticateWithSessionTicketAsync(const FString& SessionTicket);
80+
7881
UFUNCTION(BlueprintCallable, Category="0xSequence SDK - Functions")
7982
void StartGuestSessionAsync();
8083

Plugins/SequencePlugin/Source/SequencePlugin/Public/SequenceAuthenticator.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ class SEQUENCEPLUGIN_API USequenceAuthenticator : public UObject, public INative
180180
* If IsFederatingSessionInUse = false, we operate as normal
181181
*/
182182
void CheckAndFederateSessionInUse();
183+
184+
/**
185+
* Authenticates using a PlayFab Session Ticket
186+
* @param SessionTicket Session Ticket to authenticate with
187+
* @param ForceCreateAccountIn Force create account if it already exists
188+
*/
189+
void AuthenticateUsingPlayfabSessionTicket(const FString& SessionTicket, const bool ForceCreateAccountIn);
183190
public:
184191

185192
/**
@@ -258,6 +265,12 @@ class SEQUENCEPLUGIN_API USequenceAuthenticator : public UObject, public INative
258265
*/
259266
void PlayFabLogin(const FString& UsernameIn, const FString& PasswordIn, const bool ForceCreateAccountIn);
260267

268+
/**
269+
* Used to authenticate using a Session Ticket
270+
* @param SessionTicket Session Ticket to login with
271+
*/
272+
void PlayFabAuthenticateWithSessionTicket(const FString& SessionTicket);
273+
261274
/**
262275
* Used to complete Email based authentication, whether it be for normal Authentication OR Federation
263276
* @param CodeIn Received Code from email
@@ -333,7 +346,7 @@ class SEQUENCEPLUGIN_API USequenceAuthenticator : public UObject, public INative
333346
* Override to handle Id Token received from NativeOAuth.h
334347
*/
335348
virtual void HandleNativeIdToken(const FString& IdToken) override;
336-
349+
337350
private:
338351

339352
FString BuildRedirectPrefix() const;
@@ -366,7 +379,7 @@ class SEQUENCEPLUGIN_API USequenceAuthenticator : public UObject, public INative
366379
* @param OnFailure Called when unsuccessful (returns error)
367380
*/
368381
static void PlayFabNewAccountLoginRPC(const FString& UsernameIn, const FString& EmailIn, const FString& PasswordIn, const TSuccessCallback<FString>& OnSuccess, const FFailureCallback& OnFailure);
369-
382+
370383
static FString GeneratePlayFabUrl();
371384

372385
static FString GeneratePlayFabRegisterUrl();

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ In a C++ UObject with a series of pass through **[UFUNCTIONS]** setup similarly
278278
*/
279279
void PlayFabLogin(const FString& UsernameIn, const FString& PasswordIn, const bool ForceCreateAccountIn);
280280
281+
/**
282+
* Used to authenticate using a Session Ticket
283+
* @param SessionTicket Session Ticket to login with
284+
*/
285+
void PlayfabAuthenticateWithSessionTicket(const FString& SessionTicket);
286+
281287
/**
282288
* Used to complete Email based authentication, whether it be for normal Authentication OR Federation
283289
* @param CodeIn Received Code from email
@@ -401,6 +407,7 @@ else
401407
### PlayFab Social Signin based Authentication with CustomUI
402408
1) Start by calling either PlayFabLogin (Login With Existing)
403409
or PlayFabRegisterAndLogin (Create a new PlayFab account & Login with it) that's it.
410+
or PlayfabAuthenticateWithSessionTicket (Authenticate with a PlayFab Session Ticket)
404411

405412
### Guest Login with CustomUI
406413
1) Start by calling GuestLogin, and that's it.

0 commit comments

Comments
 (0)