Se o OAuth2 Server for destruído (porque foi reiniciado) e houver Access Tokens válidos emitidos, eles são perdidos por padrão. Você pode recuperar esses Access Tokens usando o método AddToken. Este método armazena os tokens no OAuth2 Server.
Adicionar um Token requer as seguintes informações:
Você pode salvar os tokens emitidos tratando o 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;