Hi ashish;
I assumed the sub
is the user ID, how can I get the user ID given a token? Client side I get an access token like this:
const {access_token} = await new AuthenticationClient({
clientId: process.env.AUTH0_CLIENT,
clientSecret: process.env.AUTH0_SECRET,
domain: 'any4.auth0.com'
}).clientCredentialsGrant({audience: 'https://any4.io/'})
On the server side I verify the token with this middleware:
import * as jwt from 'koa-jwt'
import {koaJwtSecret as secret} from 'jwks-rsa'
const authenticator = jwt({
secret: secret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 1,
jwksUri: `https://any4.auth0.com/.well-known/jwks.json`
}),
audience: 'https://any4.io/',
algorithms: ['RS256'],
issuer: `https://any4.auth0.com/`,
key: 'jwtData'
})
And get a decoded token looking like this:
{
"iss": "https://any4.auth0.com/",
"sub": "iBOtBwpT2vobt3FiDuxpBpU2Gs2F2wqb@clients",
"aud": "https://any4.io/",
"iat": 1578953267,
"exp": 1579039667,
"azp": "iBOtBwpT2vobt3FiDuxpBpU2Gs2F2wqb",
"gty": "client-credentials",
"permissions": []
}
I tried getting the user profile like this:
new AuthenticationClient({domain: 'any4.auth0.com'}).getProfile(authorization.split(' ')[1])
.then(console.log, console.log)
And I get Unauthorized
I’m guessing because the client is missing openid
scope and I don’t know how to fix that. I didn’t see my problem addressed in your links, forgive me if I’m blind.