Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   oAuth (https://www.delphipraxis.net/161667-oauth.html)

trax17 14. Jul 2011 20:05

oAuth
 
Ist hier bei irgend jemandem eine "gewisse" Erfahrung zu dem Thema vorhanden?
Ich versuche verzweifelt den Code von http://chuckbeasley.wordpress.com/20...th-for-delphi/ ans laufen zu bekommen.

Ich möchte gerne die Kombination DropBox / oAuth hinbekommen.

Es scheitert bei mir am "abholen" des Tokens auf:
https://api.dropbox.com/0/oauth/access_token

s.h.a.r.k 14. Jul 2011 21:31

AW: oAuth
 
Und was genau scheitert? Hast du schon Code geschrieben, der nicht funktioniert? Oder hast du Probleme beim Ansatz? Ein wenig mehr Infos wären da schon hilfreich ;)

trax17 15. Jul 2011 06:40

AW: oAuth
 
Liste der Anhänge anzeigen (Anzahl: 1)
Anbei mein Code.
Ich bin mir auch unsicher, da in der .Net Anwendung http://sharpbox.codeplex.com/ die Authentifizierung nicht komplett über oAuth abläuft:
https://www.dropbox.com/developers/docs#token

Mein Projekt ist als ZIP File im Anhang.


Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
  StdCtrls, OleCtrls, SHDocVw;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    edtAppKey: TEdit;
    Label2: TLabel;
    edtAppSecret: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    edtUserName: TEdit;
    edtPassword: TEdit;
    btn1: TButton;
    btn2: TButton;
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation


uses
OAuth;

{$R *.dfm}

var
ConsumerKey, ConsumerSecret, UserName, Password : String;
AccessTokenUrl, AuthorizationTokenUrl, RequestTokenUrl : String;

  IdHTTP1     : TIdHTTP;

  Consumer   : TOAuthConsumer;
  ARequest   : TOAuthRequest;
  Token      : TOAuthToken;
  Response   : String;
  HMAC       : TOAuthSignatureMethod_HMAC_SHA1;
  TokenKey   : String;
  TokenSecret : String;



procedure TForm1.btn1Click(Sender: TObject);
var
  Url        : String;
begin

   AccessTokenUrl        := 'http://api.dropbox.com/0/oauth/access_token';
   AuthorizationTokenUrl := 'http://www.dropbox.com/0/oauth/authorize';
   RequestTokenUrl       := 'http://api.dropbox.com/0/oauth/request_token';

   ConsumerKey           := edtAppKey.Text;
   ConsumerSecret        := edtAppSecret.Text;
   UserName              := edtUserName.Text;
   Password              := edtPassword.Text;

   Consumer  := TOAuthConsumer.Create(ConsumerKey, ConsumerSecret);
   HMAC      := TOAuthSignatureMethod_HMAC_SHA1.Create;

   //Step 1 – Request request token (step A in diagram)

    IdHTTP1   := TidHTTP.create(nil);

    ARequest := TOAuthRequest.Create(RequestTokenUrl);
    ARequest := ARequest.FromConsumerAndToken(Consumer, nil, RequestTokenUrl);

    ARequest.Sign_Request(HMAC, Consumer, nil);

    Url        := RequestTokenUrl + '?' + ARequest.GetString;

    Response   := IdHTTP1.Get(Url);

    TokenSecret := Copy(Response, 20, 15);
    TokenKey   := Copy(Response, 48, 63);


    Token := TOAuthToken.Create(TokenKey, TokenSecret);

    //Step 2 – Authorize (Step C in diagram)

    Url := AuthorizationTokenUrl;

    Url :=
    URL + '?' + 'oauth_token=' + TokenKey;

    WebBrowser1.Navigate(Url);

   end;




procedure TForm1.btn2Click(Sender: TObject);
var Url : String;
begin
    //Step 3 – Request access token (Step E in diagram)

    Url := '';
    Url := AccessTokenUrl;

    Consumer := nil;

    Consumer := TOAuthConsumer.Create(TokenKey, TokenSecret);

    ARequest.HTTPURL := Url;
    ARequest := ARequest.FromConsumerAndToken(Consumer, Token, URL);
    ARequest.Sign_Request(HMAC, Consumer, Token);

    Url := Url + '?' + ARequest.GetString;

    Response := idHTTP1.Get(Url);

    idhttp1.ResponseText;

    TokenSecret := Copy(Response, 20, 15);
    TokenKey   := Copy(Response, 48, 63);

    Token := TOAuthToken.Create(TokenKey, TokenSecret);
end;

end.

Dazu verwende ich "OAuth for Delphi", zu finden unter: http://sourceforge.net/projects/oauthdelphi/


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:08 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz