Skip to content

Commit 762928a

Browse files
committed
feat: store tokens
1 parent b839208 commit 762928a

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

src/Packages/Passport/Runtime/Scripts/Private/Core/Model/BrowserResponse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ public class BrowserResponse
88
public string requestId;
99
public bool success;
1010
public string errorType;
11-
public string error;
11+
public string? error;
1212
}
1313

1414
public class StringResponse : BrowserResponse
1515
{
16-
public string result;
16+
public string? result;
1717
}
1818

1919
public class StringListResponse : BrowserResponse

src/Packages/Passport/Runtime/Scripts/Private/Model/Response/TokenResponse.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ namespace Immutable.Passport.Model
55
[Serializable]
66
public class TokenResponse
77
{
8-
public string accessToken;
9-
public string refreshToken;
10-
public string idToken;
11-
public string tokenType;
12-
public int expiresIn;
8+
public string access_token;
9+
public string refresh_token;
10+
public string id_token;
11+
public string token_type;
12+
public int expires_in;
1313
}
1414
}

src/Packages/Passport/Runtime/Scripts/Private/PassportFunction.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static class PassportFunction
1414
public const string GET_EMAIL = "getEmail";
1515
public const string GET_PASSPORT_ID = "getPassportId";
1616
public const string GET_LINKED_ADDRESSES = "getLinkedAddresses";
17+
public const string STORE_TOKENS = "storeTokens";
1718
public static class IMX
1819
{
1920
public const string GET_ADDRESS = "getAddress";

src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,13 @@ public async UniTask<bool> HasCredentialsSaved()
503503
}
504504
}
505505

506+
public async UniTask<bool> CompleteLogin(TokenResponse request)
507+
{
508+
var json = JsonUtility.ToJson(request);
509+
var callResponse = await _communicationsManager.Call(PassportFunction.STORE_TOKENS, json);
510+
return callResponse.GetBoolResponse() ?? false;
511+
}
512+
506513
public async UniTask<string?> GetAddress()
507514
{
508515
var response = await _communicationsManager.Call(PassportFunction.IMX.GET_ADDRESS);

src/Packages/Passport/Runtime/Scripts/Public/Passport.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ public async UniTask<bool> ConnectImx(bool useCachedSession = false, DirectLogin
309309
return await GetPassportImpl().ConnectImx(useCachedSession, directLoginMethod);
310310
}
311311

312+
/// <summary>
313+
/// Completes the login process by storing the token. This is required for the login to be complete.
314+
/// </summary>
315+
/// <param name="request">The token request</param>
316+
/// <returns>
317+
/// True if successful, otherwise false.
318+
/// </returns>
319+
public async UniTask<bool> CompleteLogin(TokenResponse request)
320+
{
321+
return await GetPassportImpl().CompleteLogin(request);
322+
}
323+
312324
/// <summary>
313325
/// Gets the wallet address of the logged in user.
314326
/// <returns>

0 commit comments

Comments
 (0)