@@ -160,6 +160,65 @@ begin
160160 end ;
161161end ;
162162
163+ function Split (const Value : String; const Delimiter: String): TStringList;
164+ var
165+ dx: integer;
166+ ns: String;
167+ txt: String;
168+ delta: integer;
169+ begin
170+ delta := Length(Delimiter);
171+ txt := value + Delimiter;
172+ Result := TStringList.Create();
173+
174+ while Length(txt) > 0 do
175+ begin
176+ dx := Pos(delimiter, txt);
177+ ns := Copy(txt, 0 , dx-1 );
178+ Result.Add(ns);
179+ txt := Copy(txt, dx+delta, MaxInt);
180+ end ;
181+ end ;
182+
183+ // Tests whether a String value starts with another String value, returns true if it does
184+ function StartsWith (const Text: String; const Value : String): boolean;
185+ var
186+ I: Integer;
187+ begin
188+ if Length(Text) < Length(Value ) then
189+ begin
190+ Result := False;
191+ end else begin
192+ for I := 1 to Length(Value ) do
193+ begin
194+ if Value [I] <> Text[I] then
195+ begin
196+ Result := False;
197+ Exit;
198+ end ;
199+ end ;
200+ Result := True;
201+ end ;
202+ end ;
203+
204+ // Extracts a particular cookie value from the Set-Cookie response header
205+ function GetCookieValue (const CookieText: String; const CookieName: String): String;
206+ var
207+ Cookies: TStringList;
208+ I: integer;
209+ begin
210+ Cookies := Split(CookieText, ' ;' );
211+
212+ for I := 0 to Cookies.Count - 1 do
213+ begin
214+ if StartsWith(Cookies.Strings[I], CookieName + ' =' ) then
215+ begin
216+ Result := Split(Cookies.Strings[I], ' =' )[1 ];
217+ Exit;
218+ end ;
219+ end ;
220+ end ;
221+
163222function ExtractSAMLFormValues (ResponseText: String): SAMLFormParams;
164223var
165224 I, J, K: Integer;
@@ -316,10 +375,8 @@ begin
316375 AuthLabel.Font.Color := clRed;
317376 Exit;
318377 end else begin
319- MsgBox(' Got cookies: ' + WinHttpReq.getResponseHeader(' Set-Cookie' ), mbInformation, MB_OK);
320-
321- // MsgBox('Got response code: ' + WinHttpReq.Status + ', response: ' +
322- // WinHttpReq.ResponseText, mbInformation, MB_OK);
378+ MsgBox(' Got rh_sso cookie: ' +
379+ GetCookieValue(WinHttpReq.getResponseHeader(' Set-Cookie' ), ' rh_sso' ), mbInformation, MB_OK);
323380 end ;
324381 end ;
325382
0 commit comments