Skip to content

Commit 1db950e

Browse files
fix: make encryption key optional for custom auth wallets (#5341)
## Problem solved fixes CNCT-2269 <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on making the `encryptionKey` optional for in-app and ecosystem wallets' custom authentication methods, enhancing security by discouraging hardcoding sensitive information. ### Detailed summary - Updated `SingleStepAuthArgsType` to make `encryptionKey` optional for both `jwt` and `auth_endpoint` strategies. - Removed hardcoded `encryptionKey` from various authentication examples in documentation. - Emphasized the use of environment variables or user input for `encryptionKey`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 3a65fae commit 1db950e

File tree

6 files changed

+9
-27
lines changed

6 files changed

+9
-27
lines changed

.changeset/rich-kangaroos-sip.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Make encryption key optional for in-app and ecosystem wallets custom auth

apps/portal/src/app/connect/in-app-wallet/custom-auth/configuration/page.mdx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ const handlePostLogin = async (jwt: string) => {
6767
client,
6868
strategy: "jwt",
6969
jwt,
70-
encryptionKey: "your-encryption-key",
7170
});
7271
return wallet;
7372
});
@@ -87,7 +86,6 @@ const account = await wallet.connect({
8786
client,
8887
strategy: "jwt",
8988
jwt,
90-
encryptionKey: "your-encryption-key",
9189
});
9290

9391
// use the account to send transactions
@@ -96,10 +94,6 @@ const account = await wallet.connect({
9694
</TabsContent>
9795
</Tabs>
9896

99-
You can set your `encryptionKey` in either a secret env variable or ask the user to enter a password for it.
100-
101-
** Do not hardcode the `encryptionKey` in your code. **
102-
10397
## Generic auth
10498

10599
Generic auth is a lower-level option that can be used when you have your own auth server that you use to authenticate users.
@@ -159,7 +153,6 @@ const handlePostLogin = async (jwt: string) => {
159153
strategy: "auth_endpoint",
160154
// This is the payload that is sent to the auth endpoint
161155
payload,
162-
encryptionKey: "your-encryption-key",
163156
});
164157
return wallet;
165158
});
@@ -182,15 +175,10 @@ const account = await wallet.connect({
182175
strategy: "auth_endpoint",
183176
// This is the payload that is sent to the auth endpoint
184177
payload,
185-
encryptionKey: "your-encryption-key",
186178
});
187179

188180
// use the account to send transactions
189181
```
190182

191183
</TabsContent>
192184
</Tabs>
193-
194-
You can set your `encryptionKey` in either a secret env variable or ask the user to enter a password for it.
195-
196-
**Do not hardcode the `encryptionKey` in your code. Use environment variables, server returned keys or user derived keys.**

apps/portal/src/app/connect/in-app-wallet/custom-auth/custom-auth-server/page.mdx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ const handlePostLogin = async (jwt: string) => {
107107
client,
108108
strategy: "auth_endpoint",
109109
payload: JSON.stringify({ userId: "ANY_RANDOM_ID_HERE" }),
110-
encryptionKey: "your-encryption-key",
111110
});
112111
return wallet;
113112
});
@@ -127,7 +126,6 @@ const account = await wallet.connect({
127126
client,
128127
strategy: "auth_endpoint",
129128
payload: JSON.stringify({ userId: "ANY_RANDOM_ID_HERE" }),
130-
encryptionKey: "your-encryption-key",
131129
});
132130

133131
// use the account to send transactions
@@ -136,10 +134,6 @@ const account = await wallet.connect({
136134
</TabsContent>
137135
</Tabs>
138136

139-
You can set your encryptionKey in either a secret env variable or ask the user to enter a password for it.
140-
141-
** Do not hardcode the encryptionKey in your code. **
142-
143137
A persistent, cross-platform wallet is now created for your user!
144138

145139
Of course, you would use your own auth server instead of the one we provided. The rest of this guide will show you how to create your own auth server.

apps/portal/src/app/connect/in-app-wallet/custom-auth/firebase-auth/page.mdx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,12 @@ const connectInApp = async (jwt: string) => {
153153
client,
154154
strategy: "jwt",
155155
jwt: await getFirebaseJWT(),
156-
encryptionKey: "your-encryption-key",
157156
});
158157
return wallet;
159158
});
160159
};
161160
```
162161

163-
You can set your `encryptionKey` in either a secret env variable or ask the user to enter a password for it.
164-
165-
** Do not hardcode the `encryptionKey` in your code. **
166-
167162
After the connectInApp function returns, the ThirdwebProvider will have connected a wallet thereby granting access to all hooks and functionalities.
168163

169164
</Step>

apps/portal/src/app/dotnet/wallets/providers/in-app-wallet/page.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ var address = await wallet.LoginWithOauth(
6464
var address = await siweWallet.LoginWithSiwe(chainId: 1);
6565

6666
// Custom Auth (JWT)
67-
var address = await wallet.LoginWithCustomAuth(jwt: "myjwt", encryptionkey: "myencryptionkey");
67+
var address = await wallet.LoginWithCustomAuth(jwt: "myjwt");
6868

6969
// Custom Auth (AuthEndpoint)
70-
var address = await wallet.LoginWithAuthEndpoint(payload: "mypayload", encryptionkey: "myencryptionkey");
70+
var address = await wallet.LoginWithAuthEndpoint(payload: "mypayload");
7171

7272
// Guest Login (Easy onboarding)
7373
var address = await wallet.LoginWithGuest();

packages/thirdweb/src/wallets/in-app/core/authentication/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export type SocialAuthArgsType = {
3434

3535
export type SingleStepAuthArgsType =
3636
| SocialAuthArgsType
37-
| { strategy: "jwt"; jwt: string; encryptionKey: string }
38-
| { strategy: "auth_endpoint"; payload: string; encryptionKey: string }
37+
| { strategy: "jwt"; jwt: string; encryptionKey?: string }
38+
| { strategy: "auth_endpoint"; payload: string; encryptionKey?: string }
3939
| {
4040
/**
4141
* @deprecated

0 commit comments

Comments
 (0)