Skip to content

Commit

Permalink
Merge pull request #8 from MeroFuruya:7-token-is-empty-error
Browse files Browse the repository at this point in the history
fix token is empty error #7
  • Loading branch information
MeroFuruya authored Apr 12, 2023
2 parents 7c7ffe3 + f69d37c commit 44db0ee
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 49 deletions.
105 changes: 56 additions & 49 deletions MicrosoftApiAuthenticator.pas
Original file line number Diff line number Diff line change
Expand Up @@ -709,71 +709,78 @@ procedure TMsDelegatedAuthenticator.FOnCommandGet(AContext: TIdContext;
AError, AErrorDescription: string;
AParams: TStringList;
begin
// parse Url Params
AParams := TStringList.Create;
AParams.Delimiter := '&';
AParams.StrictDelimiter := true;
AParams.DelimitedText := ARequestInfo.QueryParams;
// handle connection
if (AParams.Values[Code] <> '') and (AParams.Values[State] <> '') then
if ARequestInfo.Document.Trim(['/']).ToLower = self.FClientInfo.RedirectUri.URL.Trim(['/']).ToLower then
begin
// Check if State is correct
if AParams.Values[State] = Self.FState then
// parse Url Params
AParams := TStringList.Create;
AParams.Delimiter := '&';
AParams.StrictDelimiter := true;
AParams.DelimitedText := ARequestInfo.QueryParams;
// handle connection
if (AParams.Values[Code] <> '') and (AParams.Values[State] <> '') then
begin
// save Acces Code
self.FAccesCode := AParams.Values[Code];
// Check if State is correct
if AParams.Values[State] = Self.FState then
begin
// save Acces Code
self.FAccesCode := AParams.Values[Code];
end
else
begin
// in case the state is not correct, "create" the error
AError := Error_invalidRequest;
AErrorDescription := Error_invalidRequestDescription;
end;
end
else
begin
// in case the state is not correct, "create" the error
AError := Error_invalidRequest;
AErrorDescription := Error_invalidRequestDescription;
end;
end
else
begin
// try to get the error message, if there is none, just say unknown
AError := AParams.Values[Error];
if AError = '' then AError := Error_unknown;
AErrorDescription := AParams.Values[ErrorDescription];
if AErrorDescription = '' then
begin
AErrorDescription := AParams.Values['error_subcode'];
// try to get the error message, if there is none, just say unknown
AError := AParams.Values[Error];
if AError = '' then AError := Error_unknown;
AErrorDescription := AParams.Values[ErrorDescription];
if AErrorDescription = '' then
AErrorDescription := Error_unknown;
begin
AErrorDescription := AParams.Values['error_subcode'];
if AErrorDescription = '' then
AErrorDescription := Error_unknown;
end;
end;
end;
AParams.Free;
AParams.Free;

// create the Response Page
if (AError <> '') or (AErrorDescription <> '') then
begin
self.FAccesCodeErrorOccured := true;
if (AError = 'access_denied') and (AErrorDescription = 'cancel') then
// create the Response Page
if (AError <> '') or (AErrorDescription <> '') then
begin
self.FAccesCodeErrorIsCancel := true;
AResponseInfo.ContentStream := TStringStream.Create(
'<title>Login cancelled</title>The Authentication process was cancelled. You can close this tab now.'
);
self.FAccesCodeErrorOccured := true;
if (AError = 'access_denied') and (AErrorDescription = 'cancel') then
begin
self.FAccesCodeErrorIsCancel := true;
AResponseInfo.ContentStream := TStringStream.Create(
'<title>Login cancelled</title>The Authentication process was cancelled. You can close this tab now.'
);
end
else
begin
self.FAccesCodeErrorIsCancel := false;
// when there is an error, the error page is shown
// TODO: Check if content stream is already a created object
AResponseInfo.ContentStream := TStringStream.Create(
'<title>Login error</title><b>Error:</b><br>' + AError +
'<br><br><b>Description:</b><br>' + AErrorDescription
);
end;
end
else
begin
self.FAccesCodeErrorIsCancel := false;
// when there is an error, the error page is shown
// TODO: Check if content stream is already a created object
AResponseInfo.ContentStream := TStringStream.Create(
'<title>Login error</title><b>Error:</b><br>' + AError +
'<br><br><b>Description:</b><br>' + AErrorDescription
);
// if everything is ok, the OnPageOpen function is called and the Response
// must be built there
self.FEvents.OnPageOpen(AResponseInfo);
// Set Variable
self.FAccesCodeSet := true;
end;
end
else
begin
// if everything is ok, the OnPageOpen function is called and the Response
// must be built there
self.FEvents.OnPageOpen(AResponseInfo);
// Set Variable
self.FAccesCodeSet := true;
AResponseInfo.ResponseNo := 404;
end;
end;

Expand Down
1 change: 1 addition & 0 deletions test-app/main.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ begin
procedure(out Cancel: boolean)
begin
Cancel := KeyPressed(0);
Sleep(1000);
end
)
);
Expand Down

0 comments on commit 44db0ee

Please sign in to comment.