xcall OAUTH2, opcode, status, clientid$, clientsecret$, option, auth'endpoint$, token'endpoint$, challenge$, scope$, refresh'token$, response$, handle, stsmsg$ {,file$}
The subroutine OAUTH2 implements the industry-standard OAUTH2 protocol for authorization via the ASHNET library update 1.12.163. It provides a means of obtaining an OAUTH2 access token needed for some modern web services, such as Gmail when "less secure applications" is not enabled.
Parameters
Name |
Type |
I/O |
Description |
opcode |
Num |
in |
1: Request the auth url 2: Step 2 to request the token after signing in on web 3: Request a refresh token for previously authorized service |
status |
Signed Int |
out |
Return status: 0=ok, else ASHNET_xxx errors |
clientid$ |
String |
in |
Client id previously assigned by service provider |
clientsecret$ |
String |
in |
Client secret previously assigned (or negotiated) by service provider |
option |
|
in |
For opcode 1, port; for opcode 2, timeout (in secs) |
auth'endpoint$ |
String |
in |
URL determined by service provider. For example, Google uses "https://accounts.google.com/o/oauth2/v2/auth" |
token'endpoint$ |
String |
in |
URL determined by service provider. For example, Google's API uses "https://www.googleapis.com/oauth2/v4/token" |
challenge$ |
String |
in |
Optional challenge string |
scope$ |
String |
in |
Scope of the request, typically a URL, e.g. "https://mail.google.com" |
refresh'token$ |
String |
in |
Token used to request a refresh authorization (op 3) |
response$ |
String |
out |
Response (typically in the form of a JSON document). Argument does not auto-expand; make sure it is sufficiently large! |
handle |
X8 |
in/out |
Value returned by op 1 and passed to op 2 |
stsmsg$ |
String |
out |
Status message |
file$ |
String |
in |
For op 1, if specified, the response tokens are written directly to the specified file. For op 3, if specified and the refresh_token$ parameter is "", then the refresh_token string is retrieved from the file, and the file is updated with the new access_token. In either case, the response is also returned in the response$ parameter. |
See sample program OAUTH2 in EXLIB:[908,77]