Hello,
Yes, first save the token, I've updated the demo and now the token is stored in an INIFile (of course you can use any other method, is just for testing purposes)
procedure TFRMOAuth2Server.OAuth2OAuth2AfterAccessToken(Sender: TObject; Connection: TsgcWSConnection; OAuth2: TsgcHTTPOAuth2Request; aResponse: string);
begin
DoLog('Access Token Issued');
// ... save token in INIFile to recover the token if server is restarted
DoSaveToken(oAuth2);
end;
procedure TFRMOAuth2Server.DoSaveToken(const aAuth2: TsgcHTTPOAuth2Request);
var
oINI: TINIFile;
begin
oINI := TINIFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
Try
oINI.WriteString(aAuth2.App.AppName, 'Token', aAuth2.Token.AccessToken);
oINI.WriteString(aAuth2.App.AppName, 'RefreshToken', aAuth2.Token.RefreshToken);
oINI.WriteDateTime(aAuth2.App.AppName, 'Expires', aAuth2.Token.Expires);
Finally
oINI.Free;
End;
end;
And when the server starts, load the tokens saved.
Next week I will release a new sgcWebSockets version.
Kind Regards,
Sergio