Custom REST and OAuth services
Use the Cloud Pack infrastructure when an application needs to wrap a REST service that is not already exposed as a ready-made component.
Choose the base
| Base | Use when |
|---|---|
TTMSFNCCloudOAuth |
The service uses OAuth 2.0 and needs a browser consent flow, token exchange, token testing, and token persistence. |
TTMSFNCSimpleCloudOAuth |
The service has no OAuth flow but should reuse the Cloud Pack request pipeline. |
TTMSFNCRESTClient |
The application needs configurable REST requests without creating a new component class. |
TTMSFNCCloudOAuth descendants implement four service-specific steps: building the authorization URL, exchanging the authorization code for tokens, testing whether tokens are valid, and interpreting the token-test response.
OAuth service shape
A custom OAuth service descends from TTMSFNCCloudOAuth and overrides the service-specific methods:
type
TTMSFNCCloudSample = class(TTMSFNCCloudOAuth)
protected
function GetAuthenticationURL: string; override;
procedure RetrieveAccessToken; override;
public
procedure TestTokens(const ATestTokensRequestResultEvent: TTMSFNCCloudBaseRequestResultEvent = nil); override;
function GetTestTokensResult(const ARequestResult: TTMSFNCCloudBaseRequestResult): Boolean; override;
end;
The authentication flow is:
- Build the provider authorization URL with the client ID, callback URL, requested scopes, and provider-specific query parameters.
- Let the provider redirect back to the component's local callback server.
- Exchange the returned authentication code for an access token and, when available, a refresh token.
- Test the tokens against a provider endpoint and return
Trueonly when the response proves that the component can call the API.
After those steps succeed, call service requests through the component request object or through service-specific wrapper methods.
Simple service shape
Use TTMSFNCSimpleCloudOAuth for unauthenticated or API-key based services where no OAuth browser flow is needed. Configure the Request object with host, path, query string, HTTP method, body data, and result target, then execute the request asynchronously.
For low-level request tooling, use the REST Client guides. The REST Client is often the fastest option when the application only needs to call one or two endpoints and does not need a reusable component abstraction.