Is it possible to set redirect uri when using custom jwt wallet authentication

my plan is base.
i have my authentication server and i want to connect with web3auth using with custom jwt.
const web3authProvider = await this.web3auth.connectTo(WALLET_ADAPTERS.AUTH, {
loginProvider: “jwt”,
extraLoginOptions: {
id_token: accessToken,
verifierIdField: “sub”,
domain: window.location.origin,
redirectUrl: window.location.origin, <— can i set redirect uri
},
});

1 Like

Hello 劉鍾敏,

It’s great to hear that you’re working with the Web3Auth PnP Web SDK and planning to use custom JWT authentication.

To set up a redirect URI when using the connectTo method with custom JWT, you can indeed define a redirectUrl within your extraLoginOptions. This parameter allows you to specify where users should be redirected after the login process.

Since you are on the base plan, ensure that any URI you wish to use for redirection is both valid and properly configured in your authentication server setup. Please also confirm this redirection URI is added to the allowlist within your Web3Auth project settings to avoid any issues.

For more detailed guidance on setting up custom JWT authentication with Web3Auth, you can refer to the Web3Auth documentation, particularly the section on custom authentication.

If you encounter any issues or have any specific implementation questions, feel free to share the details or any errors you encounter!

Good luck with your integration! :blush:

Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.

Additionally, we would recommend you to join our biweekly Office Hours to get this resolved even faster. Web3Auth Developer Office Hours

1 Like

May I ask what is your intended use case?

connectTo takes loginParams, and it doesn’t have the redirectUrl parameter.

Also, unless you’re using Auth0, you don’t have to specify the domain in the extraLoginOptions

Thanks for the reply.

I already have my own authentication server and I am expecting to link wallets using JWT (access token) for each user issued by the authentication server. I have verified with Web3Auth’s Custom Authentication that it is possible to link wallets.

Here is the code I implemented.
      const loginOptions = {
        loginProvider: 'jwt', extraLoginOptions: { loginProvider: 'jwt', extraLoginOptions
        extraLoginOptions: {
          id_token: accessToken, domain: window.location.origin, { id_token: accessToken
          domain: window.location.origin,.
          // eslint-disable-next-line @typescript-eslint/no-explicit-any
        } as any, }
      }

loginOptions.extraLoginOptions.redirectUrl = I want to set my service url after web3auth wallet issued or connecting
            const authOnlyAdapter = new AuthAdapter({
              adapterSettings: { {
                uxMode: forceRedirect ? UX_MODE.REDIRECT : UX_MODE.POPUP,
                loginConfig: {
                  jwt: {
                    verifier: useRuntimeConfig().public.jwtVerifier, { jwtVerifier
                    typeOfLogin: 'jwt',
                    clientId: useRuntimeConfig().public.web3AuthClientId as string || '',
                  }, }
                }, }
                redirectUrl: forceRedirect ? redirectUrl : undefined, }
              }, }
            })

          this.web3auth.configureAdapter(authOnlyAdapter)
        const web3authProvider = await this.web3auth.connectTo( <-- it is only first connection if reconnect would be error
          WALLET_ADAPTERS.AUTH,.
          loginOptions, loginOptions
        )

What i want to know

  1. it is right or not the below code

loginOptions.extraLoginOptions.redirectUrl = I want to set my service url after web3auth wallet issued or connecting

  1. If a user logs out of my service and then logs in again, I would like to know if the same flow needs to be followed each time to connect with connectTo in web3auth sdk function, or is there any alternative way?

thanks in advance.

If you have your authentication server, we would be requiring just the id_token(JWT) and not the access_token. No need to pass the domain or to setup the redirectUrl, redirect logic can be handled at code level. Also, can you give me a sample idToken and your verifier name?

here is sample token

eyJhbGciOiJFUzI1NiIsImtpZCI6IlBLOThkejhfbUZLLWdxN1BDTzBzaVlXdDhWbXdfY21VSkpidkhQWEtGMVUiLCJ0eXAiOiJKV1QifQ.eyJzaWQiOiJaLTMyT3doRC1rWkltQUZQIiwiaXNzIjoibmV3bG8ueHl6Iiwic3ViIjoiekRCMnhrY1NVZUFreFhFaFdkMVAiLCJhdWQiOiJhYWFhYWFhYWEiLCJleHAiOjE3NDM2NTI1MTUsIm5iZiI6MTc0MzY0ODMxNSwiaWF0IjoxNzQzNjQ4MzE1fQ.8OLSZbRWWvV4hydDdy9FBTaPjsVOTWXc42pFj_bii2-AYbwN6ib2Q7AFr5Oqo0C_tEgK1WA2SrIso-8_sPwX6A

verifier name is Newlo-custom-test

Your verifier setup is correct and the idToken has all the necessary information needed for the login.

Simply don’t pass the domain and redirectURI, login will work.

thanks.
I have an one more question.
Is it possible to connect web3auth wallet without redirect or popup mode after connectTo function once?

With PnP SDK, it’s not. But using SFA and CoreKit SDKs you can, but that’s completely a different solution.