Capacitor Android Issue (Custom Discord Authentication)

We have a React/Capacitor application wired up to use web3Auth + Discord Login. We have used the following guide Discord Guide to get setup & have it working successfully for WEB & IOS. But we are currently running into an issue with native android devices.

At the moment when a user triggers the discord login from within our app the user is redirected to the following page (Open Login) & nothing happens, upon further investigation of the source maps we get an error about redirectUrl does not exist. But we have set that in our adapterSettings.

Screen Shot 2022-08-22 at 9 01 53 PM

Here is a snippet of our initialization code.

<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const web3AuthInit = async () => { try { setInitLoading(true) const web3authCore = new Web3AuthCore({ chainConfig: { chainNamespace: CHAIN_NAMESPACES.EIP155, chainId: '0x1', rpcTarget: 'https://mainnet.infura.io/v3/776218ac4734478c90191dde8cae483c', blockExplorer: 'https://etherscan.io/', ticker: 'ETH', tickerName: 'Ethereum', }, enableLogging: true, })
  const adapter = new OpenloginAdapter({
    adapterSettings: {
      network: 'testnet',
      clientId:
        'XXX',
      uxMode: 'redirect',
      redirectUrl: &quot;XXX&quot;
      loginConfig: {
        discord: {
          name: 'discord',
          verifier: 'discord-learn-card-verifier',
          typeOfLogin: 'discord',
          clientId: 'XXX',
          mainOption: true,
          showOnMobile: true,
          showOnDesktop: true,
        },
      },
    },
  })

  web3authCore.configureAdapter(adapter)
  subscribeAuthEvents(web3authCore)
  web3AuthStore.set.web3Auth(web3authCore)

  await web3authCore.init()
} catch (error) {
  setInitLoading(false)
  console.log(error)
}

}">

const web3AuthInit = async () => {
try {
setInitLoading(true)
const web3authCore = new Web3AuthCore({
chainConfig: {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: ‘0x1’,
rpcTarget:
https://mainnet.infura.io/v3/776218ac4734478c90191dde8cae483c,
blockExplorer: https://etherscan.io/,
ticker: ‘ETH’,
tickerName: ‘Ethereum’,
},
enableLogging: true,
})

  <span class="pl-k">const</span> <span class="pl-s1">adapter</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">OpenloginAdapter</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
    <span class="pl-c1">adapterSettings</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">network</span>: <span class="pl-s">'testnet'</span><span class="pl-kos">,</span>
      <span class="pl-c1">clientId</span>:
        <span class="pl-s">'XXX'</span><span class="pl-kos">,</span>
      <span class="pl-c1">uxMode</span>: <span class="pl-s">'redirect'</span><span class="pl-kos">,</span>
      <span class="pl-c1">redirectUrl</span>: <span class="pl-s">"XXX"</span>
      <span class="pl-s1">loginConfig</span>: <span class="pl-kos">{</span>
        <span class="pl-s1">discord</span>: <span class="pl-kos">{</span>
          <span class="pl-c1">name</span>: <span class="pl-s">'discord'</span><span class="pl-kos">,</span>
          <span class="pl-c1">verifier</span>: <span class="pl-s">'discord-learn-card-verifier'</span><span class="pl-kos">,</span>
          <span class="pl-c1">typeOfLogin</span>: <span class="pl-s">'discord'</span><span class="pl-kos">,</span>
          <span class="pl-c1">clientId</span>: <span class="pl-s">'XXX'</span><span class="pl-kos">,</span>
          <span class="pl-c1">mainOption</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
          <span class="pl-c1">showOnMobile</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
          <span class="pl-c1">showOnDesktop</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
        <span class="pl-kos">}</span><span class="pl-kos">,</span>
      <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span>

  <span class="pl-s1">web3authCore</span><span class="pl-kos">.</span><span class="pl-en">configureAdapter</span><span class="pl-kos">(</span><span class="pl-s1">adapter</span><span class="pl-kos">)</span>
  <span class="pl-en">subscribeAuthEvents</span><span class="pl-kos">(</span><span class="pl-s1">web3authCore</span><span class="pl-kos">)</span>
  <span class="pl-s1">web3AuthStore</span><span class="pl-kos">.</span><span class="pl-c1">set</span><span class="pl-kos">.</span><span class="pl-en">web3Auth</span><span class="pl-kos">(</span><span class="pl-s1">web3authCore</span><span class="pl-kos">)</span>

  <span class="pl-k">await</span> <span class="pl-s1">web3authCore</span><span class="pl-kos">.</span><span class="pl-en">init</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span> <span class="pl-k">catch</span> <span class="pl-kos">(</span><span class="pl-s1">error</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-en">setInitLoading</span><span class="pl-kos">(</span><span class="pl-c1">false</span><span class="pl-kos">)</span>
  <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">error</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span>

}



Originally posted by: gerardopar

Check the discussion at: https://github.com/orgs/Web3Auth/discussions/460

Hey @gerardopar

What's your redirectUrl? Also, have you whitelisted that in the dashboard?

And please note:

Screenshot 2022-09-05 at 6 25 52 PM

https://web3auth.io/docs/sdk/web/openlogin#openloginloginparams

Originally posted by: shahbaz17

Please note that for Android, your URL looks similar to {YOUR_APP_PACKAGE_NAME}://auth



Originally posted by: yashovardhan

@shahbaz17 @yashovardhan After doing an immense amount of debugging, I've been able to localize the problem within the @toruslabs/openlogin package. It seems that, for some reason, in this specific environment, third party cookies aren't working correctly!

To workaround this, I have set no3PC to true, but on the current version of @web3auth/openlogin-adapter, this will cause the adapter to fail to initialize due to an invalid check inside the @toruslabs/openlogin package. Fortunately, that has already been fixed (see this commit) upstream! The problem is that @web3auth/openlogin-adapter doesn't have the latest version of @toruslabs/openlogin bumped in its package json yet, so the code that ultimately gets pulled in still does not work.

I have put up this PR to address this. Hopefully with that merged in and a new package released, this should start working! I have tested manually editing the compiled @toruslabs/openlogin file, and it has been working for me!



Originally posted by: TaylorBeeston