TsgcHTTP_OAuth2_Server › Methods › RegisterProvider
Registers an external identity provider (Google, GitHub, Microsoft, etc.) so the server can delegate federated sign-in to it.
function RegisterProvider(const aName, aClientId, aClientSecret, aAuthorizeURL, aTokenURL, aScope, aURL, aCallbackURL: string): Boolean;
| Name | Type | Description |
|---|---|---|
aName | const string | Unique display name of the provider (for example, 'Google', 'GitHub', 'Microsoft'). |
aClientId | const string | Client identifier issued to this server by the external identity provider. |
aClientSecret | const string | Client secret issued to this server by the external identity provider. Must be kept confidential. |
aAuthorizeURL | const string | Authorization endpoint of the external provider (where the user is redirected to sign in). |
aTokenURL | const string | Token endpoint of the external provider (where the authorization code is exchanged for an access token). |
aScope | const string | Space-separated list of scopes requested from the external provider (for example, 'openid email profile'). |
aURL | const string | UserInfo/resource URL used to retrieve the authenticated user profile from the external provider. |
aCallbackURL | const string | Public callback URL on this server that the external provider should redirect to after user authorization. |
Returns True when the provider is added to the internal federation list; False when a provider with the same aName is already registered. (Boolean)
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.
// 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');