Closed isaced closed 1 day ago
By examining the client.ts
file, it appears that the accessToken is only checked and updated when getAccessToken()
is called, and the idToken
is updated simultaneously.
I'm not sure if this is expected. In my project, I currently don't need to use the accessToken
, so I haven't called the getAccessToken()
method. Are there other ways to update the idToken?
Would you like to provide more details on how you gonna use ID token in your project?
Usually you should rely on access token
for authorization. In Logto, we only use the existence of idToken
to check whether a user is authenticated. And ID token is refreshed along with the refresh of any access token. So far, we do not provide an API to actively refresh ID token.
After integrating my application with Logto, I use the idToken
to protect the backend APIs. Since I only need simple user authentication without requiring fine-grained control over API authorization, I opted to use the idToken.
I didn't create an api-resource in the Logto console but instead used the idToken directly for authentication. In my backend's jwtVerify
call, I did not use the audience
parameter.
I am now trying to switch to using accessToken
authentication, using the specified API Resource works properly, but using the Default API
does not work. I'm not sure what I am doing wrong.
getAccessToken()
, and the parameters passed are empty.jwtVerify()
, audience parameter is empty.const { payload } = await jwtVerify(
token,
createRemoteJWKSet(new URL(this.discoveryCache.jwks_uri)),
{
issuer: this.discoveryCache.issuer,
// audience: ''
},
);
got error: ERR_JWS_INVALID
After integrating my application with Logto, I use the
idToken
to protect the backend APIs. Since I only need simple user authentication without requiring fine-grained control over API authorization, I opted to use the idToken.I didn't create an api-resource in the Logto console but instead used the idToken directly for authentication. In my backend's
jwtVerify
call, I did not use theaudience
parameter.
You should always use an access token to protect API resources, even if you don't need fine-grained access control. We have Protect your API guide here.
If no resource
is specified when initializing a auth request, you will get an opaque access token (not JWT) and hence JWT verification is not applicable in this scenario. In order to get and validate an opaque access token, token introscpection is needed.
Understood, thank you for your response.
At present, I obtain the IdToken through
{ getIdToken } = useLogto();
(react) and then pass it to the back-end structure for authentication through the HTTP Authorization Header.At the beginning, it works well. However, the JWT expires after one hour and will not be refreshed.