Skip to content

Commit 7fa71e6

Browse files
committed
Coinbase Login & Fix OAuth Linking
1 parent 45b66ba commit 7fa71e6

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

Thirdweb.Console/Program.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,7 @@
8989
// );
9090
// }
9191

92-
// var ecosystemWallet = await EcosystemWallet.Create(
93-
// client: client,
94-
// ecosystemId: "ecosystem.the-bonfire",
95-
// ecosystemPartnerId: "20842d97-be35-4ecc-b51e-9f3ba0843a60",
96-
// email: "[email protected]"
97-
// );
92+
// var ecosystemWallet = await EcosystemWallet.Create(client: client, ecosystemId: "ecosystem.the-bonfire", email: "[email protected]");
9893

9994
// if (!await ecosystemWallet.IsConnected())
10095
// {
@@ -117,9 +112,15 @@
117112
// );
118113
// Console.WriteLine($"Ecosystem Wallet typed sign: {ecosystemTypedSignature}");
119114

120-
// var siweSigner = await PrivateKeyWallet.Generate(client: client);
121-
// var ecosystemWalletOther = await EcosystemWallet.Create(client: client, ecosystemId: "ecosystem.the-bonfire", authProvider: AuthProvider.Siwe, siweSigner: siweSigner);
122-
// var linkedAccounts = await ecosystemWallet.LinkAccount(walletToLink: ecosystemWalletOther, chainId: 421614);
115+
// var ecosystemWalletOther = await EcosystemWallet.Create(client: client, ecosystemId: "ecosystem.the-bonfire", authProvider: AuthProvider.Telegram);
116+
// var linkedAccounts = await ecosystemWallet.LinkAccount(
117+
// walletToLink: ecosystemWalletOther,
118+
// browserOpenAction: (url) =>
119+
// {
120+
// var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true };
121+
// _ = Process.Start(psi);
122+
// }
123+
// );
123124
// Console.WriteLine($"Linked accounts: {JsonConvert.SerializeObject(linkedAccounts, Formatting.Indented)}");
124125

125126
// var ecosystemSmartWallet = await SmartWallet.Create(ecosystemWallet, 421614);
@@ -322,7 +323,7 @@
322323

323324
#region InAppWallet - OAuth
324325

325-
// var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.X);
326+
// var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.Coinbase);
326327
// if (!await inAppWalletOAuth.IsConnected())
327328
// {
328329
// _ = await inAppWalletOAuth.LoginWithOauth(

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public partial class EcosystemWallet : PrivateKeyWallet
1818
private readonly string _email;
1919
private readonly string _phoneNumber;
2020
private readonly string _authProvider;
21+
private readonly string _ecosystemId;
22+
private readonly string _ecosystemPartnerId;
2123

2224
private string _address;
2325

@@ -26,9 +28,21 @@ public partial class EcosystemWallet : PrivateKeyWallet
2628
private const string EMBEDDED_WALLET_PATH_V1 = $"{EMBEDDED_WALLET_BASE_PATH}/v1";
2729
private const string ENCLAVE_PATH = $"{EMBEDDED_WALLET_PATH_V1}/enclave-wallet";
2830

29-
private EcosystemWallet(ThirdwebClient client, EmbeddedWallet embeddedWallet, IThirdwebHttpClient httpClient, string email, string phoneNumber, string authProvider, IThirdwebWallet siweSigner)
31+
private EcosystemWallet(
32+
string ecosystemId,
33+
string ecosystemPartnerId,
34+
ThirdwebClient client,
35+
EmbeddedWallet embeddedWallet,
36+
IThirdwebHttpClient httpClient,
37+
string email,
38+
string phoneNumber,
39+
string authProvider,
40+
IThirdwebWallet siweSigner
41+
)
3042
: base(client, null)
3143
{
44+
this._ecosystemId = ecosystemId;
45+
this._ecosystemPartnerId = ecosystemPartnerId;
3246
this._embeddedWallet = embeddedWallet;
3347
this._httpClient = httpClient;
3448
this._email = email;
@@ -79,6 +93,7 @@ public static async Task<EcosystemWallet> Create(
7993
AuthProvider.Line => "Line",
8094
AuthProvider.Guest => "Guest",
8195
AuthProvider.X => "X",
96+
AuthProvider.Coinbase => "Coinbase",
8297
AuthProvider.Default => string.IsNullOrEmpty(email) ? "Phone" : "Email",
8398
_ => throw new ArgumentException("Invalid AuthProvider"),
8499
};
@@ -113,12 +128,12 @@ public static async Task<EcosystemWallet> Create(
113128
try
114129
{
115130
var userAddress = await ResumeEnclaveSession(enclaveHttpClient, embeddedWallet, email, phoneNumber, authproviderStr).ConfigureAwait(false);
116-
return new EcosystemWallet(client, embeddedWallet, enclaveHttpClient, email, phoneNumber, authproviderStr, siweSigner) { _address = userAddress };
131+
return new EcosystemWallet(ecosystemId, ecosystemPartnerId, client, embeddedWallet, enclaveHttpClient, email, phoneNumber, authproviderStr, siweSigner) { _address = userAddress };
117132
}
118133
catch
119134
{
120135
enclaveHttpClient.RemoveHeader("Authorization");
121-
return new EcosystemWallet(client, embeddedWallet, enclaveHttpClient, email, phoneNumber, authproviderStr, siweSigner) { _address = null };
136+
return new EcosystemWallet(ecosystemId, ecosystemPartnerId, client, embeddedWallet, enclaveHttpClient, email, phoneNumber, authproviderStr, siweSigner) { _address = null };
122137
}
123138
}
124139

@@ -329,6 +344,7 @@ public async Task<List<LinkedAccount>> LinkAccount(
329344
case "Telegram":
330345
case "Line":
331346
case "X":
347+
case "Coinbase":
332348
serverRes = await walletToLink.PreAuth_OAuth(isMobile ?? false, browserOpenAction, mobileRedirectScheme, browser).ConfigureAwait(false);
333349
break;
334350
default:
@@ -450,6 +466,11 @@ public async Task<string> LoginWithOtp(string otp)
450466
var redirectUrl = isMobile ? mobileRedirectScheme : "http://localhost:8789/";
451467
var loginUrl = await this._embeddedWallet.FetchHeadlessOauthLoginLinkAsync(this._authProvider, platform).ConfigureAwait(false);
452468
loginUrl = platform == "web" ? loginUrl : $"{loginUrl}?platform={platform}&redirectUrl={redirectUrl}&developerClientId={this.Client.ClientId}&authOption={this._authProvider}";
469+
loginUrl = $"{loginUrl}&ecosystemId={this._ecosystemId}";
470+
if (!string.IsNullOrEmpty(this._ecosystemPartnerId))
471+
{
472+
loginUrl = $"{loginUrl}&ecosystemPartnerId={this._ecosystemPartnerId}";
473+
}
453474

454475
browser ??= new InAppWalletBrowser();
455476
var browserResult = await browser.Login(this.Client, loginUrl, redirectUrl, browserOpenAction, cancellationToken).ConfigureAwait(false);

Thirdweb/Thirdweb.Wallets/InAppWallet/InAppWallet.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public enum AuthProvider
2323
Siwe,
2424
Line,
2525
Guest,
26-
X
26+
X,
27+
Coinbase
2728
}
2829

2930
public struct LinkedAccount
@@ -105,6 +106,7 @@ public static async Task<InAppWallet> Create(
105106
Thirdweb.AuthProvider.Line => "Line",
106107
Thirdweb.AuthProvider.Guest => "Guest",
107108
Thirdweb.AuthProvider.X => "X",
109+
Thirdweb.AuthProvider.Coinbase => "Coinbase",
108110
Thirdweb.AuthProvider.Default => string.IsNullOrEmpty(email) ? "Phone" : "Email",
109111
_ => throw new ArgumentException("Invalid AuthProvider"),
110112
};
@@ -230,6 +232,7 @@ public async Task<List<LinkedAccount>> LinkAccount(
230232
case "Telegram":
231233
case "Line":
232234
case "X":
235+
case "Coinbase":
233236
serverRes = await walletToLink.PreAuth_OAuth(isMobile ?? false, browserOpenAction, mobileRedirectScheme, browser).ConfigureAwait(false);
234237
break;
235238
default:

0 commit comments

Comments
 (0)