TsgcHTTP_OAuth2_ServerMethods › RegisterProvider

RegisterProvider Method

Registers an external identity provider (Google, GitHub, Microsoft, etc.) so the server can delegate federated sign-in to it.

Syntax

function RegisterProvider(const aName, aClientId, aClientSecret, aAuthorizeURL, aTokenURL, aScope, aURL, aCallbackURL: string): Boolean;

Parameters

NameTypeDescription
aNameconst stringUnique display name of the provider (for example, 'Google', 'GitHub', 'Microsoft').
aClientIdconst stringClient identifier issued to this server by the external identity provider.
aClientSecretconst stringClient secret issued to this server by the external identity provider. Must be kept confidential.
aAuthorizeURLconst stringAuthorization endpoint of the external provider (where the user is redirected to sign in).
aTokenURLconst stringToken endpoint of the external provider (where the authorization code is exchanged for an access token).
aScopeconst stringSpace-separated list of scopes requested from the external provider (for example, 'openid email profile').
aURLconst stringUserInfo/resource URL used to retrieve the authenticated user profile from the external provider.
aCallbackURLconst stringPublic callback URL on this server that the external provider should redirect to after user authorization.

Return Value

Returns True when the provider is added to the internal federation list; False when a provider with the same aName is already registered. (Boolean)

Remarks

Registered providers appear on the sign-in page rendered by the OAuth2 server so users can choose federated login. When a user picks a provider, the server redirects to aAuthorizeURL, then handles the callback on aCallbackURL, exchanges the code at aTokenURL and finally calls aURL to fetch the user profile. Call UnRegisterProvider or ClearProviders to remove entries.

Example

// Register Google as an external identity provider
OAuth2.RegisterProvider('Google',
  'your-google-client-id',
  'your-google-client-secret',
  'https://accounts.google.com/o/oauth2/v2/auth',
  'https://oauth2.googleapis.com/token',
  'openid email profile',
  'https://www.googleapis.com/oauth2/v3/userinfo',
  'https://www.esegece.com/sgc/oauth2/callback');

Back to Methods