Skip to content
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

Allow overriding Session ID for Guest mode #124

Merged
merged 1 commit into from
Jan 17, 2025
Merged
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
6 changes: 5 additions & 1 deletion Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public Task<string> RecoverAddressFromTypedDataV4<T, TDomain>(T data, TypedData<
/// <param name="chainId">The chain ID if linking an external wallet (SIWE).</param>
/// <param name="jwt">The JWT token if linking custom JWT auth.</param>
/// <param name="payload">The login payload if linking custom AuthEndpoint auth.</param>
/// <param name="defaultSessionIdOverride">The default session ID override if linking Guest auth.</param>
/// <param name="forceWalletIds">The wallet IDs to force display if linking using SiweExternal auth.</param>
/// <returns>A list of <see cref="LinkedAccount"/> objects.</returns>
public Task<List<LinkedAccount>> LinkAccount(
IThirdwebWallet walletToLink,
Expand All @@ -153,7 +155,9 @@ public Task<List<LinkedAccount>> LinkAccount(
IThirdwebBrowser browser = null,
BigInteger? chainId = null,
string jwt = null,
string payload = null
string payload = null,
string defaultSessionIdOverride = null,
List<string> forceWalletIds = null
);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,9 @@ public async Task<List<LinkedAccount>> LinkAccount(
IThirdwebBrowser browser = null,
BigInteger? chainId = null,
string jwt = null,
string payload = null
string payload = null,
string defaultSessionIdOverride = null,
List<string> forceWalletIds = null
)
{
if (!await this.IsConnected().ConfigureAwait(false))
Expand Down Expand Up @@ -496,11 +498,10 @@ public async Task<List<LinkedAccount>> LinkAccount(
serverRes = await ecosystemWallet.PreAuth_AuthEndpoint(payload).ConfigureAwait(false);
break;
case "Guest":
serverRes = await ecosystemWallet.PreAuth_Guest().ConfigureAwait(false);
serverRes = await ecosystemWallet.PreAuth_Guest(defaultSessionIdOverride).ConfigureAwait(false);
break;
case "SiweExternal":
// TODO: Allow enforcing wallet ids in linking flow?
serverRes = await ecosystemWallet.PreAuth_SiweExternal(isMobile ?? false, browserOpenAction, null, mobileRedirectScheme, browser).ConfigureAwait(false);
serverRes = await ecosystemWallet.PreAuth_SiweExternal(isMobile ?? false, browserOpenAction, forceWalletIds, mobileRedirectScheme, browser).ConfigureAwait(false);
break;
case "Google":
case "Apple":
Expand Down Expand Up @@ -827,7 +828,7 @@ public async Task<string> LoginWithBackend()

#region Guest

private async Task<Server.VerifyResult> PreAuth_Guest()
private async Task<Server.VerifyResult> PreAuth_Guest(string defaultSessionIdOverride = null)
{
var sessionData = this.EmbeddedWallet.GetSessionData();
string sessionId;
Expand All @@ -837,15 +838,15 @@ public async Task<string> LoginWithBackend()
}
else
{
sessionId = Guid.NewGuid().ToString();
sessionId = defaultSessionIdOverride ?? Guid.NewGuid().ToString();
}
var serverRes = await this.EmbeddedWallet.SignInWithGuestAsync(sessionId).ConfigureAwait(false);
return serverRes;
}

public async Task<string> LoginWithGuest()
public async Task<string> LoginWithGuest(string defaultSessionIdOverride = null)
{
var serverRes = await this.PreAuth_Guest().ConfigureAwait(false);
var serverRes = await this.PreAuth_Guest(defaultSessionIdOverride).ConfigureAwait(false);
return await this.PostAuth(serverRes).ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ public virtual Task<List<LinkedAccount>> LinkAccount(
IThirdwebBrowser browser = null,
BigInteger? chainId = null,
string jwt = null,
string payload = null
string payload = null,
string defaultSessionIdOverride = null,
List<string> forceWalletIds = null
)
{
throw new InvalidOperationException("LinkAccount is not supported for private key wallets.");
Expand Down
8 changes: 6 additions & 2 deletions Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,9 @@ public async Task<List<LinkedAccount>> LinkAccount(
IThirdwebBrowser browser = null,
BigInteger? chainId = null,
string jwt = null,
string payload = null
string payload = null,
string defaultSessionIdOverride = null,
List<string> forceWalletIds = null
)
{
var personalWallet = await this.GetPersonalWallet().ConfigureAwait(false);
Expand All @@ -1180,7 +1182,9 @@ public async Task<List<LinkedAccount>> LinkAccount(
}
else
{
return await personalWallet.LinkAccount(walletToLink, otp, isMobile, browserOpenAction, mobileRedirectScheme, browser, chainId, jwt, payload).ConfigureAwait(false);
return await personalWallet
.LinkAccount(walletToLink, otp, isMobile, browserOpenAction, mobileRedirectScheme, browser, chainId, jwt, payload, defaultSessionIdOverride, forceWalletIds)
.ConfigureAwait(false);
}
}

Expand Down
Loading