1- unit uRESTDWAuthenticators;
1+ unit uRESTDWAuthenticators;
22
33{ $I ..\..\Includes\uRESTDW.inc}
44
@@ -32,8 +32,20 @@ interface
3232
3333uses
3434 Classes, SysUtils, DateUtils,
35- uRESTDWConsts, uRESTDWAbout, uRESTDWDataUtils, uRESTDWJSONInterface,
36- uRESTDWTools, uRESTDWParams;
35+ uRESTDWConsts, uRESTDWAbout, uRESTDWDataUtils, uRESTDWJSONInterface,
36+ uRESTDWTools, uRESTDWParams, uRESTDWProtoTypes, uRESTDW.OpenSsl_11;
37+
38+ Type
39+ TRESTDWCertOptions = Record
40+ Country,
41+ State,
42+ Locality,
43+ Organization,
44+ OrgUnit,
45+ CommonName,
46+ ServerName : String;
47+ ExpiresDays : Integer;
48+ End ;
3749
3850Type
3951 TRESTDWAuthenticatorBase = class (TRESTDWComponent)
@@ -138,36 +150,63 @@ TRESTDWAuthToken = class(TRESTDWServerAuthBase)
138150 property AutoRenewToken: Boolean read FAutoRenewToken write FAutoRenewToken;
139151 end ;
140152
141- TRESTDWAuthOAuth = class (TRESTDWServerAuthBase)
153+ TRESTDWAuthOAuth = Class (TRESTDWServerAuthBase)
142154 private
143- FTokenType: TRESTDWAuthOptionTypes;
144- FAutoBuildHex: Boolean;
145- FToken: String;
146- FGrantCodeEvent: String;
147- FGrantType: String;
148- FGetTokenEvent: String;
149- FClientID: String;
150- FClientSecret: String;
151- FRedirectURI: String;
152- FExpiresIn: TDateTime;
155+ FTokenType : TRESTDWAuthOptionTypes;
156+ FBeginTime,
157+ FEndTime : TDateTime;
158+ FRSASHA256_Validation,
159+ FServerValidationCert,
160+ FAutoBuildHex : Boolean;
161+ FLifeCycle : Integer;
162+ FToken,
163+ FGrantCodeEvent,
164+ FGrantType,
165+ FGetTokenEvent,
166+ FHeader,
167+ FPayLoad,
168+ FSignature,
169+ FPublicKey,
170+ FPrivateKey,
171+ FRedirectURI : String;
153172 public
154- constructor Create(aOwner: TComponent); override;
155- function AuthValidate (ADataModuleRESTDW: TObject;
156- AUrlToExec, AWelcomeMessage, AAccessTag, AAuthUsername, AAuthPassword: String;
157- ARawHeaders: TStrings; ARequestType: TRequestType; var ADWParams: TRESTDWParams;
158- var AGetToken: Boolean; var ATokenValidate: Boolean; var AToken: String;
159- var AErrorCode: Integer; var AErrorMessage: String; var AAcceptAuth: Boolean): Boolean; override;
173+ Constructor Create (aOwner : TComponent); Override;
174+ Function CreateSelfSignedCert_X509 (CertOptions : TRESTDWCertOptions;
175+ Var Certificate,
176+ PrivateKey : TRESTDWBytes) : Boolean;
177+ Function AuthValidate (ADataModuleRESTDW : TObject;
178+ AUrlToExec,
179+ AWelcomeMessage,
180+ AAccessTag,
181+ AAuthUsername,
182+ AAuthPassword : String;
183+ ARawHeaders : TStrings;
184+ ARequestType : TRequestType;
185+ Var ADWParams : TRESTDWParams;
186+ Var AGetToken : Boolean;
187+ Var ATokenValidate : Boolean;
188+ Var AToken : String;
189+ Var AErrorCode : Integer;
190+ Var AErrorMessage : String;
191+ Var AAcceptAuth : Boolean) : Boolean; Override;
160192 published
161- property TokenType: TRESTDWAuthOptionTypes read FTokenType write FTokenType;
162- property AutoBuildHex: Boolean read FAutoBuildHex write FAutoBuildHex;
163- property Token: String read FToken write FToken;
164- property GrantCodeEvent: String read FGrantCodeEvent write FGrantCodeEvent;
165- property GrantType: String read FGrantType write FGrantType;
166- property GetTokenEvent: String read FGetTokenEvent write FGetTokenEvent;
167- property ClientID: String read FClientID write FClientID;
168- property ClientSecret: String read FClientSecret write FClientSecret;
169- property RedirectURI: String read FRedirectURI write FRedirectURI;
170- property ExpiresIn: TDateTime read FExpiresIn;
193+ Property TokenType : TRESTDWAuthOptionTypes Read FTokenType Write FTokenType;
194+ Property AutoBuildHex : Boolean Read FAutoBuildHex Write FAutoBuildHex;
195+ Property RSASHA256_Validation : Boolean Read FRSASHA256_Validation Write FRSASHA256_Validation;
196+ Property LifeCycle : Integer Read FLifeCycle Write FLifeCycle;
197+ Property BeginTime : TDateTime Read FBeginTime Write FBeginTime; // iat
198+ Property EndTime : TDateTime Read FEndTime Write FEndTime;// exp
199+ Property ServerValidationCert : Boolean Read FServerValidationCert Write FServerValidationCert;
200+ Property Token : String Read FToken Write FToken;
201+ Property GrantCodeEvent : String Read FGrantCodeEvent Write FGrantCodeEvent;
202+ Property GrantType : String Read FGrantType Write FGrantType;
203+ Property GetTokenEvent : String Read FGetTokenEvent Write FGetTokenEvent;
204+ Property Header : String Read FHeader;
205+ Property PayLoad : String Read FPayLoad Write FPayLoad;
206+ Property Signature : String Read FSignature Write FSignature;
207+ Property PublicKey : String Read FPublicKey Write FPublicKey;
208+ Property PrivateKey : String Read FPrivateKey Write FPrivateKey;
209+ Property RedirectURI : String Read FRedirectURI Write FRedirectURI;
171210 end ;
172211
173212 TOnUserBasicAuth = Procedure(Welcomemsg, AccessTag,
@@ -177,14 +216,14 @@ TRESTDWAuthOAuth = class(TRESTDWServerAuthBase)
177216 Var ErrorMessage : String;
178217 Var Accept : Boolean) Of Object ;
179218
180- TOnGetToken = Procedure(Welcomemsg,
181- AccessTag : String;
182- Params : TRESTDWParams;
183- AuthOptions : TRESTDWAuthToken;
184- Var ErrorCode : Integer;
185- Var ErrorMessage : String;
186- Var TokenID : String;
187- Var Accept : Boolean) Of Object ;
219+ TOnGetToken = Procedure(Welcomemsg,
220+ AccessTag : String;
221+ Params : TRESTDWParams;
222+ AuthOptions : TRESTDWAuthToken;
223+ Var ErrorCode : Integer;
224+ Var ErrorMessage : String;
225+ Var TokenID : String;
226+ Var Accept : Boolean) Of Object ;
188227
189228 TOnUserTokenAuth = Procedure(Welcomemsg,
190229 AccessTag : String;
@@ -926,7 +965,22 @@ procedure TRESTDWAuthToken.SetToken(AValue: String);
926965
927966{ TRESTDWAuthOAuth }
928967
929- Function TRESTDWAuthOAuth.AuthValidate (ADataModuleRESTDW : TObject;
968+ Function TRESTDWAuthOAuth.CreateSelfSignedCert_X509 (CertOptions : TRESTDWCertOptions;
969+ Var Certificate,
970+ PrivateKey : TRESTDWBytes) : Boolean;
971+ begin
972+ Result := TRESTDWOpenSSLHelper.CreateSelfSignedCert_X509(CertOptions.Country,
973+ CertOptions.State,
974+ CertOptions.Locality,
975+ CertOptions.Organization,
976+ CertOptions.OrgUnit,
977+ CertOptions.CommonName,
978+ CertOptions.ServerName,
979+ CertOptions.ExpiresDays,
980+ Certificate, PrivateKey);
981+ End ;
982+
983+ Function TRESTDWAuthOAuth.AuthValidate (ADataModuleRESTDW : TObject;
930984 AUrlToExec,
931985 AWelcomeMessage,
932986 AAccessTag,
@@ -950,16 +1004,24 @@ procedure TRESTDWAuthToken.SetToken(AValue: String);
9501004Constructor TRESTDWAuthOAuth.Create(aOwner: TComponent);
9511005Begin
9521006 Inherited ;
953- FClientID := ' ' ;
954- FClientSecret := ' ' ;
955- FToken := ' ' ;
956- FRedirectURI := ' ' ;
957- FGrantType := ' client_credentials' ;
958- FGetTokenEvent := ' access-token' ;
959- FGrantCodeEvent := ' authorize' ;
960- FAutoBuildHex := False;
961- FExpiresIn := 0 ;
962- FTokenType := rdwOATBasic;
1007+ FRSASHA256_Validation := True;
1008+ FServerValidationCert := True;
1009+ FToken := ' ' ;
1010+ FRedirectURI := ' ' ;
1011+ FGrantType := ' client_credentials' ;
1012+ FGetTokenEvent := ' access-token' ;
1013+ FGrantCodeEvent := ' authorize' ;
1014+ FHeader := ' {"alg": "RS256", "typ": "JWT"}' ;
1015+ FLifeCycle := 1800 ; // 30 Minutos
1016+ FPayLoad := ' ' ;
1017+ FSignature := ' ' ;
1018+ FPublicKey := ' ' ;
1019+ FPrivateKey := ' ' ;
1020+ FRedirectURI := ' ' ;
1021+ FBeginTime := 0 ;
1022+ FEndTime := 0 ;
1023+ FAutoBuildHex := False;
1024+ FTokenType := rdwOATBasic;
9631025End ;
9641026
9651027{ TRESTDWAuthenticatorBase }
0 commit comments