useGetToken

Overview

Custom hook that provides a function to get JWT token for the logged in account. If a valid token is in the cache this will be returned, otherwise a request for a new token will be sent.

If a logged in account is not available, there will be a redirect to the configured OIDC provider’s login page (Indigo IAM, Entra ID, …).

As this uses MSAL’s caching functionality under the hood, it can be called on every API request without affecting performance.

Example : Default usage
import { useGetToken } from '@ska-telescope/ska-login-page';

...

const getToken = useGetToken();

...

const accessToken = await getToken({ scopes: ['user:read'] });