TsgcHTTP_OAuth2_ServerEvents › OnOAuth2Authentication

OnOAuth2Authentication Event

Validates user credentials submitted on the sign-in page during the authorize flow.

Syntax

property OnOAuth2Authentication: TsgcHTTPOAuth2AuthenticationEvent;
// TsgcHTTPOAuth2AuthenticationEvent = procedure(Connection: TsgcWSConnection; OAuth2: TsgcHTTPOAuth2Request; aUser, aPassword: String; var Authenticated: Boolean) of object

Default Value

Remarks

OnOAuth2Authentication is raised when the user submits the built-in sign-in page during the authorization code or password grant. aUser and aPassword carry the credentials posted by the browser (or sent by a resource-owner-password client) and OAuth2 exposes the request context (client_id, scope, redirect_uri, state). Verify the credentials against your own store (LDAP, database, SSO) and set Authenticated to True to let the server continue with code issuance and consent, or leave it False to reject the sign-in and re-display the page. The component does not persist passwords; they are only available inside this event.

Example


procedure OnOAuth2Authentication(Connection: TsgcWSConnection; OAuth2: TsgcHTTPOAuth2Request;
  aUser, aPassword: string; var Authenticated: Boolean);
begin
  Authenticated := ValidateUserAgainstDatabase(aUser, aPassword);
  if not Authenticated then
    DoLog('OAuth2 sign-in failed for user: ' + aUser);
end;

Back to Events