1

We have an ISAPI webbroker application developed in Delphi Seattle 10. It has support for sign in using SSO Azure.

We use TRest components to get the accesscode and graph data.

It works most of them time , but 1 or 2 times per day it gives us this error:

REST request failed: Error opening request: (6) The handle is invalid

Setup is : we have 3 rest components in a datammodule

     RESTClientsso: TRESTClient;
     RESTRequestsso: TRESTRequest;
     RESTResponseSSO: TRESTResponse;

We assign the Rest Component to a class

AzureSSOClass:=TAzureSSOClass.Create;
try
  AzureSSOClass.RESTClientSSO:=RESTClientsso;
  AzureSSOClass.RESTRequesTSSO:=RESTRequestsso;
  AzureSSOClass.RESTResponseSSO:=RESTResponseSSO;    

Then we have this function that gives the alert on RESTRequestSSO.Execute;

function TAzureSSOClass.getAccessCode: Boolean;
var

  LJSONObject : TJSONObject;
  infoRest : String;
  s:String;
begin
 result :=true;

 s:='https://login.microsoftonline.com/';
 s:=s+FTenant+'/oauth2/token';
 RESTClientSSO.BaseURL:=s;

 RESTClientSSO.HandleRedirects:=true;
 RESTRequestSSO.Method :=TRESTRequestMethod.rmPOST;

 // paramter..
 RestRequestSSO.Params.Clear;
 RestRequestSSO.Params.AddItem('grant_type', 'authorization_code');
 RestRequestSSO.Params.AddItem('code',   Fcode);
 RestRequestSSO.Params.AddItem('client_id', FClientID);
 RestRequestSSO.Params.AddItem('resource', 'https://graph.windows.net');
 RestRequestSSO.Params.AddItem('client_secret',FClientSecret);

 RESTRequestSSO.Execute;  // here we get the error

  inforest:=RESTResponseSSO.Content;
   try
      LJSONObject := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(infoRest), 0) as TJSONObject;
      FAccessCode:=LJSONObject.Values['access_token'].Value;
      Fidtoken:=LJSONObject.Values['access_token'].Value;
      GetPayload;
      ParseToken;
   finally
    LJSONObject.Free
   end;

  if FAccessCode =''  then
  begin
   Ferror:='error getting access code';
   result:=false;
  end;

end;

Any idea why this happens , is it not a good idea to do this inside a webbroker application ?

bsw
  • 153
  • 13

0 Answers0