Powershell script to get the refresh token expiry

Hi All,
I am currently working on a PS script to generate OAuth 2 access tokens(having shorter expiry) using refresh token(having longer expiry).
I do have the code figured out for this but would need help to have a code to be able to identify the expiry of the refresh token. Based on this expiry, the code should be able to generate emails(reminders) to generate a new refresh token.
I tried checking ‘expires_in’ property but it is a static value, i wanted more of countdown.
Any help would be appreciated.

Thanks,
Devender

OAuth for what service? Lots of things support Oauth. Also show your code.

Hi Neemobeer, OAuth to connect to EPM(Oracle) Cloud service from an onpremise server. Below is the code

$client_id = 
$scope = 
$Base_URL = 

#code to generate the verification uri, user code and device code
$header = @{'Content-Type'='application/x-www-form-urlencoded;charset=utf-8'}
$cred=Get-Credential
$dev_resp = Invoke-WebRequest -URI $Base_URL/oauth2/v1/device -method POST -Headers $header -Body @{"response_type"='device_code';'scope'=$scope;'client_id'=$client_id}
$device_resp = ConvertFrom-Json $dev_resp
$device_code = $device_resp.device_code
$user_code = $device_resp.user_code
$verification_uri = $device_resp.verification_uri

#verify the verification uri and close it
#---------------------------------------------

#generate access token and refresh token
$header = @{'Content-Type'='application/x-www-form-urlencoded;charset=utf-8'}
$cred=Get-Credential
$resp=Invoke-WebRequest -URI $Base_URL/oauth2/v1/token -method POST -Headers $header -Body @{"grant_type"='urn:ietf:params:oauth:grant-type:device_code';"device_code"=$device_code;"client_id"=$client_id} 
$refresh_resp = ConvertFrom-Json $resp
$refresh_token = $refresh_resp.refresh_token

#encrypt the refresh token
epmautomate encrypt $refresh_token MyKey C:\Keys\refresh.epw ClientID=$client_id

#generate a fresh access token from the existing refresh token
$header = @{'Content-Type'='application/x-www-form-urlencoded;charset=utf-8'}
$refreshTokenParams = @{ 
    grant_type = "refresh_token"
    client_id = $client_id
    refresh_token = $refresh_token
}
$tokenResponse = Invoke-WebRequest  -Uri $Base_URL/oauth2/v1/token -Method POST -Headers $header -Body $refreshTokenParams


$token_new = ConvertFrom-Json $tokenResponse
$refresh_token_new = $token_new.refresh_token
$access_token = $token_new.access_token

#update the new refresh token
epmautomate encrypt $refresh_token_new MyKey C:\Keys\refresh.epw ClientID=$client_id

#code to check the validity of the refresh token and notify the users to generate a new refresh token
---
---
---

Expires_in is all you get, but you can create a datetime variable with a + expires_in and there’s your time