ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Communication / Managing the OAuth 2.0 protocol
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Refreshes a user's OAuth2 token when it expires.
New in version 2024
Android This function is now available for Android applications.
Android Widget This function is now available in Android widget mode.
Example
// Session OAuth
TokenSession is AuthToken // Session OAuth
bufToken is Buffer
sFichierPersistanceAuth is string = fDataDir() + [fSep] + "AuthSession.bin"
// Paramètres de connexion OAuth
m_Svc is OAuth2Parameters         // Service OAuth (Login)
m_Svc.ClientID = "mon_client_id"
m_Svc.ClientSecret = "123456-mon_client_secret-387854"
m_Svc.AuthURL = "https://api.serveur.com/connect/authorize"
m_Svc.TokenURL = "https://api.serveur.com/connect/token"
m_Svc.Scope = "openid profile offline_access"
m_Svc.RedirectionURL = "http://localhost:3333"

// ou
// m_Svc est un OpenIDParamètres         // Service OAuth (Login)
// m_Svc.ClientID = "mon_client_id"
// m_Svc.ClientSecret = "123456-mon_client_secret-387854"
// m_Svc.URLConfiguration = "https://api.serveur.com/.well-known/openid-configuration"
// m_Svc.URLRedirection = "http://localhost:3333"

// Token précédemment mémorisé?
IF fFileExist(sFichierPersistanceAuth) THEN
WHEN EXCEPTION IN
// Charge la session
bufToken = fLoadBuffer(sFichierPersistanceAuth)
Deserialize(TokenSession, bufToken, psdBinary)             
DO
// Erreur de relecture du token
ToastDisplay("Session mémorisée invalide")
ELSE
// Token est expiré ou va expirer dans la minute qui arrive
// et il est renouvelable?  
IF (TokenSession.ExpirationDate-1 min < SysDateTime()) _AND_ 
TokenSession.Refresh <> "" THEN
TokenSession = TokenSession.RenouvelleToken()
IF TokenSession.Valid THEN
Serialize(TokenSession, bufToken, psdBinary)
fSaveBuffer(sFichierPersistanceAuth, bufToken) 
ELSE
Error("Echec du renouvellement de la session")
END
END 
END
END
IF NOT TokenSession.Valid THEN
// Connexion au service
TokenSession = AuthIdentify(m_Svc)    
IF TokenSession.Valid THEN
// Sauvegarde du token
Serialize(TokenSession, bufToken, psdBinary)
fSaveBuffer(sFichierPersistanceAuth, bufToken)
END
END
IF NOT TokenSession.Valid THEN
Error("Impossible de démarrer la session", ErrorInfo())
ELSE
MonIdentité is OpenIDIdentity = OpenIDReadIdentity(TokenSession)
IF MonIdentité.Valid THEN
// Les informations récupérables sur l'identité de la personne connectée 
// dépendent du site qui permet l’authentification
Info("Connexion OK: " + MonIdentité.Source)
ELSE
Info("Connexion valide, mais Ã©chec identité ", ErrorInfo())
END
END
Syntax
<Result> = <Token>.RefreshToken()
<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.
Component: wd290ggl.dll
Minimum version required
  • Version 26
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 11/22/2023

Send a report | Local help