getAccessToken() returns encrypted token

,
  • Which SDK this is regarding:@auth0/nextjs-auth0”: “1.6.1”
  • Platform Version: e.g. Node v14.17.5

Using the examples from

and How to Authenticate with Next.js and Auth0: A Guide for Every Deployment Model

I am able to setup a nextjs/react app, sign into auth0 and get tokens back.
The issue I am having is when I call “getAccessToken()” in the api layer, the token returned seems to be encrypted (or at least not readable)
for example,

ewogICJhbGciOiAiZGlyIiwKICAiZW5jIjogIkEyNTZHQ00iLAogICJpc3MiOiAiaHR0cHM6Ly9zb21lLnVzLmF1dGgwLmNvbS8iCn0=…qigMtSvaWPt1Xf0t.aei3MbDgoP028UyerpXPRRa_yLsrZQjRzO4lmbctxcyZq0lDYXSIsLXKUBcxMaffxeayDm5XRv0N49MSLoVgaHwz-AnSqqczS51tUyn8o1shUCgVoRYsefEM4FwFHb7GE-TDGNSsojjjQtsNvANpkyxK87Kh0mzFpV6cCFrqEFGtxJdGVmzaGtVC_3Cs18RgJEB9zPyACuigOmizSBG-8ORrz–xbe4-uufWzsNxcVC4od7EQB1_QXMtXHRSMK07rC4SOaF3Rf3EqQ4muIAAa4jEgpfSz9AkqHRJEOJH4kiOota7_rN-fckgV2vNOKJWQw0aMZLFBFWy42b08bnwM7xGiWM07_WUhg8.IaTp46zPVmhM9c-_T2fnqQ

Some code in pages/api/user.js

import { getAccessToken, withApiAuthRequired } from ‘@auth0/nextjs-auth0’;

export default withApiAuthRequired(async function users(req, res) {
console.log(“getting users …”)
try {
const { accessToken } = await getAccessToken(req, res);
console.log(“with access token …”, accessToken)
const response = await fetch(https://someapi.com/user, {
headers: {
Authorization: Bearer ${accessToken},
‘Content-Type’: ‘application/json’
},
method: ‘GET’
});
console.log(‘getting json …’, response.status)
let json = await response.json();
console.log(“json”, json);
res.status(response.status).json(json)
} catch(error) {
console.error(error)
res.status(error.status || 500).end(error.message)
}
});

and then I attempt to call that with client side code in pages/users.js

import Link from ‘next/link’
import useSWR from ‘swr’
import { withPageAuthRequired } from ‘@auth0/nextjs-auth0’

const fetcher = url => fetch(url).then(r => r.json())

const Users = () => {
const { users, error } = useSWR(‘/api/user’, fetcher)
if (!Array.isArray(users)) {
return (
<>
Home

Users (no array)

{JSON.stringify(users)}
</>
)
}

return (
    <>
        <Link href="/">Home</Link><br />
        <div>Users</div>
        <ul>
            {users.map(d => (<li key={d.userId}>{d.name} {d.userId}</li>))}
        </ul>
    </>
)

}
export const getServerSideProps = withPageAuthRequired();
export default Users

Hey there!

In order to handle that most effectively can I ask you to raise it as a GitHub issue in the SDK repo so we can have that addressed directly with the SDK maintainers? Once you have a link to it make sure to share it here with us so we can ping them.

1 Like

Hey there!

Did you have a chance to open it?

Sorry for the delay – and the skimpy description – See I am getting encrpted cookie when asking for access token · Issue #537 · auth0/nextjs-auth0 · GitHub
And thanks for your follow up

1 Like

No worries!

Thanks for creating the issue, I’ll ping the repo maintainers in a few minutes!