-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathIdSASL.OAuth.OAuth2Bearer.pas
68 lines (55 loc) · 1.89 KB
/
IdSASL.OAuth.OAuth2Bearer.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
66
67
68
unit IdSASL.OAuth.OAuth2Bearer;
interface
uses
System.Classes
, System.SysUtils
, IdSASL
, IdSASL.OAuth.Base
;
type
TIdOAuth2Bearer = class(TIdSASLOAuthBase)
private
FPort: Integer;
public
property Port: Integer read FPort write FPort;
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
{ TIdOAuth2Bearer }
constructor TIdOAuth2Bearer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
destructor TIdOAuth2Bearer.Destroy;
begin
inherited;
end;
class function TIdOAuth2Bearer.ServiceName: TIdSASLServiceName;
begin
Result := 'OAUTHBEARER';
end;
function TIdOAuth2Bearer.TryStartAuthenticate(const AHost, AProtocolName: String; var VInitialResponse: String): Boolean;
begin
VInitialResponse := 'n,a=' + FUser + ',' + Chr($01) + 'host=' + AHost + Chr($01) + 'port=' + FPort.ToString + Chr($01) + 'auth=Bearer ' + FToken + Chr($01) + Chr($01);
Result := True;
end;
function TIdOAuth2Bearer.StartAuthenticate(const AChallenge, AHost, AProtocolName: string): string;
begin
Result := 'n,a=' + FUser + ',' + Chr($01) + 'host=' + AHost + Chr($01) + 'port=' + FPort.ToString + Chr($01) + 'auth=Bearer ' + FToken + Chr($01) + Chr($01);
end;
function TIdOAuth2Bearer.ContinueAuthenticate(const ALastResponse, AHost, AProtocolName: string): string;
begin
// Nothing to do
end;
procedure TIdOAuth2Bearer.FinishAuthenticate;
begin
// Nothing to do
end;
end.