AccessToken

Description

Sends a request to get the token information.

Applies to

OAuthClient object

Syntax

objectname.AccessToken ( TokenRequest tokenRequest, TokenResponse tokenResponse )

Argument

Description

objectname

A reference to the OAuthClient object.

tokenRequest

A reference to the TokenRequest object specifying the request information.

tokenResponse

A reference to the TokenResponse object into which the function returns the object.

Return value

Integer.

Returns the value as follows. If any argument's value is null, the method returns null.

1 -- Success.

-1 -- A general error occurred.

-2 -- Invalid URL.

-3 -- Cannot connect to the Internet.

-4 -- Timeout.

-7 -- Certification revocation checking has been enabled, but the revocation check failed to verify whether a certificate has been revoked. The server used to check for revocation might be unreachable.

-8 -- SSL certificate is invalid.

-9 -- SSL certificate was revoked.

-10 -- The function is unfamiliar with the Certificate Authority that generated the server's certificate.

-11 -- SSL certificate common name (host name field) is incorrect, for example, if you entered www.appeon.com and the common name on the certificate says www.devmagic.com.

-12 -- SSL certificate date that was received from the server is bad. The certificate has expired.

-13 -- The certificate was not issued for the server authentication purpose.

-14 -- The application experienced an internal error loading the SSL libraries.

-15 -- More than one type of errors when validating the server certificate.

-16 -- The server requires the client to provide a certificate.

-17 -- The client certificate has no private key.

-18 -- The private key in the client certificate is wrong.

-19 -- A security error has occurred. Possible cause: The client does not support the SSL/TLS version required by the server. For example: Client does not support TLS 1.3 when server requires TLS 1.3.

-20 -- Response is unrecognizable. Normally this is because the HTTP version does not match with the version required by the server.

-21 -- TLS 1.3 error. The server does not support TLS 1.3.

Examples

The following example code can obtain the AccessToken of an Office 365 email account. This AccessToken can be used by the SMTPClient object to send emails using the XOAUTH2 type.

Long ll_rc
String ls_token, ls_type, ls_description, ls_uri, ls_state, ls_body
OAuthClient lnv_OAuthClient
TokenRequest lnv_TokenRequest
TokenResponse lnv_TokenResponse

lnv_OAuthClient = Create OAuthClient

lnv_TokenRequest.TokenLocation = "http://login.microsoftonline.com/8bb73260-fca9-43ec-8c48-1e3ce7******/oauth2/v2.0/token"
lnv_TokenRequest.Method = "POST"
lnv_TokenRequest.Clientid = "291335a5-eb93-4ed5-b2e8-770b0bb******"
lnv_TokenRequest.ClientSecret = "RTb8Q~~GR2NGTfTjpDqczxPCqP_pDpYPnw.******" 
lnv_TokenRequest.Scope = "https://outlook.office365.com/.default" 
lnv_TokenRequest.GrantType = "client_credentials"
lnv_TokenRequest.SecureProtocol = 0

ll_rc = lnv_OAuthClient.AccessToken(lnv_TokenRequest, lnv_TokenResponse)

If ll_rc = 1 and lnv_TokenResponse.GetStatusCode() = 200 Then
            ls_token = lnv_TokenResponse.GetAccessToken()
            Messagebox('AccessToken',ls_token)
else
            lnv_TokenResponse.getBody(ls_body)
            lnv_TokenResponse.getTokenerror(ls_type, ls_description, ls_uri, ls_state)
            Messagebox('Error', "lnv_OAuthClient.AccessToken(request, lnv_TokenResponse)=" + String ( ll_rc ) + "~r~nlnv_TokenResponse.getStatuscode()="  + String ( lnv_TokenResponse.getStatuscode()) + "~r~nlnv_TokenResponse.getStatustext()=" + lnv_TokenResponse.getStatustext() +"~r~nlnv_TokenResponse.getBody(ls_body),ls_body="+ls_body )
end if

Destroy lnv_OAuthClient

See also

RequestResource