PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Operating mode of OAuth 2.0 authentication
  • How OpenID authentication works
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
Performs an authentication using:
  • the OAuth 2.0 protocol on any Web service.
  • WindowsLinux the OpenID protocol on any Web service.
Example
// Exemple permettant de récupérer un token pour effectuer une requête sur DropBox
OAuth2Params is OAuth2Parameters
OAuth2Params.ClientID = "01234567890123456789"
OAuth2Params.ClientSecret = "98765432109876543210"
OAuth2Params.AuthURL = "https://www.dropbox.com/oauth2/authorize"
OAuth2Params.TokenURL = "https://api.dropboxapi.com/oauth2/token"
OAuth2Params.AdditionalParameters = "force_reapprove=false"
<COMPILE IF TypeConfiguration<>Site>
//Si ce n'est pas dans un site WEB il faut une URL de redirection en localhost
OAuth2Params.RedirectionURL = "http://localhost:9874/"
<END>
 
// Demande d'authentification: ouvre la fenêtre de login
MonToken is AuthToken = AuthIdentify(OAuth2Params)
 
// Requête authentifiée sur une API de DropBox
req is httpRequest
req.Method = httpPost
req.URL = "https://api.dropboxapi.com/2/files/list_folder"
req.AuthToken = MonToken // Token d'authentification
req.ContentType = "application/json"
vParamAPI is Variant
vParamAPI.path = "/Homework/math"
vParamAPI.recursive = False
vParamAPI.include_media_info = False
vParamAPI.include_deleted = False
vParamAPI.include_has_explicit_shared_members = False
req.Content = VariantToJSON(vParamAPI)
 
réponseHTTP is httpResponse = HTTPSend(req)
let Données = JSONToVariant(réponseHTTP.Content)
// Utilisation des données reçues ...
Syntax
WindowsLinux

Authentication via the OpenID protocol Hide the details

<Result> = AuthIdentify(<Authentication parameters>)
<Result>: AuthToken variable
AuthToken variable corresponding to the token containing the access information for the next authenticated requests.
<Authentication parameters>: OpenIDParameters variable
Name of OpenIDParameters variable containing the parameters describing the elements required to retrieve the access token.

Authentication via the OAuth 2.0 protocol (asynchronous syntax) Hide the details

AuthIdentify(<Authentication parameters> , <WLanguage procedure>)
<Authentication parameters>: OAuth2Parameters variable
Name of OAuth2Parameters variable containing the parameters describing the elements required to retrieve the access token.
<WLanguage procedure>: Procedure name
Name of the WLanguage procedure ("callback") called during the authentication. For more details on this procedure, see Parameters of the procedure used by AuthIdentify.
WindowsLinux

Authentication via the OpenID protocol (asynchronous syntax) Hide the details

AuthIdentify(<Authentication parameters> , <WLanguage procedure>)
<Authentication parameters>: OpenIDParameters variable
Name of OpenIDParameters variable containing the parameters describing the elements required to retrieve the access token.
<WLanguage procedure>: Procedure name
Name of the WLanguage procedure ("callback") called during the authentication. For more details on this procedure, see Parameters of the procedure used by AuthIdentify.
Remarks

Operating mode of OAuth 2.0 authentication

The steps of OAuth 2.0 authentication performed by AuthIdentify are as follows:
  • Running a first HTTP request to ask for an authorization (authorization URL specified in the OAuth2Parameters variable).
  • Opening a window for user identification according to the OAuth 2.0 protocol. The identification interface is given by the service accessed.
  • After identification, the server returns a first authorization code allowing you to ask the resources for an access token. This code is added as parameter of second URL (access token URL specified in the OAuth2Parameters variable).
  • Running the second HTTP request to ask for the access token. The result is a JSON buffer that contains, among other things, the access token ("access_token") that will be used for the authenticated requests. The AuthToken variable contains the information found in this JSON buffer. This access token will be used by the calls to the APIs of Web service.
To use the APIs of the Web service, simply use the HTTPSend function with an httpRequest variable defining the query to be executed.
The AuthToken variable will be assigned to the AuthToken property of the httpRequest variable (see example).
In this case, the server will receive the HTTP "Authorization" header with a value in the following format: "Authorization: Bearer xxx_access_token_xxx".
Caution:
  • If the server does not return the access token in the format of JSON code according to the OAuth2.0 standard, an error will occur and the token will not be retrieved. The server response can be retrieved via the ServerResponse property of the AuthToken variable.
  • If the server does not support the HTTP "Authorization" header for transmitting the access token, this transmission must be done by the developer according to the format expected by the requested service.
    The following example allows you to use the Web service of Facebook. In this case, the access token must be specified on the request URL.

    How OpenID authentication works

    The following are OpenID authentication steps performed by AuthIdentify:
    • Running a first HTTP request to ask for an authorization (authorization URL specified in the OpenIDParameters variable).
    • Opening a window for user identification according to the OpenID protocol. The identification interface is given by the service accessed.
    • Running a second HTTP request to ask for the access token, after the identification. The result is a JSON buffer that contains, among other things, the access token ("access_token") that will be used for the authenticated requests. The AuthToken variable contains the information found in this JSON buffer. This access token will be used by the calls to the APIs of Web service.
    To identify the user, simply use OpenIDReadIdentity and specify the AuthToken variable.
    Caution: If the server does not return the access token in the format of JSON code according to the OAuth2.0 standard, an error will occur and the token will not be retrieved. The server response can be retrieved via the ServerResponse property of the AuthToken variable.
    Related Examples:
    WD OAuth Training (WINDEV): WD OAuth
    [ + ] OAuth allows you to act as user of an external platform without knowing the identifiers (user name and password) of this user.
    Several external platforms (among which Google, Twitter, Facebook) propose APIs for which you have the ability to connect with the information belonging to one of their users. This identification is performed via OAuth. Therefore, all the requests performed on their services (API, ...) will require an access token identifying both the application (the "client") and the user.
    The example proposes to connect to Google and Microsoft via the AuthConnect function and the OAuth2Parameter type.
    Business / UI classification: Business Logic
    Component: wd280ggl.dll
    Minimum version required
    • Version 22
    This page is also available for…
    Comments
    Click [Add] to post a comment