Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 19-12-2023
david.camaleon david.camaleon is offline
Miembro
 
Registrado: oct 2008
Posts: 18
Poder: 0
david.camaleon Va por buen camino
Autorizacion Bearer Token en delphi

Buenos días,

Estoy tratando de obtener una lista de productos de un servicio API Rest que necesita autorización Bearer Token. Usando Postman funciona perfectamente una vez obtenido el token de autorización. Pero en delphi no se muy bien como hacerlo. mi Código es el siguiente;


Código Delphi [-]
procedure TFMain.Button2Click(Sender: TObject);
var
  token: WideString;
  RESTClient: TRESTClient;
  RESTRequest: TRESTRequest;
  RESTResponse: TRESTResponse;
  Authenticator:TOAuth2Authenticator;

begin
  Token:='xxxxxxxxxxxxxxxxxxxxxxxxxxx'

// Creamos componentes para las peticiones http
  RESTClient    := TRESTClient.Create(nil);
  RESTRequest   := TRESTRequest.Create(nil);
  RESTResponse  := TRESTResponse.Create(nil);
  Authenticator := TOAuth2Authenticator.Create(nil);

  try

    // Configurar el cliente REST
    REstClient.BaseURL        := 'https://api.server.es';    
    RESTClient.Accept         := 'application/json';
    RESTClient.Authenticator  := Authenticator;

    // Configurar el autenticador OAuth2
    Authenticator.AccessTokenEndpoint := UrlAutenticacion;
    Authenticator.AccessToken         := token;
    Authenticator.ClientID               := 'xxxxx; // UserID
    Authenticator.ClientSecret         := 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz';
    Authenticator.TokenType           := TOAuth2TokenType.ttBEARER;


    // Configurar la solicitud REST
    RESTRequest.Client    := RESTClient;
    RESTRequest.Response  := RESTResponse;
    RESTRequest.Method    := TRESTRequestMethod.rmGET;
    RESTRequest.Resource  := '/api/v2/products/GetAllProducts';

    // Realizar la solicitud
    RESTRequest.Execute;

    // Mostrar la respuesta
    Respuesta.Text:=Response.Content;

  finally
    // Liberar recursos
    RESTClient.Free;
    RESTRequest.Free;
    RESTResponse.Free;
    Authenticator.Free;
  end;
end;


Muchas gracias de antemano.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Ayuda con un servicio SOAP de impuestos en Bolivia con TOKEN en delphi CrazySoft Providers 16 04-03-2022 01:13:55
consumir web service SOAP con TOKEN en delphi Muriel Delphi para la web 14 07-02-2022 09:17:37
Delegar autorización para manipular usuarios en firebird 2.01 sitrico Firebird e Interbase 0 21-09-2007 01:15:45
Token unknown ? sierraja SQL 2 30-08-2005 03:56:53
Problema Autorizacion llamada metodo SOAP?????? mguixot Providers 0 14-01-2004 13:22:25


La franja horaria es GMT +2. Ahora son las 06:33:56.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi