OAuth2 | Recover Access Tokens

If the OAuth2 Server is destroyed (because it's restarted) and there are valid Access Tokens issued, these are lost by default. You can recover these Access Tokens using the method AddToken. This method stores the tokens in the OAuth2 Server.

 

Add a Token requires the following information:

 

 

You can save the issued tokens handling the OAuth2AfterAccessToken event.

 


private void OnOAuth2AfterAccessToken(TObject Sender, TsgcWSConnection Connection, TsgcHTTPOAuth2Request OAuth2, 
  string aResponse)
{
  // ... store OAuth2 Token data
}

OAuth2 = new TsgcHTTP_OAuth2_Server.Create();
OAuth2.Apps.AddApp("MyApp", "http://127.0.0.1:8080", "client-id", "client-secret");
OAuth2.AddToken("MyApp", "12146ce12b0e4813987f2794f768905cefc39da6fbd54f6d9b38387489280608", 1622796714, 
  "ef3e3dfa56ec44109c3d345b1541f08e539ce21432d9433099b48a3d08d34bc0");
oServer.Authentication.Enabled = true;
oServer.Authentication.OAuth.OAuth2 = OAuth2;