Si el OAuth2 Server se destruye (porque se reinicia) y existen Access Tokens válidos emitidos, estos se pierden por defecto. Puede recuperar estos Access Tokens utilizando el método AddToken. Este método almacena los tokens en el OAuth2 Server.
Añadir un token requiere la siguiente información:
Puede guardar los tokens emitidos gestionando el evento OAuth2AfterAccessToken .
procedure OnOAuth2AfterAccessToken(Sender: TObject; Connection: TsgcWSConnection; OAuth2: TsgcHTTPOAuth2Request;
aResponse: string);
begin
// ... store OAuth2 Token data
end;
OAuth2 := TsgcHTTP_OAuth2_Server.Create(nil);
OAuth2.Apps.AddApp('MyApp', 'http://127.0.0.1:8080', 'client-id', 'client-secret');
OAuth2.AddToken('MyApp', '12146ce12b0e4813987f2794f768905cefc39da6fbd54f6d9b38387489280608', EncodeDate(2022,1,1),
'ef3e3dfa56ec44109c3d345b1541f08e539ce21432d9433099b48a3d08d34bc0');
oServer.Authentication.Enabled := True;
oServer.Authentication.OAuth.OAuth2 := OAuth2;