ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Communication / Managing the OAuth 2.0 protocol
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Refreshes a user's OAuth2 token when it expires.
Example
// OAuth session
SessionToken is AuthToken // OAuth session
bufToken is Buffer
sAuthPersistenceFile is string = fDataDir() + [fSep] + "AuthSession.bin"
// OAuth connection parameters
m_Svc is OAuth2Parameters         // OAuth Service (Login)
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"

// or
// m_Svc IS OpenIDParameters         // Service OAuth (Login)
// m_Svc.ClientID = "my_client_id"
// m_Svc.ClientSecret = "123456-my_client_secret-387854"
// m_Svc.ConfigurationURL = "https://api.server.com/.well-known/openid-configuration"
// m_Svc.RedirectionURL = "http://localhost:3333"

// Token previously stored?
IF fFileExist(sAuthPersistenceFile) THEN
	WHEN EXCEPTION IN
		// Loads the session
		bufToken = fLoadBuffer(sAuthPersistenceFile)
		Deserialize(SessionToken, bufToken, psdBinary)             
	DO
		// Unable to read token again
		ToastDisplay("Invalid stored session")
	ELSE
		// Token has expired or will expire in the next minute
		// and it is renewable?  
		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
	// Connect to the service
	SessionToken = AuthIdentify(m_Svc)    
	IF SessionToken.Valid THEN
		// Save token
		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
		// The information that can be retrieved about the identity of the connected user 
		// depend on the site that used for the authentication
		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.
Component: wd300ggl.dll
Minimum version required
  • Version 26
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 12/10/2024

Send a report | Local help