Search code examples
pascalquickblox

How to create a QuickBlox session in Pascal


I'm having troubles with creating QuickBlox session on Pascal.

Didn't find any examples here http://quickblox.com/developers/Authentication_and_Authorization#Examples

Does anybody can help me?


Solution

  • Here is how to start with Pascal:

    program qbsession;
    
    uses fphttpclient,sysutils;
    
    var
      HTTP: TFPHTTPClient;
    var 
      qbresponse: String;
    
    const 
      applicationId: String = '92';
      authKey: String = 'wJHdOcQSxXQGWx5';
      authSecret: String = 'BTFsj7Rtt27DAmT';
    
    var
      randomValue: Integer;
      timestamp: Int64;
      body: String;
      signature: String;
    
    begin
      Randomize;
    
      randomValue := Random(5000);
      timestamp := Trunc((Now - EncodeDate(1970, 1 ,1)) * 24 * 60 * 60);
    
      HTTP := TFPHTTPClient.Create(nil);
    
      // This is still to figure out how to do
      // It should be some examples on Pascal how to do it
      // http://quickblox.com/developers/Authentication_and_Authorization#Signature_generation
      signature := '...';
    
      body := 'application_id=' + applicationId + '&auth_key=' + authKey 
       + '&timestamp=' + IntToStr(timestamp) + '&nonce=' + IntToStr(randomValue) 
       + '&signature=' + signature;
    
      WriteLn('body: ' + body);
    
      qbresponse := HTTP.FormPost('http://api.quickblox.com/session.json', body);
    
      WriteLn('Response: ' + qbresponse);
    
      HTTP.Free;
    end.