Trochę się męczyłem wiec daje dla gotowca jak w Lazarus pobrać "token_type": "Bearer"
Specyfikacja API ( https://auth0.com/docs -fajne środowisko jak ktoś chce się podszkolić trial 22 dni!)
curl --request POST
--url 'https://dev-qq/oauth/token'
--header 'content-type: application/x-www-form-urlencoded'
--data grant_type=client_credentials
--data client_id=YOUR_CLIENT_ID
--data client_secret=YOUR_CLIENT_SECRET
--data audience=YOUR_API_IDENTIFIERDodaj cytat...
jedyne na co trzeba zwrócić uwagę to składnia Params tu miałem trochę problemu oryginalnie składnia wyglądała tak:
Params : string = '{"title": "titre","body": "corps","userId": 1}';
uses fphttpclient, opensslsockets;
procedure TForm1.Button11Click(Sender: TObject);
var
Client: TFPHttpClient;
Response: TStringStream;
Params: string = 'grant_type=client_credentials&client_id=SgJdGB38LFzn0m&client_secret=xku-oYvTfSgODXmU6854i3qIKaUEfWl6JnfIq91hwZUiyK9&audience=https://devauth0.com/api/v2/';
begin
Client := TFPHttpClient.Create(nil);
Client.AddHeader('Content-Type', 'application/x-www-form-urlencoded');
Client.AllowRedirect := true;
Client.RequestBody := TRawByteStringStream.Create(Params);
Response := TStringStream.Create('');
try
try
Client.Post('https://dev-qq/oauth/token', Response);
form1.Memo1.Lines.Add('Response Code: ' + IntToStr(Client.ResponseStatusCode));
Memo1.Append('Réponse : ' + Response.DataString);
except on E: Exception do
form1.Memo1.Lines.Add('Something bad happened: ' + E.Message);
end;
finally
Client.RequestBody.Free;
Client.Free;
Response.Free;
end;
end;
fphttpclient gotowiec do pobrania tokena może się komuś przyda
var
Indy : TIdHTTP;
IdSSL : TIdSSLIOHandlerSocketOpenSSL;
Data : String;
JSONToSend : TStringStream;
Response: string;
begin
Indy := TIdHTTP.Create(nil);
try
IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(Indy);
IdSSL.SSLOptions.SSLVersions := [sslvTLSv1_2];
Indy.IOHandler := IdSSL;
Indy.Request.BasicAuthentication := False;
Indy.Request.CustomHeaders.Values['content-type'] :='application/x-www-form-urlencoded';
Data:='grant_type=client_credentials&client_id=SgJdGB38LFzn0m&client_secret=xku-oYvTfSgODXmU6854i3qIKaUEfWl6JnfIq91hwZUiyK9&audience=https://devauth0.com/api/v2/';
JSONToSend := TStringStream.Create(Data,TEncoding.UTF8);
try
Response := Indy.Post('https://dev-qq/oauth/token',JSONToSend);
finally
JSONToSend.Free;
end;
memo1.Text := Response;
finally
Indy.Free;
end;
end;
Indy gotowiec do indy potrzebne są :
IdSSLIOHandlerSocketOpenSSL1
i IdHTTP1
Czy macie pomysł jak inaczej wprowadzić Data np. coś takiego
P1: grant_type=client_credentials
P2: client_id=SgJdGB38LFzn0m
P3: client_secret=xku-oYvTfSgODXmU6854i3qIKaUEfWl6JnfIq91hwZUiyK9
P4: audience=https://devauth0.com/api/v2/