-
Notifications
You must be signed in to change notification settings - Fork 21
/
IdSASL.OAuth.XOAUTH2.pas
66 lines (52 loc) · 1.64 KB
/
IdSASL.OAuth.XOAUTH2.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
62
63
64
65
unit IdSASL.OAuth.XOAUTH2;
interface
uses
Classes
, SysUtils
, IdSASL
, IdSASL.OAuth.Base
;
type
TIdSASLXOAuth = class(TIdSASLOAuthBase)
public
class function ServiceName: TIdSASLServiceName; override;
constructor Create(AOwner: TComponent);
destructor Destroy; override;
function TryStartAuthenticate(const AHost, AProtocolName : string; var VInitialResponse: string): Boolean; override;
function ContinueAuthenticate(const ALastResponse, AHost, AProtocolName : string): string; override;
function StartAuthenticate(const AChallenge, AHost, AProtocolName: string): string; override;
{ For cleaning up after Authentication }
procedure FinishAuthenticate; override;
end;
implementation
{ TIdSASLXOAuth }
class function TIdSASLXOAuth.ServiceName: TIdSASLServiceName;
begin
Result := 'XOAUTH2';
end;
constructor TIdSASLXOAuth.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
destructor TIdSASLXOAuth.Destroy;
begin
inherited;
end;
function TIdSASLXOAuth.TryStartAuthenticate(const AHost, AProtocolName : string; var VInitialResponse: string): Boolean;
begin
VInitialResponse := Format('user=%s'#1'auth=Bearer %s'#1#1, [FUser, FToken]); {do not localize}
Result := True;
end;
function TIdSASLXOAuth.StartAuthenticate(const AChallenge, AHost, AProtocolName: string): string;
begin
Result := Format('user=%s'#1'auth=Bearer %s'#1#1, [FUser, FToken]); {do not localize}
end;
function TIdSASLXOAuth.ContinueAuthenticate(const ALastResponse, AHost, AProtocolName: string): string;
begin
// Nothing to do
end;
procedure TIdSASLXOAuth.FinishAuthenticate;
begin
// Nothing to do
end;
end.