diff --git a/Assets/Plugins/Android/com.google.android.gms.play-services-games-v2-17.0.0.aar b/Assets/Plugins/Android/com.google.android.gms.play-services-games-v2-17.0.0.aar index 91c9603..8cb0a3e 100644 Binary files a/Assets/Plugins/Android/com.google.android.gms.play-services-games-v2-17.0.0.aar and b/Assets/Plugins/Android/com.google.android.gms.play-services-games-v2-17.0.0.aar differ diff --git a/Assets/Samples/Scripts/DeeplinkExample.cs b/Assets/Samples/Scripts/DeeplinkExample.cs index 8522c62..42b7b79 100644 --- a/Assets/Samples/Scripts/DeeplinkExample.cs +++ b/Assets/Samples/Scripts/DeeplinkExample.cs @@ -76,7 +76,7 @@ public async void ProcessLinking() PlayGames.RefreshCredentials(); try { - LinkResponse response = await StashClient.LinkGooglePlayGames(_stashChallenge, InternalPlayerId, PlayGames.AuthCode); + LinkResponse response = await StashAuth.LinkGooglePlayGames(_stashChallenge, InternalPlayerId, PlayGames.AuthCode); Debug.Log("[STASH][Google Play Games] Account linked successfully."); } diff --git a/Assets/Stash/Scripts/Core/StashClient.cs b/Assets/Stash/Scripts/Core/StashAuth.cs similarity index 87% rename from Assets/Stash/Scripts/Core/StashClient.cs rename to Assets/Stash/Scripts/Core/StashAuth.cs index 2313a2f..910cacc 100644 --- a/Assets/Stash/Scripts/Core/StashClient.cs +++ b/Assets/Stash/Scripts/Core/StashAuth.cs @@ -3,11 +3,15 @@ using UnityEngine; using Stash.Core.Exceptions; using Stash.Models; - +using Stash.Scripts.Core; namespace Stash.Core { -public static class StashClient + /// + /// Linking the player's account to Stash web shop or using 3rd party authentication provider. + /// + +public static class StashAuth { /// /// Links the player's account to Stash account for Apple Account & Google Account. @@ -16,8 +20,12 @@ public static class StashClient /// Stash code challenge from the deeplink. /// Player identification, that will be used to identify purchases. /// Valid JWT token of the player. + /// Stash API environment (Defaults to Test). /// Returns a confirmation response, or throws StashAPIRequestError if fails. - public static async Task LinkAccount(string challenge, string playerId, string idToken) + public static async Task LinkAccount(string challenge, + string playerId, + string idToken, + StashEnvironment environment = StashEnvironment.Test) { // Create the authorization header with the access token RequestHeader authorizationHeader = new() @@ -27,7 +35,7 @@ public static async Task LinkAccount(string challenge, string play }; // Create the request body with the challenge and internal user id - var requestBody = new LinkBody() + var requestBody = new LinkBody { codeChallenge = challenge, user = new LinkBody.User @@ -37,7 +45,7 @@ public static async Task LinkAccount(string challenge, string play }; // Set the URL for the link account endpoint - const string requestUrl = StashConstants.RootUrlTest + StashConstants.LinkAccount; + string requestUrl = environment.GetRootUrl() + StashConstants.LinkAccount; // Make a POST request to link the access token Response result = await RestClient.Post(requestUrl, JsonUtility.ToJson(requestBody), new List { authorizationHeader }); @@ -56,11 +64,9 @@ public static async Task LinkAccount(string challenge, string play throw new StashParseError(result.Data); } } - else - { - // Throw an error if the API request was not successful - throw new StashRequestError(result.StatusCode, result.Data); - } + + // Throw an error if the API request was not successful + throw new StashRequestError(result.StatusCode, result.Data); } @@ -76,9 +82,10 @@ public static async Task LinkAccount(string challenge, string play /// A random string that GameKit uses to compute the hash and randomize it. (Base64 Encoded) /// The URL for the public encryption key. /// The signature’s creation date and time. + /// Stash API environment (Defaults to Test). /// A LinkResponse object. public static async Task LinkAppleGameCenter(string challenge, string playerId, string bundleId, string teamPlayerID, string signature, - string salt, string publicKeyUrl, string timestamp ) + string salt, string publicKeyUrl, string timestamp, StashEnvironment environment = StashEnvironment.Test) { // Create the request body with the challenge and internal user id var requestBody = new LinkGameCenterBody() @@ -106,7 +113,7 @@ public static async Task LinkAppleGameCenter(string challenge, str }; // Set the URL for the link account endpoint - const string requestUrl = StashConstants.RootUrlTest + StashConstants.LinkAppleGameCenter; + string requestUrl = environment.GetRootUrl() + StashConstants.LinkAppleGameCenter; // Make a POST request to link the access token Response result = await RestClient.Post(requestUrl, JsonUtility.ToJson(requestBody)); @@ -139,7 +146,7 @@ public static async Task LinkAppleGameCenter(string challenge, str /// Player identification, that will be used to identify purchases. /// The authorization code generated using RequestServerSideAccess /// A LinkResponse object. - public static async Task LinkGooglePlayGames(string challenge, string playerId, string authCode) + public static async Task LinkGooglePlayGames(string challenge, string playerId, string authCode, StashEnvironment environment = StashEnvironment.Test) { // Create the request body with the challenge and internal user id var requestBody = new LinkGooglePlayGamesBody() @@ -153,7 +160,7 @@ public static async Task LinkGooglePlayGames(string challenge, str }; // Set the URL for the link account endpoint - const string requestUrl = StashConstants.RootUrlTest + StashConstants.LinkGooglePlayGames; + string requestUrl = environment.GetRootUrl() + StashConstants.LinkGooglePlayGames; // Make a POST request to link the access token Response result = await RestClient.Post(requestUrl, JsonUtility.ToJson(requestBody)); @@ -179,7 +186,7 @@ public static async Task LinkGooglePlayGames(string challenge, str } } - /// + /// /// Log in to stash account created using 3rd party authentication provider. /// For use with bespoke login provider. Not intended for general account linking. /// @@ -188,7 +195,7 @@ public static async Task LinkGooglePlayGames(string challenge, str /// Valid identification token (OICD) of the player. /// URL to the player's profile image/avatar to be displayed during login and on web shop. /// Returns a confirmation response, or throws StashAPIRequestError if fails. - public static async Task CustomLogin(string code, string playerId, string idToken, string profileImageUrl) + public static async Task CustomLogin(string code, string playerId, string idToken, string profileImageUrl, StashEnvironment environment = StashEnvironment.Test) { // Create the authorization header with the access token RequestHeader authorizationHeader = new() @@ -209,7 +216,7 @@ public static async Task CustomLogin(string code, string playerId, }; // Set the URL for the link account endpoint - const string requestUrl = StashConstants.RootUrlTest + StashConstants.CustomLogin; + string requestUrl = environment.GetRootUrl() + StashConstants.CustomLogin; // Make a POST request to link the access token Response result = await RestClient.Post(requestUrl, JsonUtility.ToJson(requestBody), new List { authorizationHeader }); diff --git a/Assets/Stash/Scripts/Core/StashClient.cs.meta b/Assets/Stash/Scripts/Core/StashAuth.cs.meta similarity index 100% rename from Assets/Stash/Scripts/Core/StashClient.cs.meta rename to Assets/Stash/Scripts/Core/StashAuth.cs.meta diff --git a/Assets/Stash/Scripts/Core/StashConstants.cs b/Assets/Stash/Scripts/Core/StashConstants.cs index 0aed169..e4bd66f 100644 --- a/Assets/Stash/Scripts/Core/StashConstants.cs +++ b/Assets/Stash/Scripts/Core/StashConstants.cs @@ -2,9 +2,11 @@ namespace Stash.Core { public class StashConstants { + //Root URLs public const string RootUrl = "https://api.stash.gg"; public const string RootUrlTest = "https://test-api.stash.gg"; + //Account Linking public const string LinkAccount = "/sdk/link_code/link"; public const string CustomLogin = "/sdk/custom_login/approve_with_jwt"; public const string LinkAppleGameCenter = "/sdk/link_code/link_apple_game_center"; diff --git a/Assets/Stash/Scripts/Core/StashEnvironment.cs b/Assets/Stash/Scripts/Core/StashEnvironment.cs new file mode 100644 index 0000000..c1a5d78 --- /dev/null +++ b/Assets/Stash/Scripts/Core/StashEnvironment.cs @@ -0,0 +1,22 @@ +namespace Stash.Scripts.Core +{ + public enum StashEnvironment + { + Test, + Production + } + + public static class StashEnvironmentAdapter { + public static string GetRootUrl(this StashEnvironment env) { + switch (env) + { + case StashEnvironment.Test: + return Stash.Core.StashConstants.RootUrlTest; + case StashEnvironment.Production: + default: + return Stash.Core.StashConstants.RootUrl; + + } + } + } +} \ No newline at end of file diff --git a/Assets/Stash/Scripts/Core/StashEnvironment.cs.meta b/Assets/Stash/Scripts/Core/StashEnvironment.cs.meta new file mode 100644 index 0000000..fd1b262 --- /dev/null +++ b/Assets/Stash/Scripts/Core/StashEnvironment.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: dcdfc9752b114645bde1e011aa0d2ec7 +timeCreated: 1718878123 \ No newline at end of file diff --git a/ProjectSettings/GvhProjectSettings.xml b/ProjectSettings/GvhProjectSettings.xml index 1d4f738..3d7f0d7 100644 --- a/ProjectSettings/GvhProjectSettings.xml +++ b/ProjectSettings/GvhProjectSettings.xml @@ -2,8 +2,7 @@ - - + + - \ No newline at end of file