Welcome to the setup guide for 'Authentication for Patreon'. This tool integrates OAuth services into Unity projects, specifically designed to work with Patreon's API version 2. This guide provides straightforward, step-by-step instructions for both initial setup and advanced configurations.
To verify correct extraction, in Unity go to Tools > Authentication for Patreon > Setup Assistant and click "Verify Backend Folder".
Find the extracted Backend folder on your desktop. Key files include:
The Authentication for Patreon system supports offline authentication, allowing users to access the app for a specified number of days without an internet connection. This feature can be enabled and configured in the Patreon Integration script settings.
Namespace: MSCreativeTech.AuthenticationForPatreon
Description: Handles the integration between your Unity application and Patreon.
- Instance: Singleton instance of the class. - _isAuthenticated: (Private, Serialized) Flag indicating if the user is authenticated. - IsAuthenticated: (Public) Property to get or privately set _isAuthenticated. - MemberId: (Public) The ID of the authenticated Patreon member. - patreonAuthCode: (Private) Authorization code received from Patreon. - isAuthenticationInProgress: (Private) Flag for authentication in progress. - encryptedClientID, encryptedClientIDAesKey, encryptedClientIDAesIV, patreonClientID: (Private, Serialized) Encryption and decryption details for the client ID. - patreonTiers: (Private, Serialized) List of Patreon tiers. - _tierIndex, tierIndex: (Private) Current Patreon tier index of the user. - logoutScene: (Private, Serialized) Scene to load upon logout. - _memberId: (Private) Member details. - allowAccessWithNoTier: (Serialized) Allow access even if the user doesn't belong to any valid tier. - enableOfflineAuthentication: (Serialized) Toggle to enable or disable offline authentication. - isAuthenticatedViaTimecode: (Private) Flag indicating if the user is authenticated via offline timecode. - enableRateLimiting: (Serialized) Enable or disable rate limiting for the authentication process. - maxRequestsPerHour: (Serialized) The maximum number of authentication requests allowed per hour. - enableDebugLogs: (Serialized) Toggle to enable or disable debug logs for the script. - enableErrorCodes: (Serialized) Enable or disable error codes display. - authenticationTimeout: (Serialized) The timeout value for the authentication process, in seconds. - requestTimeout: (Serialized) The timeout value for web requests, in seconds. - allowedOfflineDays: (Serialized) Number of days offline authentication is allowed. - backendServerIP, serverDomain: (Serialized) Backend server configuration details. - useHTTPS: (Serialized) Flag to toggle HTTPS communication. - successfulAuthHTML: (Serialized) HTML content to display when authentication is successful. - errorMessageText, statusText: (Serialized) References to UI elements for displaying messages. - loginButton, logoutButton: (Serialized) References to UI elements for login/logout actions. - onTierStatusUpdate: (Serialized) Event triggered on tier status update.
- Awake(): Initializes the script, validates configurations, and sets up offline authentication. - Start(): Sets up server details and offline data. - Update(): Monitors main thread actions queue. - OnOfflineAuthentication(): Handles actions after successful offline authentication. - LogCurrentKeyValues(): Logs the current PlayerPrefs key-values. - Logout(): Logs the user out and clears offline data. - LoadOfflineData(): Loads saved token and other data. - SaveOfflineData(string accessToken): Saves offline authentication data. - GenerateHardwareId(): Generates a hardware ID for offline authentication. - StartAuthenticationProcess(): Initiates the web-based Patreon authentication. - StartWebServer(): Starts the built-in web server for authentication callback. - GetTiers(): Initiates the process to fetch Patreon tiers. - GetAccessTokenFromBackend(): Coroutine to fetch the access token. - OnRequestReceived(IAsyncResult): Handles received HTTP request for authentication. - FetchMembershipInfo(string): Fetches Patreon membership information. - OnMembershipInfoReceived(AsyncOperation): Handles received membership info. - HandleNoMatchingTiers(): Handles the scenario when no matching tiers are found. - HandleNoValidTierData(): Handles the scenario when no valid tier data is found. - OnUserAuthenticated(): Handles actions after successful online authentication. - CloseWebServer(): Stops and closes the web server. - GetNetworkTime(): Fetches the network time. - SwapEndianness(ulong): Utility to swap endianness of a ulong value. - IsValidBase64String(): Checks if a given string is a valid Base64 string. - EncryptDate(string dateToEncrypt, string offlineEncryptionKey, string offlineEncryptionIV): Encrypts a date using AES encryption. - DecryptDate(string encryptedDate, string offlineEncryptionKey, string offlineEncryptionIV): Decrypts an AES-encrypted date. - DecryptClientID(string encryptedClientID): Decrypts an AES-encrypted client ID. - Log(string message, int errorCode = 0): Logs messages and error codes. - ResetErrorCodeText(): Resets the text for error messages. - SetKeyAndIV(string newKey, string newIV): Sets new encryption key and IV for offline authentication. - AuthenticationTimeoutHandler(): Coroutine for handling authentication timeout.
- PatreonTokenResponse: A record for the response from Patreon when requesting a token. - PatreonResponse: A record for the general response from Patreon. - PatreonData: A record for Patreon data. - PatreonRelationships: A record for Patreon relationships. - PatreonMemberships: A record for Patreon memberships. - PatreonMemberData: A record for Patreon member data. - PatreonTier: A record for Patreon tiers.
onTierStatusUpdate(): Invoked when the user's tier status updates. In the DemoScene, this event calls CheckTier(int sentTier) in the TierCheck script, which triggers a function to load the EmptySceneToLoad.
Namespace: MSCreativeTech.AuthenticationForPatreon
Description: Checks the Patreon tier of an authenticated user and performs actions accordingly.
- patreonIntegration (Private): Reference to the PatreonIntegration script. - errorMessageText (Private): Reference to a UI element for displaying error messages. - sceneToLoad (Private): Name of the scene to load upon successful tier check. - minimumRequiredTier (Private): Minimum required Patreon tier for access. - enableDebugLogs: (Serialized) Toggle to enable or disable debug logs for the script. - enableErrorCodes: (Serialized) Enable or disable error codes display. - loadSceneOnTierReceive: (Serialized) Flag to load the specified scene when tier is received.
- CheckTier(int sentTier): Checks the Patreon tier of the user. - CheckMemberID(string sentMemberID): Checks the Patreon member ID of the user. - LoadScene(): Loads the specified Unity scene. - GetSavedTier(): Retrieves the saved Patreon tier from PlayerPrefs. - Log(string message, int errorCode = 0): Logs messages and error codes.
onTierMatch(): Invoked when the Patreon tier of the user matches the required tier.
For questions or issues, please contact mscreativetech@proton.me.