# Set the expiry time of the refresh token (in seconds)
$refreshTokenExpiry = 3600
# Generate the refresh token and store it in $refreshToken
# ...
# Calculate the expiry time of the refresh token
$expiryTime = (Get-Date).AddSeconds($refreshTokenExpiry)
# Schedule email reminders based on the remaining time until the token expires
$reminderIntervals = @(1800, 600, 60) # Remind 30 mins, 10 mins, and 1 min before expiry
foreach ($interval in $reminderIntervals) {
$reminderTime = $expiryTime.AddSeconds(-$interval)
Register-ScheduledTask -TaskName "Refresh Token Expiry Reminder" `
-Trigger (New-ScheduledTaskTrigger -Once -At $reminderTime) `
-Action {
# Send email reminder
Send-MailMessage -To "user@example.com" -Subject "Refresh token will expire soon" `
-Body "Your refresh token will expire in $($interval / 60) minutes."
}
}
Powershell script to get the refresh token expiry
Devender
20
Reputation points
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
Windows for business | Windows Server | User experience | PowerShell
Answer accepted by question author
Sedat SALMAN
14,455
Reputation points MVP