|
|
|
|
- Properties specific to OAuth2Parameters variables
- Operating mode of OAuth 2.0 authentication
- PKCE authentication
OAuth2Parameters (Variable type) In french: OAuth2Paramètres
The OAuth2Parameters type is used to define the information required to authenticate on a web service implementing the OAuth 2.0 standard. These characteristics can be defined and changed using different WLanguage properties. This type of variable must be passed as parameter to AuthIdentify. If authentication is successful, this function returns an Variable of type AuthToken, which can be used to make authenticated requests to the Web service. Remark: For more details on the declaration of this type of variable and the use of WLanguage properties, see Declaring a variable.
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 ConfigurationType<>SITE>
OAuth2Params.RedirectionURL = "http://localhost:9874/"
<END>
MyToken is AuthToken = AuthIdentify(OAuth2Params)
req is httpRequest
req.Method = httpPost
req.URL = "https://api.dropboxapi.com/2/files/list_folder"
req.AuthToken = MyToken
req.ContentType = "application/json"
vAPIParam is Variant
vAPIParam.path = "/Homework/math"
vAPIParam.recursive = False
vAPIParam.include_media_info = False
vAPIParam.include_deleted = False
vAPIParam.include_has_explicit_shared_members = False
req.Content = VariantToJSON(vAPIParam)
HTTPresponse is httpResponse = HTTPSend(req)
let Data = JSONToVariant(HTTPresponse.Content)
Remarks Properties specific to OAuth2Parameters variables The following properties can be used to handle the information required to perform the authentication: | | | Property name | Type used | Effect |
---|
AdditionalParameters | Character string | Parameters of the first authentication request. This string must be formatted as URL parameters. | AuthURL | Character string | Authorization URL to be used (first URL of OAuth 2.0 specification). | ClientID | Character string | Client ID provided by the service when registering the application. | ClientSecret | Character string | Secret application access code. This code is provided by the service when registering the application. | GrantType | Constant | Grant type available. The possible values are: - gtClientCredentials: Authentication without login window. The access authorization is given to the application (not to the user). The token provided to access the resources of the application is linked to the application itself.
- gtAuthorizationCode (Default value): The access authorization is given to the user. A login window appears to let users enter their username and password. The access token is linked to the user.
| New in version 2024Option | Integer constant | Authentication options: - authDefault: OAuth authentication by default.
- authPKCE: Authentication via PKCE (Proof Key for Code Exchange).
Remark: PKCE provides additional security compared to OAuth. In some cases, although PKCE is used, it may be necessary to specify the secret key (ClientSecret property). We advise you to check the information expected by the platform used. | RedirectionURL | Character string | Redirection URL to use during the authentication mechanism. | ResponseType | Character string or constant | Type of response expected. The possible values are: - oauth2ResponseTypeCode (or "Code"): The response is of type "Code".
- oauth2ResponseTypeToken (or "Token"): The response is of type "Token".
The default value is oauth2ResponseTypeCode. Remarks: - For a "personal" authentication, the response type must be "Token".
- In the case of an authentication for an API or service (e.g. Google mail server), the response type must be "Code".
| Scope | Character string | Requested permissions. The possible values are specific to the web service used. The possible values must be separated by a space. | TokenURL | Character string | URL for retrieving the access token to use (second URL of OAuth 2.0 standard). |
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 an OAuth 2.0 authentication window. The authentication window is defined by each service.
- After the authentication, the server returns an authorization code to request 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 elements, the access token ("access_token") to be used for the requests that require authentication. The AuthToken variable contains the information found in this JSON buffer. This access token will be used by the calls to the APIs of the web service.
To use the APIs of the web service, simply use HTTPSend with a variable of type httpRequest defining the request 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.
New in version 2024PKCE authentication PKCE authentication example:
OAuth2Params is OAuth2Parameters
OAuth2Params.ClientID = "D90iXZWlteM3ESORkGkoWyGkJuxifE1z"
OAuth2Params.Option = authPKCE
OAuth2Params.AuthURL = "https://dev-rw5r4o2eowb8s70k.us.auth0.com/authorize"
OAuth2Params.TokenURL = "https://dev-rw5r4o2eowb8s70k.us.auth0.com/oauth/token"
OAuth2Params.RedirectionURL = "http://localhost:9874"
OAuth2Params.Scope = "openid email"
MonToken is AuthToken = AuthIdentify(OAuth2Params)
IF MonToken <> Null _AND_ NOT ErrorOccurred THEN
MonIdentité is OpenIDIdentity = OpenIDReadIdentity(MonToken)
IF MonIdentité.Valid THEN
Trace(MonIdentité.Email)
Trace(MonIdentité.Name)
Trace(MonIdentité.FirstName)
END
ELSE
Info("Echec" + ErrorInfo(errFullDetails))
END
Related Examples:
|
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.
|
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|