KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to check authentication token and expiration in OAuth2Provider Class instance
PRODUCT: 4D | VERSION: 20 R | PLATFORM: Mac & Win
Published On: July 2, 2025

When implementing a sign-in workflow with the OAuth2Provider class to log in users to Gmail, for instance, it is could be useful to test and verify the status of the authentication token by checking the current access token, refresh token, and token expiration values. For example:

$oAuth2:=cs.NetKit.OAuth2Provider.new($param)
$Gmail:=cs.NetKit.Google.new($oAuth2; {mailType: "JMAP"})

In the above code, an OAuth2Provider class instance is created and passed as a parameter to instantiate a 4D Netkit Google class object to send emails. To verify that the authentication token is periodically updated (e.g. after calling the .getToken() method), the returned $oAuth2 object contains properties in token and tokenExpiration that can be inspected or even displayed in a test email, for example:

$email:=New object
$email.subject:="This is a Test Email"
$email.textBody:="ACCESS TOKEN: "+$oAuth2.token.access_token+"\n"
$email.textBody+="REFRESH TOKEN: "+$oAuth2.token.refresh_token+"\n"
$email.textBody+="EXPIRATION: "+$oAuth2.tokenExpiration
$email.from:="testAcct@gmail.com"
$email.to:="otherTestAcct@gmail.com"
$status:=$Gmail.mail.send($email)

In the above example, the access token (token.access_token), refresh token (token.refresh_token), and token expiration (tokenExpiration) values are concatenated and sent in a test email to display the status of the latest authentication token used to send the Google email.