How do I retrieve user email address if I have public key or public wallet address?

Hello

I’m using a third-party integration that uses web3auth and has a verifier associated and tied directly with it. How would be able to use that information in their email address? Either afterward or during authentication?

I’m using the single factor auth on my nodejs server, version 7.0.1 and 7.0.f for web3auth base.

this is what I get from the auth provider:


Web3AuthProvider: {
"_events":{},"_eventsCount":0,
"defaultConfig":
{"chainConfig":
{"chainId":"0x5","rpcTarget":"https://rpc.ankr.com/eth_goerli","displayName":"goerli","blockExplorer":"https://goerli.etherscan.io/","ticker":"ETH","tickerName":"Ethereum","chainNamespace":"eip155"},"networks":{"0x5":
{"chainId":"0x5","rpcTarget":"https://rpc.ankr.com/eth_goerli","displayName":"goerli","blockExplorer":"https://goerli.etherscan.io/","ticker":"ETH","tickerName":"Ethereum","chainNamespace":"eip155"}}},"defaultState":
{"chainId":"loading"},"disabled":false,"name":"BaseController","initialConfig":{"chainConfig":
{"chainId":"0x5","rpcTarget":"https://rpc.ankr.com/eth_goerli","displayName":"goerli","blockExplorer":"https://goerli.etherscan.io/","ticker":"ETH","tickerName":"Ethereum","chainNamespace":"eip155"}},"initialState":{},"internalConfig":{"chainConfig":
{"chainId":"0x5","rpcTarget":"https://rpc.ankr.com/eth_goerli","displayName":"goerli","blockExplorer":"https://goerli.etherscan.io/","ticker":"ETH","tickerName":"Ethereum","chainNamespace":"eip155"},"networks":{"0x5":
{"chainId":"0x5","rpcTarget":"https://rpc.ankr.com/eth_goerli","displayName":"goerli","blockExplorer":"https://goerli.etherscan.io/","ticker":"ETH","tickerName":"Ethereum","chainNamespace":"eip155"}}},"internalState":
{"chainId":"0x5"},"_providerEngineProxy":{},"chainConfig":

{"chainId":"0x5","rpcTarget":"https://rpc.ankr.com/eth_goerli","displayName":"goerli","blockExplorer":"https://goerli.etherscan.io/","ticker":"ETH","tickerName":"Ethereum","chainNamespace":"eip155"},"networks":{"0x5":
{"chainId":"0x5","rpcTarget":"https://rpc.ankr.com/eth_goerli","displayName":"goerli","blockExplorer":"https://goerli.etherscan.io/","ticker":"ETH","tickerName":"Ethereum","chainNamespace":"eip155"}}}

@vjgee I also attached my code, it’ll be good to have some help on this

@ty1 Thanks for your question.

What third-party integration are you using here?

You can decode the idToken to get the email address:

Here’s my code it’s a small indie thrid party:


const loginUser = async (web3auth, loginChallenge, clientSessionToken) => {
  const socket = io(HEIRLOOM_AUTH_SERVER, {
    query: {
      apiKey: HEIRLOOM_API_KEY,
      jwtChallenge: loginChallenge
    }
  })
  const topic = `tokens:${HEIRLOOM_API_KEY}:${loginChallenge}`
  // Setup websocket listener for authentication result from Heirloom
  socket.on(topic, async function (heirloomResponse) {
  // socket.once(topic, async function (heirloomResponse) {
    // socket.off(topic);
    console.log(`✅ Event ${topic} received!`)
    console.log(`🔵 - clientSessionToken token in loginUser: ${clientSessionToken}`)

    const payload = {
      verifier: 'heirloom-staging-verifier',
      verifierId: heirloomResponse.verifierId, // This will be end-user's DID
      idToken: heirloomResponse.idToken
    }

    // Use the payload to call web3auth api directly.
    const web3authProvider = await web3auth.connect(payload)

    if (!web3authProvider) {
      console.log('Web3AuthProvider is null')
      return
    }

    console.log(`Web3AuthProvider: ${JSON.stringify(web3authProvider)}`)
    let privateKey = await web3authProvider.request({ method: 'eth_private_key' })
    if (!privateKey.startsWith('0x')) {
      privateKey = `0x${privateKey}`
    }

    // Create a new Wallet instance with the private key
    const wallet = new ethers.Wallet(privateKey)

    // Send acknowledgement to Heirloom. This will complete the login flow
    socket.emit(`acknowledgement-${topic}`)

    const clientSocket = socketManager.getSocket(clientSessionToken)
    if (clientSocket) {
      clientSocket.emit('userLoggedIn', { address: wallet.address })
    } else {
      console.log(`No socket found for client session token: ${clientSessionToken}`)
    }
    socket.disconnect()
  })
}

Hello @ty1
As @vjgee answered, since you are using SFA web sdk,
you have to utilize your returned idToken and parse it, and then get the email.
Check out how we doing this in this example application.

Once more, try utilize the idToken, not the public address or public Key.

Can pacify me which line of code to use specifically to gather the email?

const parseToken = (token: any) => {
    try {
      const base64Url = token.split(".")[1];
      const base64 = base64Url.replace("-", "+").replace("_", "/");
      return JSON.parse(window.atob(base64 || ""));
    } catch (err) {
      console.error(err);
      return null;
    }
  };

This this the function that I need to use in order to obtain the email?

yes. refer to this function: getting user info

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.