Skip to content

Runtime error appended to otherwise valid extension method response #23

@FredTheDane

Description

@FredTheDane

Hi folks,

Some months back I managed to get it to work seamlessly with Teams and Azure AD, and it is awesome! However, today I tried to optimize the code a little, to improve response times and ran into a weird problem. My code to set the authentication token for the MFWSClient used to be as follows:

public void SetAuthenticationToken(string token)
        {
            _logger.LogDebug("Authenticated: " + Authenticated);
            if (Authenticated) return;

            var oAuth2TokenResponse = new OAuth2TokenResponse()
            {
                IdToken = token
            };
            
            Client.AddAuthorizationHeader(_serverContext.OAuth2Configuration, oAuth2TokenResponse);
            try
            {
                var sessionInfo = Client.GetCurrentSessionInfo();
                Authenticated = true;
                _logger.LogDebug("Authentication successful");
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Authentication unsuccessful");
                Authenticated = false;
            }

            return;
        }

Essentially setting up a token response, adding the authorization header, and checking that it works by getting the session info. Attempting to improve response time I thought that perhaps removing the call to get the session info could help. So I commented on the first line in the try/catch and tried again.

After setting the authentication token, the first thing that I call an extension method. However, without the session info call, an HTML document with a runtime error got appended to my otherwise valid response from the extension method! Something along the lines of: https://pastebin.com/gt64hAqa (Note my valid response in the top, and then the HTML appended to it afterwards)

I have no idea why the runtime error is appended to my valid response. The weird thing is that it is only appended to the response of the first extension method call of the day. Subsequent calls work just fine and if I put GetCurrentSessionInfo inside the SetAuthenticationToken method again, I also get no additional HTML in my response.

For now I have "fixed it" by removing the HTML from the response manually :D

Anyone who has an idea why this would happen?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions