Skip to content

Commit

Permalink
Add /custom_login/approve
Browse files Browse the repository at this point in the history
  • Loading branch information
oliexe committed May 15, 2024
1 parent a79cb35 commit fb2372d
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 9 deletions.
10 changes: 10 additions & 0 deletions .idea/.idea.stash-unity/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.stash-unity/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.stash-unity/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static class GameInfo {

public const string ApplicationId = "1045293753265"; // Filled in automatically
public const string IosClientId = "__IOS_CLIENTID__"; // Filled in automatically
public const string WebClientId = "1045293753265-ejh4ifdimiqfqhj2msj2c3h7oib9r7aq.apps.googleusercontent.com"; // Filled in automatically
public const string WebClientId = ""; // Filled in automatically
public const string NearbyConnectionServiceId = "";

public static bool ApplicationIdInitialized() {
Expand Down
55 changes: 55 additions & 0 deletions Assets/Stash/Scripts/Core/StashClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,60 @@ public static async Task<LinkResponse> LinkAccount(string challenge, string play
}
}

/// <summary>
/// Links the player's account to Stash account for Apple Account & Google Account.
///
/// </summary>
/// <param name="challenge">Stash code challenge from the deeplink.</param>
/// <param name="playerId">Player identification, that will be used to identify purchases.</param>
/// <param name="idToken">Valid JWT token of the player.</param>
/// <returns>Returns a confirmation response, or throws StashAPIRequestError if fails.</returns>
public static async Task<LinkResponse> LinkCustom(string challenge, string playerId, string idToken)
{
// Create the authorization header with the access token
RequestHeader authorizationHeader = new()
{
Key = "Authorization",
Value = "Bearer " + idToken
};

// Create the request body with the challenge and internal user id
var requestBody = new LinkBody()
{
codeChallenge = challenge,
user = new LinkBody.User
{
id = playerId
}
};

// Set the URL for the link account endpoint
const string requestUrl = StashConstants.RootUrlTest + StashConstants.LinkCustomAccount;
// Make a POST request to link the access token
Response result = await RestClient.Post(requestUrl, JsonUtility.ToJson(requestBody), new List<RequestHeader> { authorizationHeader });

// Check the response status code
if (result.StatusCode == 200)
{
try
{
// Parse the response data into a LinkResponse object
LinkResponse resultResponse = JsonUtility.FromJson<LinkResponse>(result.Data);
return resultResponse;
}
catch
{
// Throw an error if there is an issue parsing the response data
throw new StashParseError(result.Data);
}
}
else
{
// Throw an error if the API request was not successful
throw new StashRequestError(result.StatusCode, result.Data);
}
}

/// <summary>
/// Links an Apple Game Center account to the Stash user's account.
/// Requires a valid response (signature, salt, timestamp, publicKeyUrl) received from GameKit "fetchItems" no older than 1 hour.
Expand Down Expand Up @@ -160,6 +214,7 @@ public static async Task<LinkResponse> LinkGooglePlayGames(string challenge, str
{
try
{
Debug.Log("[RESPONSE RAW] " + result.Data);
LinkResponse resultResponse = JsonUtility.FromJson<LinkResponse>(result.Data);
return resultResponse;
}
Expand Down
1 change: 1 addition & 0 deletions Assets/Stash/Scripts/Core/StashConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class StashConstants
public const string RootUrlTest = "https://test-api.stash.gg";

public const string LinkAccount = "/sdk/link_code/link";
public const string LinkCustomAccount = "/sdk/custom_login/approve";
public const string LinkAppleGameCenter = "/sdk/link_code/link_apple_game_center";
public const string LinkGooglePlayGames = "/sdk/link_code/link_google_play";
}
Expand Down
7 changes: 0 additions & 7 deletions ProjectSettings/GooglePlayGameSettings.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
lastUpgrade=01101
proj.pluginVersion=0.11.01
proj.AppId=1045293753265
and.BundleId=com.stash.iosdemo
proj.classDir=Assets%2fSamples
proj.ConstantsClassName=GPGSIds
and.ResourceData=%3c%3fxml+version%3d%221.0%22+encoding%3d%22utf-8%22%3f%3e%0a%3c%21--Google+Play+game+services+IDs.+Save+this+file+as+res%2fvalues%2fgames-ids.xml+in+your+project.--%3e%0a%3cresources%3e%0a++%3c%21--app_id--%3e%0a++%3cstring+name%3d%22app_id%22+translatable%3d%22false%22%3e1045293753265%3c%2fstring%3e%0a++%3c%21--package_name--%3e%0a++%3cstring+name%3d%22package_name%22+translatable%3d%22false%22%3ecom.stash.iosdemo%3c%2fstring%3e%0a++%3c%21--achievement+Test+Achievement--%3e%0a++%3cstring+name%3d%22achievement_test_achievement%22+translatable%3d%22false%22%3eCgkIscfzgrYeEAIQAw%3c%2fstring%3e%0a%3c%2fresources%3e
and.ClientId=1045293753265-ejh4ifdimiqfqhj2msj2c3h7oib9r7aq.apps.googleusercontent.com
android.SetupDone=true
3 changes: 2 additions & 1 deletion ProjectSettings/GvhProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<projectSettings>
<projectSetting name="Google.IOSResolver.VerboseLoggingEnabled" value="False" />
<projectSetting name="Google.PackageManagerResolver.VerboseLoggingEnabled" value="False" />
<projectSetting name="Google.VersionHandler.VerboseLoggingEnabled" value="False" />
<projectSetting name="Google.VersionHandler.VerboseLoggingEnabled" value="True" />
<projectSetting name="Google.VersionHandler.VersionHandlingEnabled" value="True" />
<projectSetting name="GooglePlayServices.PromptBeforeAutoResolution" value="False" />
<projectSetting name="GooglePlayServices.UseJetifier" value="True" />
</projectSettings>

0 comments on commit fb2372d

Please sign in to comment.