In this lesson, we’ll guide you through implementing authentication in your DataFlex Web API using the cWebApiAuthModifier. Let’s dive right in!
Swagger UI expects (in JSON):
basicAuth {
type: “http”
scheme: “basic”
}
In DataFlex this would be implementing as the following:
Struct basicAuth
String type
String scheme
End_struct
Object oBasicAuth is a cWebApiAuthModifier
Set psSecuritySchemaName to “BasicAuth”
Procedure OnDefineAuthRules Variant ByRef vSecurityStruct
basicAuth basicauth
Forward send OnDefineAuthRules (&vSecurityStruct)
Move “http” to basicauth.type
Move “basic” to basicauth.scheme
Move basicauth to vSecurityStruct
End_Procedure
End_Object
This controls if endpoints show up as secured in Swagger UI.
Step 4: Create a Login Endpoint
Username (Write only, sent with requests but not returned in response)
Password (Same as username)
An additional read-only field returned upon successful login.
Use the OnSetCalculatedValue in this additional field to return a token/key after successful login.
Quick Pro Tip: To make a verb public (no auth needed), just set pbSecure to false for that verb. The API will let everyone access it.