Get use token in a backstage frontend plugin

158 Views Asked by At

I'm developing a front-end plugin in backstage and need the user data that already logged in.

I can get the userEntityRef that is something like user:default/guest with the useApi, identityApiRef from @backstage/core-plugin-api, but can't get the signed token that is in the backstage cookies ( or in the Authorization header of it ). How can I get it without the backend plugin apis?

1

There are 1 best solutions below

0
meshkati On

Found it! It is possible using the getCredentials in identityApiRef from @backstage/core-plugin-api:

import { useApi, identityApiRef } from '@backstage/core-plugin-api'

const identityApi = useApi(identityApiRef);
identityApi.getCredentials().then(token => {
    console.log(token)
})