Custom JWT Login with Embedded Wallets
Embedded Wallets supports integration with custom login providers through JWT-based authentication schemes, allowing developers to maintain their existing authentication infrastructure while leveraging Web3Auth's wallet and key management capabilities. Custom authentication can be implemented using industry-standard cryptographic algorithms such as RSA or ECDSA signatures.
To use this feature, developers must ensure that their JWTs adhere to the JWT specification. Each JWT must be signed using a private key, and its corresponding public key must be accessible via a JWKS (JSON Web Key Set) endpoint. Web3Auth will use this endpoint to verify the integrity and authenticity of incoming tokens during login.
Once the custom JWT login is working, developers can proceed to add it as a custom connection in the dashboard.
Set up a custom JWT connection
To use this feature, developers must go to the Custom Connections tab in the dashboard.
Follow these steps to create a custom JWT connection:
- Visit the Embedded Wallets dashboard.
- Go to the Custom Connections section.
- Click on the Settings icon near the Custom Connection.
- Enter the Auth Connection ID.
- Paste the JWKS Endpoint.
- Paste a sample JWT Token to auto populate the best JWT validations possible.
- Select the JWT user identifier:
email,suborcustom. - (Optional) Toggle the case sensitivity of
User Identifier. - Click on Add Custom Validations to add validations manually.
- Type iss as a field and
your-issueras a value. - Type aud as a field and
your-audienceas a value.
- Type iss as a field and
- Click the Add Connection button to save the settings.
Create a JWT
To generate the JWT, developers may use a package of their choice. Web3Auth provides documentation and examples using both the jsonwebtoken and jose libraries.
Generate a private key
Developers can generate a private key using the openssl command-line tool. This private key will be used to sign the ID token.
- RSA256
- ECDSA
Developers can run the following command in the terminal to generate a new privateKey.pem file containing the RSA256 key details.
openssl genrsa -out privateKey.pem 2048
Once the private key is generated, developers can generate the public key which can be used to verify the JWT and convert it to JWKS.
openssl rsa -in privateKey.pem -pubout -out publicKey.pem
Developers can run the following command in the terminal to generate a new privateKey.pem file containing the ECDSA key details.
openssl ecparam -name secp256k1 -genkey -noout -out ec-secp256k1-privateKey.pem
Once the private key is generated, developers can generate the public key which can be used to verify the JWT and convert it to JWKS.
openssl ec -in ec-secp256k1-privateKey.pem -pubout -out ec-secp256k1-publicKey.pem