title: Nodejs- Unable to get access token from a 3rd party Auth Server using OAuth
body: <p>This is my first attempt at connecting using a custom oAuth as i couldn't find a library for the particular service i am working with. Users from my app should be able to authenticate using another service provider like google/facebook. After going through the docs, i was able to mock up something like this to get the access token .</p>
  <pre><code>export async function getTokens({
    code,
    clientId,
    clientSecret,
    redirectUri,
  }: {
    code: string
    clientId: string
    clientSecret: string
    redirectUri: string
  }): Promise&lt;{
    access_token: string
    expires_in: Number
    refresh_token: string
    scope: string
    id_token: string
  }&gt; {
  
    const url = &quot;https://api.specificservice.dev/oauth/v1/token&quot;
    const values = {
      code,
      client_id: clientId,
      client_secret: clientSecret,
      redirect_uri: redirectUri,
      grant_type: &quot;authorization_code&quot;,
    }
  
    try {
      const res = await axios.post(url, querystring.stringify(values), {
        headers: {
          &quot;Content-Type&quot;: &quot;application/x-www-form-urlencoded&quot;,
        },
      })
      console.log(res.data)
      return res.data
    } catch (error: any) {
      console.error(`Failed to fetch auth tokens`)
      throw new Error(error.message)
    }
  }
  </code></pre>
  <p>After that i thought that i needed to provide a route that would allow a user initiate this flow.</p>
  <pre><code>app.get(`/${redirectURI}`, async (req, res) =&gt; {
      const code = req.query.code as string
  
      const { access_token } = await getTokens({
        code,
        clientId: CLIENT_ID,
        clientSecret: CLIENT_SECRET,
        redirectUri: `localhost:2000/${redirectURI}`,
      })
  
      // Fetch the user's profile with the access token and bearer
      const epicUser = await axios
        .get(
          `https://authurlfromspecificservice`,
          {
            headers: {
              Authorization: `Bearer ${access_token}`,
            },
          }
        )
        .then((res) =&gt; {
          console.log(res.data)
          return res.data
        })
        .catch((error) =&gt; {
          console.error(`Failed to fetch user`)
          throw new Error(error.message)
        })
    })
  </code></pre>
  <p>This did not work as expected because the access token wasn't returned. What do i do next?</p>