OAuth2WebClient (FB)

FUNCTION_BLOCK OAuth2WebClient EXTENDS CBM.ETrigTo

Function block to a send a request via 2 legged OAuth2 authentication. Supported request types (flows): client_credentials, password and device code.

InOut:

Scope

Name

Type

Initial

Comment

Inherited from

Input

xExecute

BOOL

Rising edge: Action starts
Falling edge: Resets outputs
If a falling edge occurs before the function block has completed its action, the outputs operate in the usual manner and are only reset if either the action is completed or in the event of an error. In this case, the corresponding output values (xDone, xError) are present at the outputs for exactly one cycle.

ETrigTo

udiTimeOut

UDINT

Defines the time (µs) after which an FB (e.g. requiring an external acknowledgement) aborts operation due to a timeout with error message.

ETrigTo

Output

xDone

BOOL

TRUE: Action successfully completed

ETrigTo

xBusy

BOOL

TRUE: Function block active

ETrigTo

xError

BOOL

TRUE: Error occurred, function block aborts action
FALSE: No error

ETrigTo

Input

sURL

STRING(1024)

URL of the web server (resource server). Leave empty for autorization requests without resource requests.

eRequestType

REQUEST_TYPE

REQUEST_TYPE.GET

Type of the request: POST or GET

eContentType

CONTENT_TYPE

CONTENT_TYPE.APPLICATION_FORM

HTTP Content-Type of the request

pwsAdditionalHeader

POINTER TO WSTRING

Additional HTTP header

pwsPostValue

POINTER TO WSTRING

Post parameter

sAuthorizationServerURL

STRING(1024)

URL of authorization server

pwsAdditionalAuthenticationHeader

POINTER TO WSTRING

Additional Auth HTTP header

itfOAuth2Credentials

IOAuth2Credentials

OAuth2 credentials

xCloseConnection

BOOL

FALSE

Close the connection after each request.

itfTLSContext

NBS.ITLSContext

0

Encapsulates all the data neccecray to handle encrypted tcp connections

Static initialization, as shown in the following code snippet.

VAR
    commonName : STRING := 'MyRrasPi';
    ciCertInfo : NBS.CERT_INFO := (psInfo:=ADR(commonName), udiSize:=LEN(commonName));
    myTLSContext : NBS.TLSContext := (
        ePurpose:=NBS.PURPOSE.CLIENT_SIDE,
        sUseCaseName:='NBSTest',
        sTLSVersion:='1.3',
        ciCertInfo:=ciCertInfo,
        udiVerificationMode:=2
    );
END_VAR

itfAsyncProperty

NBS.IAsyncProperty

0

Runs the connect process in a own background task, usage see library Net Base Services

udiPostValueLength

UDINT

0

Length of pwsPostValue in bytes. udiPostValueLength = 0: The null character of pwsPostValue^ is used to calculate the content length. udiPostValueLength > 0: The specified length is used for the content length. This can be used to send binary data.

oAuth2PersistentTokens

REFERENCE TO OAuth2PersistentTokens

Reference to the tokens. The structure can be used to store the tokens, e.g., via the Persistence Manager.

Output

eError

ERROR

Current error state

httpResult

HttpResult

The result of the request

oAuth2DeviceCodeInfo

OAuth2DeviceAuthInfo

Information to register the device (device code)

eState

OAuth2State

The current state of the request

Methods:

Structure: