-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUnit2.pas
61 lines (50 loc) · 1.24 KB
/
Unit2.pas
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
54
55
56
57
58
59
60
61
unit Unit2;
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
REST.Types,
REST.Client,
REST.Authenticator.OAuth,
Data.Bind.Components,
Data.Bind.ObjectScope,
REST.Authenticator.OAuth.PasswordGrant
;
type
TForm2 = class(TForm)
RESTClient1: TRESTClient;
RESTRequest1: TRESTRequest;
RESTResponse1: TRESTResponse;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
FAuthenticator : TOAuth2AuthenticatorPasswordGrant;
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormDestroy(Sender: TObject);
begin
FreeAndNil(FAuthenticator);
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
FAuthenticator := TOAuth2AuthenticatorPasswordGrant.Create(nil);
RESTClient1.Authenticator := FAuthenticator;
FAuthenticator.AccessTokenEndpoint := '<token-endpoint-goes-here>';
FAuthenticator.Username := '<username-goes-here>';
FAuthenticator.Username := '<password-goes-here>';
// Need to call FAuthenticator.ChangePasswordToAccesToken; somewhere before making requests
end;
end.