I am using the following code to get the token, based on the below code how do we know the token is expired and get a new token
try {
final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId(clientId)
.clientSecret(clientSecret)
.tenantId(tenantId).build();
final TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(
Arrays.asList(".default"), clientSecretCredential);
graphClient = GraphServiceClient.builder().authenticationProvider(tokenCredentialAuthProvider)
.buildClient();
} catch (Exception e) {
// TODO: handle exception
}
How to know the token has expired . What is the check to do and call the above code again. should i check ClientSecretCredential is null or TokenCredentialAuthProvider is null or GraphServiceClient is null
if (ClientSecretCredential == null) or if (TokenCredentialAuthProvider == null) or if (GraphServiceClient == null)
I have gone through this below link, but does not give much info https://learn.microsoft.com/en-us/answers/questions/812332/access-token-expiry-time-and-refresh-token
It says
And client credential flow will not issue refresh tokens, the client can make the same call again to obtain a new access token.
But on what condition can we call the above code . Any help.