@@ -40,35 +40,54 @@ following
4040
4141You can use the manual origin whitelisting method to whitelist URLs without using the Developer
4242Dashboard. ` AuthAdapter ` accepts a parameter called ` originData ` inside the ` adapterSettings ` .
43- ` originData ` is a key value pair where the key is the origin URL and the value is a ` signature ` . The
44- signature is generated by ` whitelistUrl ` function from the ` @web3auth/auth ` package. The
45- ` whitelistUrl ` function accepts the ` clientId ` , ` clientSecret ` and ` origin ` as parameters.
43+ ` originData ` is a key-value pair where the key is the origin URL and the value is a ` signature ` . The
44+ signature is generated using the ` whitelistUrl ` function.
4645
4746:::warning Note
4847
4948Please perform this in a highly secure environment. The ` clientSecret ` should not be exposed to the
50- public making this a risky process.
49+ public, making this a risky process.
5150
5251:::
5352
5453``` tsx
5554import { AuthAdapter } from " @web3auth/auth-adapter" ;
56- import { whitelistUrl } from " @web3auth/auth" ;
5755import { CommonPrivateKeyProvider } from " @web3auth/base-provider" ;
56+ import { getPublic , sign } from " @toruslabs/eccrypto" ;
57+ import { keccak256 } from " @toruslabs/metadata-helpers" ;
58+ import base64urlLib from " base64url" ;
59+
60+ const base64url = base64urlLib ;
61+
62+ const whitelistUrl = async (clientId : string , clientSecret : string , origin : string ) => {
63+ const appKeyBuf = Buffer .from (clientSecret .padStart (64 , " 0" ), " hex" );
64+
65+ if (base64url .encode (getPublic (appKeyBuf )) !== clientId ) {
66+ throw new Error (" clientSecret mismatch" );
67+ }
68+
69+ const sig = await sign (appKeyBuf , keccak256 (Buffer .from (origin , " utf8" )));
70+ return base64url .encode (sig );
71+ };
5872
5973const clientId = " YOUR_CLIENT_ID" ; // get from https://dashboard.web3auth.io
6074const clientSecret = " CORRESPONDING_CLIENT_SECRET" ; // get from https://dashboard.web3auth.io
6175const origin = " https://example.com" ;
6276
6377const privateKeyProvider = new CommonPrivateKeyProvider ({ config: { chainConfig } });
64- const sig = await whitelistUrl (clientId , clientSecret , origin );
65-
66- const authAdapter = new AuthAdapter ({
67- privateKeyProvider ,
68- adapterSettings: {
69- originData: { [origin ]: sig },
70- },
71- });
78+
79+ (async () => {
80+ const sig = await whitelistUrl (clientId , clientSecret , origin );
81+
82+ const authAdapter = new AuthAdapter ({
83+ privateKeyProvider ,
84+ adapterSettings: {
85+ originData: { [origin ]: sig },
86+ },
87+ });
88+
89+ console .log (" AuthAdapter initialized:" , authAdapter );
90+ })();
7291```
7392
7493### How to secure deep linking via whitelisting strategies to avoid phishing attacks?
0 commit comments