Skip to content

Commit 40e1d56

Browse files
authored
Allow overriding Session ID for Guest mode (#124)
1 parent b50e1ed commit 40e1d56

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public Task<string> RecoverAddressFromTypedDataV4<T, TDomain>(T data, TypedData<
143143
/// <param name="chainId">The chain ID if linking an external wallet (SIWE).</param>
144144
/// <param name="jwt">The JWT token if linking custom JWT auth.</param>
145145
/// <param name="payload">The login payload if linking custom AuthEndpoint auth.</param>
146+
/// <param name="defaultSessionIdOverride">The default session ID override if linking Guest auth.</param>
147+
/// <param name="forceWalletIds">The wallet IDs to force display if linking using SiweExternal auth.</param>
146148
/// <returns>A list of <see cref="LinkedAccount"/> objects.</returns>
147149
public Task<List<LinkedAccount>> LinkAccount(
148150
IThirdwebWallet walletToLink,
@@ -153,7 +155,9 @@ public Task<List<LinkedAccount>> LinkAccount(
153155
IThirdwebBrowser browser = null,
154156
BigInteger? chainId = null,
155157
string jwt = null,
156-
string payload = null
158+
string payload = null,
159+
string defaultSessionIdOverride = null,
160+
List<string> forceWalletIds = null
157161
);
158162

159163
/// <summary>

Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,9 @@ public async Task<List<LinkedAccount>> LinkAccount(
427427
IThirdwebBrowser browser = null,
428428
BigInteger? chainId = null,
429429
string jwt = null,
430-
string payload = null
430+
string payload = null,
431+
string defaultSessionIdOverride = null,
432+
List<string> forceWalletIds = null
431433
)
432434
{
433435
if (!await this.IsConnected().ConfigureAwait(false))
@@ -496,11 +498,10 @@ public async Task<List<LinkedAccount>> LinkAccount(
496498
serverRes = await ecosystemWallet.PreAuth_AuthEndpoint(payload).ConfigureAwait(false);
497499
break;
498500
case "Guest":
499-
serverRes = await ecosystemWallet.PreAuth_Guest().ConfigureAwait(false);
501+
serverRes = await ecosystemWallet.PreAuth_Guest(defaultSessionIdOverride).ConfigureAwait(false);
500502
break;
501503
case "SiweExternal":
502-
// TODO: Allow enforcing wallet ids in linking flow?
503-
serverRes = await ecosystemWallet.PreAuth_SiweExternal(isMobile ?? false, browserOpenAction, null, mobileRedirectScheme, browser).ConfigureAwait(false);
504+
serverRes = await ecosystemWallet.PreAuth_SiweExternal(isMobile ?? false, browserOpenAction, forceWalletIds, mobileRedirectScheme, browser).ConfigureAwait(false);
504505
break;
505506
case "Google":
506507
case "Apple":
@@ -827,7 +828,7 @@ public async Task<string> LoginWithBackend()
827828

828829
#region Guest
829830

830-
private async Task<Server.VerifyResult> PreAuth_Guest()
831+
private async Task<Server.VerifyResult> PreAuth_Guest(string defaultSessionIdOverride = null)
831832
{
832833
var sessionData = this.EmbeddedWallet.GetSessionData();
833834
string sessionId;
@@ -837,15 +838,15 @@ public async Task<string> LoginWithBackend()
837838
}
838839
else
839840
{
840-
sessionId = Guid.NewGuid().ToString();
841+
sessionId = defaultSessionIdOverride ?? Guid.NewGuid().ToString();
841842
}
842843
var serverRes = await this.EmbeddedWallet.SignInWithGuestAsync(sessionId).ConfigureAwait(false);
843844
return serverRes;
844845
}
845846

846-
public async Task<string> LoginWithGuest()
847+
public async Task<string> LoginWithGuest(string defaultSessionIdOverride = null)
847848
{
848-
var serverRes = await this.PreAuth_Guest().ConfigureAwait(false);
849+
var serverRes = await this.PreAuth_Guest(defaultSessionIdOverride).ConfigureAwait(false);
849850
return await this.PostAuth(serverRes).ConfigureAwait(false);
850851
}
851852

Thirdweb/Thirdweb.Wallets/PrivateKeyWallet/PrivateKeyWallet.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,9 @@ public virtual Task<List<LinkedAccount>> LinkAccount(
431431
IThirdwebBrowser browser = null,
432432
BigInteger? chainId = null,
433433
string jwt = null,
434-
string payload = null
434+
string payload = null,
435+
string defaultSessionIdOverride = null,
436+
List<string> forceWalletIds = null
435437
)
436438
{
437439
throw new InvalidOperationException("LinkAccount is not supported for private key wallets.");

Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,9 @@ public async Task<List<LinkedAccount>> LinkAccount(
11581158
IThirdwebBrowser browser = null,
11591159
BigInteger? chainId = null,
11601160
string jwt = null,
1161-
string payload = null
1161+
string payload = null,
1162+
string defaultSessionIdOverride = null,
1163+
List<string> forceWalletIds = null
11621164
)
11631165
{
11641166
var personalWallet = await this.GetPersonalWallet().ConfigureAwait(false);
@@ -1180,7 +1182,9 @@ public async Task<List<LinkedAccount>> LinkAccount(
11801182
}
11811183
else
11821184
{
1183-
return await personalWallet.LinkAccount(walletToLink, otp, isMobile, browserOpenAction, mobileRedirectScheme, browser, chainId, jwt, payload).ConfigureAwait(false);
1185+
return await personalWallet
1186+
.LinkAccount(walletToLink, otp, isMobile, browserOpenAction, mobileRedirectScheme, browser, chainId, jwt, payload, defaultSessionIdOverride, forceWalletIds)
1187+
.ConfigureAwait(false);
11841188
}
11851189
}
11861190

0 commit comments

Comments
 (0)