TsgcHTTP_OAuth2_ServerMethods › RegisterApp

RegisterApp Method

Registers a new OAuth 2.0 client application on the server and returns its generated credentials.

Syntax

function RegisterApp(const aName, aRedirectURI: String; var ClientId, ClientSecret: string): Boolean;

Parameters

NameTypeDescription
aNameconst StringLogical name of the application (for example, 'MyApp'). Must be unique on the server and is used to correlate tokens with the app.
aRedirectURIconst StringRedirect URI registered for the authorization code flow (for example, http://127.0.0.1:8080). Incoming authorization requests must supply a matching redirect_uri.
ClientIdvar stringOutput parameter that receives the generated client identifier. This value is public and is used by the client to identify itself.
ClientSecretvar stringOutput parameter that receives the generated client secret. Must be kept confidential and shared only with the client application.

Return Value

Returns True when the application is registered and the credentials are filled in; False when a duplicate aName already exists. (Boolean)

Remarks

Use RegisterApp during server configuration to declare every client application that is allowed to obtain tokens. By default the registered application accepts all grant types (authorization code, client credentials, password, device code) and a 1-hour access-token lifetime; those defaults can be adjusted through the Apps collection. Call UnRegisterApp to remove it.

Example

var
  vClientId, vClientSecret: string;
begin
  if OAuth2.RegisterApp('MyApp', 'http://127.0.0.1:8080',
    vClientId, vClientSecret) then
    WriteLn(Format('Client registered: %s / %s', [vClientId, vClientSecret]));
end;

Back to Methods