-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathRac.Dropbox.VCL.pas
More file actions
53 lines (44 loc) · 1.22 KB
/
Rac.Dropbox.VCL.pas
File metadata and controls
53 lines (44 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
unit Rac.Dropbox.VCL;
interface
uses
Rac.Dropbox, System.SysUtils, Vcl.Edge;
const
AUTHORIZE_URL = '%s/oauth2/authorize?client_id=%s&response_type=token&redirect_uri=http://localhost&state=%s';
STATE_LENGTH = 64;
type TDropbox = class(TDropboxBase)
private
FState: string;
procedure _OnTitleChange(Sender: TCustomEdgeBrowser; const ADocumentTitle: string);
public
procedure Authorize(AWebBrowser: TEdgeBrowser); reintroduce;
end;
implementation
{ TDropbox }
procedure TDropbox.Authorize(AWebBrowser: TEdgeBrowser);
var
url: string;
begin
if Assigned(AWebBrowser) then
begin
FState := GetState(STATE_LENGTH);
url := Format(AUTHORIZE_URL, [DROPBOX_AUTHORIZE_URL, AppKey, FState]);
AWebBrowser.OnDocumentTitleChanged := _OnTitleChange;
AWebBrowser.Navigate(url);
end;
end;
procedure TDropbox._OnTitleChange(Sender: TCustomEdgeBrowser; const ADocumentTitle: string);
var
url: string;
begin
url := Sender.LocationURL;
if url.StartsWith(DROPBOX_RETURN_URL, true) then
begin
Sender.Stop;
if IsReturnURLCorrect(FState, url) and Assigned(OnAuthorize) then
if ParseReturnURL(url) then
OnAuthorize(Self, true)
else
OnAuthorize(Self, false);
end;
end;
end.