Check if OAuth Token is expired

D_8
Tera Contributor

I would like to know if there is a way via script to find if the existing OAuth token is still valid or expired ? 

Currently we have API calls that fetch the Access token, and we have refresh token grant flow that will get us a new access token when the previous access token expires. So before refreshing the token, we would like to know if its possible to somehow check if the current access token is still valid or not. 

1 ACCEPTED SOLUTION

ARG645
Tera Guru

Try using this code snippet. 

auth_value = "Your Token Value";

var result = GlideUser.authenticateOAuthAccessToken(auth_value);      
      if (!result) {
         gs.log("Oauth authentication failed for access token: " + auth_value);
      else{
         gs.log("The given OAuth token is Valid");
      } 
}

View solution in original post

3 REPLIES 3

ARG645
Tera Guru

Try using this code snippet. 

auth_value = "Your Token Value";

var result = GlideUser.authenticateOAuthAccessToken(auth_value);      
      if (!result) {
         gs.log("Oauth authentication failed for access token: " + auth_value);
      else{
         gs.log("The given OAuth token is Valid");
      } 
}

D_8
Tera Contributor

It worked, thank you Aman.

NIkesh4
Tera Contributor

@Aman Reddy Gurram 

 

I am trying to check my access token's validity by passing accesstoken details as shown below..

 

auth_value = "xveEwG8xMC0feu2gBiwjXtKjBbuCRrrrIsSzmvogu97X-9jH6nEiZmTRK2w0EaXINi1tXSsqWT5pNWmS5ZYUrQ"; // valid access token

var result = GlideUser.authenticateOAuthAccessToken(auth_value);
if (!result) {
gs.log("Oauth authentication failed for access token: " + auth_value);}
else{
gs.log("The given OAuth token is Valid");
}

 

 

o/p : is alwasy the same.. can u please help here, am i missing anything here

 

Oauth authentication failed for access token xveEwG8xMC0feu2gBiwjXtKjBbuCRrrrIsSzmvogu97X-9jH6nEiZmTRK2w0EaXINi1tXSsqWT5pNWmS5ZYUrQ. No user found.
*** Script: Oauth authentication failed for access token: xveEwG8xMC0feu2gBiwjXtKjBbuCRrrrIsSzmvogu97X-9jH6nEiZmTRK2w0EaXINi1tXSsqWT5pNWmS5ZYUrQ



Thanks