|
|
|
|
|
AuthRefreshToken (Function) In french: AuthRenouvelleToken Refreshes a user's OAuth2 token when it expires.
SessionToken is AuthToken
bufToken is Buffer
sAuthPersistenceFile is string = fDataDir() + [fSep] + "AuthSession.bin"
m_Svc is OAuth2Parameters
m_Svc.ClientID = "my_client_id"
m_Svc.ClientSecret = "123456-my_client_secret-387854"
m_Svc.AuthURL = "https://api.server.com/connect/authorize"
m_Svc.TokenURL = "https://api.server.com/connect/token"
m_Svc.Scope = "openid profile offline_access"
m_Svc.RedirectionURL = "http://localhost:3333"
IF fFileExist(sAuthPersistenceFile) THEN
WHEN EXCEPTION IN
bufToken = fLoadBuffer(sAuthPersistenceFile)
Deserialize(SessionToken, bufToken, psdBinary)
DO
ToastDisplay("Invalid stored session")
ELSE
IF (SessionToken.ExpirationDate-1 min < SysDateTime()) _AND_
SessionToken.Refresh <> "" THEN
SessionToken = AuthRefreshToken(SessionToken)
IF SessionToken.Valid THEN
Serialize(SessionToken, bufToken, psdBinary)
fSaveBuffer(sAuthPersistenceFile, bufToken)
ELSE
Error("Unable to refresh session")
END
END
END
END
IF NOT SessionToken.Valid THEN
SessionToken = AuthIdentify(m_Svc)
IF SessionToken.Valid THEN
Serialize(SessionToken, bufToken, psdBinary)
fSaveBuffer(sAuthPersistenceFile, bufToken)
END
END
IF NOT SessionToken.Valid THEN
Error("Unable to open the session", ErrorInfo())
ELSE
MyIdentity is OpenIDIdentity = OpenIDReadIdentity(SessionToken)
IF MyIdentity.Valid THEN
Info("Connection successful: " + MyIdentity.Source)
ELSE
Info("Valid connection, but invalid identity ", InfoError())
END
END
Syntax
<Result> = AuthRefreshToken(<Token>)
<Result>: AuthToken variable AuthToken variable that corresponds to the refreshed token. <Token>: AuthToken variable Name of the AuthToken variable that corresponds to the token to be refreshed. This token is returned by AuthIdentify, for example. Remarks Some tokens cannot be refreshed. The Refresh property of the AuthToken variable can be used to determine if the token can be refreshed.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|