Skip to content

Commit 502461e

Browse files
committed
feat: byoa complete login
1 parent 6c829f4 commit 502461e

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-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
@@ -519,6 +519,13 @@ public async UniTask<bool> HasCredentialsSaved()
519519
}
520520
}
521521

522+
public async UniTask<bool> CompleteLogin(TokenResponse request)
523+
{
524+
var json = JsonUtility.ToJson(request);
525+
var callResponse = await _communicationsManager.Call(PassportFunction.STORE_TOKENS, json);
526+
return callResponse.GetBoolResponse() ?? false;
527+
}
528+
522529
public async UniTask<string?> GetAddress()
523530
{
524531
var response = await _communicationsManager.Call(PassportFunction.IMX.GET_ADDRESS);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,19 @@ public async UniTask<bool> ConnectImx(bool useCachedSession = false, DirectLogin
313313
return await GetPassportImpl().ConnectImx(useCachedSession, directLoginOptions);
314314
}
315315

316+
/// <summary>
317+
/// Completes the login process by storing tokens received from the Bring Your Own Auth API token exchange endpoint.
318+
/// This method enables authentication using existing auth systems without requiring users to log in twice.q
319+
/// </summary>
320+
/// <param name="request">The token request</param>
321+
/// <returns>
322+
/// True if successful, otherwise false.
323+
/// </returns>
324+
public async UniTask<bool> CompleteLogin(TokenResponse request)
325+
{
326+
return await GetPassportImpl().CompleteLogin(request);
327+
}
328+
316329
/// <summary>
317330
/// Gets the wallet address of the logged in user.
318331
/// <returns>

0 commit comments

Comments
 (0)