TsgcHTTP_OAuth2_Client › Events › OnAfterRefreshToken
Fires when the token endpoint returns a new access token from a refresh_token grant.
property OnAfterRefreshToken: TsgcOnAuth2AfterRefreshToken;
// TsgcOnAuth2AfterRefreshToken = procedure(Sender: TObject; const Access_Token, Token_Type, Expires_In, Refresh_Token, Scope, RawParams: String; var Handled: Boolean) of object
—
OnAfterRefreshToken is raised when the authorization server answers the refresh_token grant with a fresh access token. Access_Token is the new bearer (or DPoP) token, Token_Type and Expires_In describe it, Refresh_Token is either the original refresh token or a rotated one (many providers rotate refresh tokens on every use, so the application must replace the stored copy with this value), Scope reports the granted scopes, and RawParams contains the full raw JSON response. The AccessToken, CurrentExpiresIn and CurrentRefreshToken properties are updated automatically before the event fires.
procedure OnOAuth2AfterRefreshToken(Sender: TObject; const Access_Token, Token_Type, Expires_In,
Refresh_Token, Scope, RawParams: string; var Handled: Boolean);
begin
DoLog('AfterRefreshToken: new access token valid for ' + Expires_In + ' seconds');
// providers that rotate refresh tokens require the new value to be persisted
if Refresh_Token <> '' then
SaveRefreshToken(Refresh_Token);
end;