Connections Concept
How the
pfx-restcomponent resolves authentication and base URLs through named connections.
Overview
Every pfx-rest endpoint can reference a named connection via the connection parameter. The connection determines:
-
The base URL for the request
-
The authentication strategy (none, Basic, JWT, OAuth2)
-
Optional default headers
-
Optional re-authentication behavior on specific HTTP error codes
If no connection is specified (or the named connection is not found and failIfNoConnection=false), the component falls back to a default no-auth connection.
Connection Types
REST Public (rest-public)
No authentication. Used for accessing public APIs.
|
Field |
Description |
|---|---|
|
|
Base URL for all requests |
|
|
Optional default headers sent with every request |
REST Basic (rest-basic)
HTTP Basic authentication. Credentials are sent with every request.
|
Field |
Default |
Description |
|---|---|---|
|
|
|
Base URL for all requests |
|
|
|
Optional default headers |
|
|
|
Basic auth username |
|
|
|
Basic auth password |
|
|
|
Header name for the auth credential |
|
|
|
Prefix for the header value |
REST JWT (rest-jwt)
Token-based authentication. A token is obtained from an auth endpoint before the first request and refreshed when it expires.
|
Field |
Default |
Description |
|---|---|---|
|
|
|
Base URL for all requests |
|
|
|
Optional default headers |
|
|
|
URL of the token endpoint |
|
|
|
Auth username |
|
|
|
Auth password |
|
|
|
Template body for the token request |
|
|
|
Content type for the token request |
|
|
|
Header name for the token |
|
|
|
Prefix for the token header value |
|
|
|
JSON key in the auth response containing the token |
|
|
|
JSON key for token expiration |
|
|
|
Location of the expiration key (e.g., in a nested object) |
|
|
|
Multiplier applied to the expiration value |
|
|
|
Comma-separated HTTP codes that trigger re-authentication |
REST OAuth2 (rest-oauth2)
OAuth2 authentication. Similar to JWT but supports client credentials and scope.
|
Field |
Default |
Description |
|---|---|---|
|
|
|
Base URL for all requests |
|
|
|
Optional default headers |
|
|
|
URL of the token endpoint |
|
|
|
OAuth2 username |
|
|
|
OAuth2 password |
|
|
|
OAuth2 client ID |
|
|
|
OAuth2 client secret |
|
|
|
OAuth2 scope |
|
|
|
Template body for the token request |
|
|
|
Content type for the token request |
|
|
|
Header name for the token |
|
|
|
Prefix for the token header value |
|
|
|
JSON key in the auth response containing the token |
|
|
|
JSON key for token expiration |
|
|
|
Location of the expiration key |
|
|
|
Multiplier applied to the expiration value |
|
|
|
Comma-separated HTTP codes that trigger re-authentication |
Authentication Template Placeholders
Token-based connections (JWT, OAuth2) use authRequestTemplate with placeholder strings that are resolved at runtime:
|
Placeholder |
Resolved From |
|---|---|
|
|
Connection username |
|
|
Connection password |
|
|
Connection clientId (OAuth2 only) |
|
|
Connection clientSecret (OAuth2 only) |
|
|
Connection scope (OAuth2 only) |
Example: The default OAuth2 template is:
{"grant_type": "password","client_id": "::clientId","client_secret": "::clientSecret","username": "::username","password":"::password"}
At runtime, ::clientId is replaced with the actual clientId value from the connection, and so on.
Re-authentication on Error Codes
For token-based connections (JWT, OAuth2), the reAuthOnCodes field accepts a comma-separated list of HTTP status codes (e.g., 400,401,404). When any of these codes are returned from a request, the component will:
-
Discard the current token
-
Request a new token from the auth endpoint
-
Retry the original request with the new token
This is useful for systems like Salesforce where tokens may be invalidated unexpectedly.
SSL Certificates
When the target API uses a self-signed or custom SSL certificate, the certificate can be configured at the connection level. The component's HTTP client will trust the configured certificate for that connection.
Connection Behavior Parameter
|
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
|
When |
Common Pitfalls
|
Pitfall |
Resolution |
|---|---|
|
Connection name misspelled or not deployed |
Enable |
|
OAuth2 token expires mid-batch |
Set |
|
Wrong |
Most OAuth2 providers expect |
|
Placeholders not replaced in template |
Ensure the connection fields ( |
|
Base URL missing trailing slash vs. URI having leading slash |
Be consistent: if |