I3DHAuthHandler.h Source File

instant3Dhub: I3DHAuthHandler.h Source File
instant3Dhub
I3DHAuthHandler.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "GameFramework/Actor.h"
9
10#include "I3DHAuthHandler.generated.h"
11
13USTRUCT(BlueprintType)
15{
16 GENERATED_BODY()
17
19 {
20 }
21
22 FI3DHAuthError(const FString& UserMessage)
23 : UserMessage(UserMessage)
24 {
25 }
26
28 UPROPERTY(BlueprintReadWrite, Category = "{instant3DhubAuth}")
29 FString UserMessage;
30};
31
33DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FI3DHAuthSuccessDelegate, FString, AccessToken, bool, WasRefresh);
35DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FI3DHAuthFailureDelegate, const FI3DHAuthError&, Error, bool, WasRefresh);
36
37class FI3DHAuthServer;
38class IHttpRequest;
39class FJsonObject;
40
49UCLASS(ClassGroup="instant3Dhub")
50class INSTANT3DHUBAUTH_API AI3DHAuthHandler : public AActor
51{
52 friend class FI3DHAuthServer;
53
54 GENERATED_BODY()
55
57
58public:
59 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
60
61
62public:
63 // Core API:
64
74 UFUNCTION(BlueprintCallable, Category = "{instant3DhubAuth}")
75 void Init(const FString& ClientId, const FString& Scope, const FString& AuthorizationUrl, const FString& TokenUrl);
76
83 UFUNCTION(BlueprintCallable, Category = "{instant3DhubAuth}")
84 void Start();
85
91 UFUNCTION(BlueprintCallable, Category = "{instant3DhubAuth}")
92 void Reset();
93
94
95private:
97 void RefreshTimerCallback();
98 void HandleTokenResponse(const TSharedPtr<FJsonObject>& JsonObject, bool WasRefresh);
99
101
102 // Note on thread safety: All variables are intended to be accessed from the
103 // game thread only. Access from other threads will require additional
104 // synchronization.
105
106private:
107 // Basic OAuth 2.0 configuration:
108
109 FString ClientId;
110 FString Scope;
111 FString AuthorizationUrl;
112 FString TokenUrl;
113
114public:
123 UPROPERTY(BlueprintReadWrite, Category = "{instant3DhubAuth}")
124 FString SuccessRedirectUrl;
125
127 UPROPERTY(BlueprintReadWrite, Category = "{instant3DhubAuth}")
128 FString SuccessHtmlResponse;
129
131 UPROPERTY(BlueprintReadWrite, Category = "{instant3DhubAuth}")
132 FString ErrorRedirectUrl;
133
135 UPROPERTY(BlueprintReadWrite, Category = "{instant3DhubAuth}")
136 FString ErrorHtmlResponse;
137
140public:
154 UPROPERTY(BlueprintAssignable, Category = "{instant3DhubAuth}")
155 FI3DHAuthSuccessDelegate Succeeded;
156
158 UPROPERTY(BlueprintAssignable, Category = "{instant3DhubAuth}")
159 FI3DHAuthFailureDelegate Failed;
160
163private:
164 // Internal state:
165
166 TSharedPtr<FI3DHAuthServer> Server;
167 TSharedPtr<IHttpRequest> TokenRequest;
168
169 FString RefreshToken;
170 FTimerHandle RefreshTimer;
171};
DECLARE_DYNAMIC_MULTICAST_DELEGATE void FI3DHAuthFailureDelegate(const FI3DHAuthError &Error, bool WasRefresh)
AuthFailure Delegate Type.
DECLARE_DYNAMIC_MULTICAST_DELEGATE void FI3DHAuthSuccessDelegate(FString AccessToken, bool WasRefresh)
AuthSuccess Delegate Type.
@ Error
Indicates a general error that doesn't match any of the specific ones.
Implements OAuth 2.0 authorization including token refresh.
Definition I3DHAuthHandler.h:51
Authentication Error with a UserMessage.
Definition I3DHAuthHandler.h:15