Skip to content

[ID-3870] feat: store tokens #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public class BrowserResponse
public string requestId;
public bool success;
public string errorType;
public string error;
public string? error;
}

public class StringResponse : BrowserResponse
{
public string result;
public string? result;
}

public class StringListResponse : BrowserResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace Immutable.Passport.Model
[Serializable]
public class TokenResponse
{
public string accessToken;
public string refreshToken;
public string idToken;
public string tokenType;
public int expiresIn;
public string access_token;
public string refresh_token;
public string id_token;
public string token_type;
public int expires_in;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class PassportFunction
public const string GET_EMAIL = "getEmail";
public const string GET_PASSPORT_ID = "getPassportId";
public const string GET_LINKED_ADDRESSES = "getLinkedAddresses";
public const string STORE_TOKENS = "storeTokens";
public static class IMX
{
public const string GET_ADDRESS = "getAddress";
Expand Down
7 changes: 7 additions & 0 deletions src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,13 @@ public async UniTask<bool> HasCredentialsSaved()
}
}

public async UniTask<bool> CompleteLogin(TokenResponse request)
{
var json = JsonUtility.ToJson(request);
var callResponse = await _communicationsManager.Call(PassportFunction.STORE_TOKENS, json);
return callResponse.GetBoolResponse() ?? false;
}

public async UniTask<string?> GetAddress()
{
var response = await _communicationsManager.Call(PassportFunction.IMX.GET_ADDRESS);
Expand Down
12 changes: 12 additions & 0 deletions src/Packages/Passport/Runtime/Scripts/Public/Passport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,18 @@ public async UniTask<bool> ConnectImx(bool useCachedSession = false, DirectLogin
return await GetPassportImpl().ConnectImx(useCachedSession, directLoginMethod);
}

/// <summary>
/// Completes the login process by storing the token. This is required for the login to be complete.
/// </summary>
/// <param name="request">The token request</param>
/// <returns>
/// True if successful, otherwise false.
/// </returns>
public async UniTask<bool> CompleteLogin(TokenResponse request)
{
return await GetPassportImpl().CompleteLogin(request);
}

/// <summary>
/// Gets the wallet address of the logged in user.
/// <returns>
Expand Down
Loading