Skip to content

Commit 4e92bd7

Browse files
committed
Introduce api versioning, update readme, minor cleanups
1 parent 5209c8b commit 4e92bd7

File tree

6 files changed

+85
-81
lines changed

6 files changed

+85
-81
lines changed

ID/GameSwiftSdkId.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace GameSwiftSDK.Id
88
/// </summary>
99
public partial class GameSwiftSdkId : MonoBehaviour
1010
{
11-
private const string ID_VERSION = "";
12-
private const string API_ADDRESS = "https://id.gameswift.io/api" + ID_VERSION;
11+
private const string ID_VERSION = "1";
12+
private const string API_ADDRESS = "https://id.gameswift.io/api/" + ID_VERSION;
1313

1414
private static GameSwiftSdkId _instance;
1515

ID/GameSwiftSdkIdGet.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static void GetAuthorizationCode (string accessToken, string clientId, st
6969
}
7070

7171
/// <summary>
72-
/// Receives logged and authorized user's information. Also maintains multiple account login attempts lock.
72+
/// Retrieves logged and authorized user's information. Also maintains multiple account login attempts lock.
7373
/// Sends a <a href="https://id.gameswift.io/swagger/#/oauth/OauthController_getMe">GET /api/{idVersion}/oauth/me</a> request.
7474
/// </summary>
7575
/// <param name="accessToken">Access Token received from <a href="https://id.gameswift.io/swagger/#/oauth/OauthController_postToken">POST /api/{idVersion}/oauth/token</a> request</param>
@@ -87,7 +87,7 @@ public static void GetOauthUserInformation (string accessToken, Action<OauthUser
8787

8888
/// <summary>
8989
/// Retrieves logged and authorized user's information. Also maintains multiple account login attempts lock.
90-
/// Uses stored Access Token in it's request call.
90+
/// Uses Access Token stored in the SDK instance after successful authorization.
9191
/// Sends a <a href="https://id.gameswift.io/swagger/#/oauth/OauthController_getMe">GET /api/{idVersion}/oauth/me</a> request.
9292
/// </summary>
9393
/// <param name="handleSuccess">Success handler</param>
@@ -97,7 +97,7 @@ public static void GetOauthUserInformation (Action<OauthUserInfoResponse> handle
9797
{
9898
if (string.IsNullOrEmpty(Instance.AccessToken))
9999
{
100-
var failMessage = "No authorization code cached from launcher, cannot retrieve user info";
100+
var failMessage = "Access Token is not stored in the SDK instance. Can't retrieve user info.";
101101
handleFailure.Invoke(new SdkFailResponse(failMessage));
102102
}
103103
else

ID/GameSwiftSdkIdPost.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -106,38 +106,6 @@ void HandleOAuthMeSuccess (OauthUserInfoResponse oauthMeResponse)
106106
}
107107
}
108108

109-
/// <summary>
110-
/// Logouts from currently logged in account.
111-
/// Sends a <a href="https://id.gameswift.io/swagger/#/default/AuthController_logout">POST /api/{idVersion}/auth/logout</a> request.
112-
/// </summary>
113-
/// <param name="email">Email address of the account to log out</param>
114-
/// <param name="handleSuccess">Success handler</param>
115-
/// <param name="handleFailure">Failure handler</param>
116-
public static void Logout (string email, Action<MessageResponse> handleSuccess,
117-
Action<BaseSdkFailResponse> handleFailure)
118-
{
119-
if (Instance._accessTokenRetrieved)
120-
{
121-
Dictionary<string, string> credentials = new Dictionary<string, string>()
122-
{
123-
{ "email", email }
124-
};
125-
var requestBody = JsonConvert.SerializeObject(credentials, Formatting.Indented);
126-
127-
var apiUri = $"{API_ADDRESS}/auth/logout";
128-
var request = new RequestData(apiUri, requestBody);
129-
request.SetupHeaders(CustomHeader.AccessToken, Instance.AccessToken);
130-
131-
GameSwiftSdkCore.SendPostRequest(request, handleSuccess, handleFailure);
132-
Instance._accessTokenRetrieved = false;
133-
}
134-
else
135-
{
136-
var failMessage = "Cannot use logout endpoint without retrieving access token from login!";
137-
handleFailure.Invoke(new SdkFailResponse(failMessage));
138-
}
139-
}
140-
141109
/// <summary>
142110
/// Refreshes current token.
143111
/// Sends a <a href="https://id.gameswift.io/swagger/#/default/AuthController_postRefresh">POST /api/{idVersion}/auth/refresh</a> request.
@@ -169,7 +137,6 @@ public static void RetrieveOauthToken (string authorizationCode, string clientId
169137
Dictionary<string, string> body = new Dictionary<string, string>()
170138
{
171139
{ "client_id", clientId },
172-
{ "client_secret", "" },
173140
{ "grant_type", "authorization_code" },
174141
{ "code", authorizationCode },
175142
{ "redirect_uri", redirectUri }

ID/Responses/WalletResponse.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class WalletResponse
1313
/// <summary>
1414
/// Games assigned to user's wallet.
1515
/// </summary>
16-
public string[] games;
16+
public Game[] games;
1717

1818
/// <summary>
1919
/// Wallet name.
@@ -30,6 +30,22 @@ public class WalletResponse
3030
/// </summary>
3131
public Chain chain;
3232

33+
/// <summary>
34+
/// Games information.
35+
/// </summary>
36+
public class Game
37+
{
38+
/// <summary>
39+
/// Game's unique ID.
40+
/// </summary>
41+
public string gameId;
42+
43+
/// <summary>
44+
/// Game types.
45+
/// </summary>
46+
public string[] types;
47+
}
48+
3349
/// <summary>
3450
/// Chain information.
3551
/// </summary>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.gameswift.sdk",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"displayName": "GameSwiftSDK",
55
"description": "Unity package making it easy to connect with GameSwift ecosystem via GameSwift ID.",
66
"documentationUrl": "https://docs.gameswift.io/gameswift-products/sdk",

readme.md

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,109 @@
1+
# What is GameSwift SDK?
2+
GameSwift SDK is a Unity toolset created to integrate with GameSwift ID ecosystem. Our SDK is multiplatform - you can build your game for PC, mobile and even browser!
3+
_Aside from GameSwift SDK, we are preparing GameSwift analytics_.
4+
15
# Getting started
26
In order to integrate your Unity game with GameSwift gaming ecosystem, [import](https://docs.unity3d.com/Manual/upm-ui-giturl.html) our package to your project by providing git url.
37
```
48
https://github.com/GameSwift/gameswift-sdk.git
59
```
610

7-
After succesful import, you can handle GameSwift login in 2 ways: with or without [GameSwift launcher](https://launcher.gameswift.io/). As long as your game targets Windows or MacOS, we strongly recommend to [use data passed from our launcher](#logging-in-from-launcher). By doing so, you don't need to implement any login screen for your game as launcher already handles user credentials in a secure way. If you are building for mobile or web, you will need to create a login screen and [implement connection](#logging-in-without-launcher) with GameSwift backend manually.
11+
You can handle GameSwift login in 2 ways: [with launcher](#logging-in-from-launcher) or [without launcher](#logging-in-without-launcher). You can download GameSwift launcher [here](https://launcher.gameswift.io/).
12+
As long as your game targets Windows or MacOS, we strongly recommend to use data passed from our launcher. By doing so, you won't need to implement any login screen for your game as launcher already handles user credentials in a secure way.
13+
If you are building for mobile or web, you will need to create a login screen and implement connection with GameSwift backend manually.
814

9-
## Logging in from launcher
10-
1. Create script that launches at the very beggining of your game.
11-
2. Within this script, call `GameSwiftSdkId.GetUserInformationFromLauncher` if game is not run from the editor.
12-
3. Create success and failure handlers. `HandleSuccess` will be called if we succesful log in from launcher. `HandleFailure` will be called otherwise.
15+
### Logging in from launcher
16+
1. Create a login class, which will be launched on application startup.
17+
2. Call a method `GameSwiftSdkId.ReadUserInfoFromLauncher` in order to retrieve `AccessToken` from launcher's command-line arguments and store it in the SDK's `GameSwiftSdkId.Instance.CmdAccessToken` field used later in the authorization step.
18+
3. Create success and fail handlers for this method.
19+
4. In the success handler call `GameSwiftSdkId.Authorize` method, which will perform all of the next steps for you automatically. Remember to use stored `GameSwiftSdkId.Instance.CmdAccessToken` here. Also, provide your `clientId` and `redirectUri`. If the process is finished successfully you will be authorized and a new `AccessToken` will be stored in the SDK's `GameSwiftSdkId.Instance.AccessToken` field. From now on you should be using this token in each request.
1320

1421
```cs
15-
using GameSwiftSDK.Core;
16-
using GameSwiftSDK.Id;
17-
using GameSwiftSDK.Id.Responses;
18-
using UnityEngine;
19-
2022
public class GameSwiftLauncherLogin : MonoBehaviour
2123
{
22-
[SerializeField]
23-
private RectTransform _waitScreen;
24-
2524
private void Awake()
2625
{
2726
if (Application.isEditor == false)
2827
{
29-
GameSwiftSdkId.GetUserInformationFromLauncher(HandleSuccess, HandleFailure);
28+
GameSwiftSdkId.ReadUserInfoFromLauncher(HandleSuccess, HandleFailure);
3029
}
3130
}
3231

3332
private void HandleSuccess(OauthUserInfoResponse response)
3433
{
35-
_waitScreen.gameObject.SetActive(false);
34+
GameSwiftSdkId.Authorize(GameSwiftSdkId.Instance.CmdAccessToken,
35+
CLIENT_ID, REDIRECT_URI, HandleAuthorizeSuccess, HandleFailure);
3636
}
3737

3838
private void HandleFailure(BaseSdkFailResponse response)
3939
{
40-
Debug.LogError($"Log in error, code: {response.statusCode}, message: {response.Message}");
40+
Debug.LogError($"Login error, code: {response.statusCode}, message: {response.Message}");
4141
Application.Quit();
4242
}
43+
44+
private void HandleAuthorizeSuccess(OauthUserInfoResponse response)
45+
{
46+
// your code on success login
47+
}
4348
}
4449
```
4550

46-
## Logging in without launcher
47-
1. Create script that launches at the very beggining of your game.
48-
2. Within this script, call `GameSwiftSdkId.Login`, passing read user credentials.
49-
3. Create success and failure handlers. `HandleSuccess` will be called if we succesful log in from launcher. `HandleFailure` will be called otherwise.
51+
Though we highly recommend using the above method, if you want to implement some specific for you project login use cases, you can execute authorization methods separately. Keep in mind though, that by doing this you will need to store `AccessToken` in your project by yourself as the last step.
52+
In order to authorize this way, instead of instructions described in the point 4, in the `GameSwiftSdkId.ReadUserInfoFromLauncher` success handler call these methods in sequence, one by one in their respective success handlers:
5053

51-
```cs
52-
using GameSwiftSDK.Core;
53-
using GameSwiftSDK.Id;
54-
using GameSwiftSDK.Id.Responses;
55-
using UnityEngine;
56-
using UnityEngine.UI;
54+
- `GameSwiftSdkId.GetAuthorizationCode` - use stored `GameSwiftSdkId.Instance.CmdAccessToken` here and provide your `clientId` and `redirectUri`.
55+
- `GameSwiftSdkId.RetrieveOauthToken` - provide `authorizationCode` retrieved from the previous method's response (`AuthorizeResponse`) and provide your `clientId` and `redirectUri` again. This will generate an `AccessToken` returned in the request's response (`TokenResponse`).
56+
- `GameSwiftSdkId.GetOauthUserInformation` - use your newly generated `AccessToken` here to get your user's information and on success store it somewhere in your project. From now on you should be using this token in each request.
57+
58+
### Logging in without launcher
59+
1. Create a login class, which will be attached to a login screen.
60+
2. On a login event call a method `GameSwiftSdkId.LoginAndAuthorize` where you need to pass user's `emailOrNickname`, `password`, your `clientId` and `redirectUri` values.
61+
3. Create success and fail handlers for this method.
62+
4. If the process is finished successfully you will be logged in, authorized and a new `AccessToken` will be stored in the SDK's `GameSwiftSdkId.Instance.AccessToken` field. From now on you should be using this token in each request.
5763

64+
```cs
5865
public class GameSwiftManualLogin : MonoBehaviour
5966
{
60-
[SerializeField]
61-
private RectTransform _loginScreen;
62-
63-
[SerializeField]
64-
private InputField _emailOrNickname;
67+
private const string CLIENT_ID = "yourClientId";
68+
private const string REDIRECT_URI = "yourRedirectUri";
6569

66-
[SerializeField]
67-
private InputField _password;
70+
[SerializeField] private TMP_InputField emailOrNickname;
71+
[SerializeField] private TMP_InputField password;
6872

6973
private void Awake()
7074
{
71-
GameSwiftSdkId.Login(_emailOrNickname.text, _password.text, HandleSuccess, HandleFailure);
75+
GameSwiftSdkId.LoginAndAuthorize(emailOrNickname.text, password.text,
76+
CLIENT_ID, REDIRECT_URI, HandleSuccess, HandleFailure);
7277
}
7378

74-
private void HandleSuccess(LoginResponse response)
79+
private void HandleSuccess(LoginResponse response)
7580
{
76-
_loginScreen.gameObject.SetActive(false);
81+
// your code on success login
7782
}
7883

79-
private void HandleFailure(BaseSdkFailResponse response)
84+
private void HandleFailure(BaseSdkFailResponse response)
8085
{
81-
Debug.LogError($"Log in error, code: {response.statusCode}, message: {response.Message}");
82-
Application.Quit();
86+
Debug.LogError($"Login error, code: {response.statusCode}, message: {response.Message}");
8387
}
8488
}
8589
```
8690

87-
# Troubleshooting
88-
In case of any problems, feel free to contact us at [[email protected]](mailto:[email protected]).
91+
Though we highly recommend using the above method, if you want to implement some specific for you project login use cases, you can execute separate login and authorization methods. In order to achieve this, instead of calling a `GameSwiftSdkId.LoginAndAuthorize` method call these methods in sequence, one by one in their respective success handlers:
92+
- `GameSwiftSdkId.Login` - provide user's `emailOrNickname` and `password`.
93+
- `GameSwiftSdkId.GetAuthorizationCode` - use the `AccessToken` retrieved from `GameSwiftSdkId.Login` method's response (`LoginResponse`) here. Also, provide your `clientId` and `redirectUri`.
94+
- `GameSwiftSdkId.RetrieveOauthToken` - provide `authorizationCode` retrieved from the previous method's response (`AuthorizeResponse`) and provide your `clientId` and `redirectUri` again. This will generate an `AccessToken` returned in the request's response (`TokenResponse`).
95+
- `GameSwiftSdkId.GetOauthUserInformation` - use your newly generated `AccessToken` here to get your user's information and on success store it somewhere in your project. From now on you should be using this token in each request.
96+
97+
### Multiple Logins Blocker
98+
You need to have your client set up to block multiple login attempts for this component to work.
99+
To configure `Multiple Logins Blocker` you need to edit `MultipleLoginsBlockerData.asset` scriptable object which should be automatically created on Unity asset refresh in the `Assets/Resources/GameSwiftSDK/` directory.
100+
When SDK instance in created this component will start working automatically in the background (if is turned on in the config file). Every specified number of seconds it will be sending hearbeats do the server to keep the lock.
101+
If you don't use our recommended login approaches, remember to call `GameSwiftSdkId.GetOauthUserInformation` method as the last step of login process. This will be your first sent heartbeat and will initialize the process.
102+
103+
# Hello Hero
104+
Hello Hero is our sample application that shows how your game can be properly integrated with our SDK. In the aplication we can test requests to the `GameSwift ID` and we can see some basic results in the panel `Output`. Feel free to experiment with it!
105+
106+
![Endpoint](GameSwitftSDK/DocsScreenshots/HelloHero.png)
107+
108+
# Contact Us
109+

0 commit comments

Comments
 (0)