question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OAuth2 Custom Providers: Thread Aborts With No Reason

See original GitHub issue

Description of bug

When building an OAuth2 Authorization Provider, during the login phase OAuthClient.Authorize() an exception is captured and is ignored that states the thread is aborted.

{"Thread was being aborted."}
    Data: {System.Collections.ListDictionaryInternal}
    ExceptionState: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
    HResult: -2146233040
    HelpLink: null
    InnerException: null
    Message: "Thread was being aborted."
    Source: "mscorlib"
    StackTrace: "   at System.Threading.Thread.AbortInternal()\r\n   at System.Threading.Thread.Abort(Object stateInfo)\r\n   at DotNetNuke.Services.Authentication.OAuth.OAuthClientBase.AuthorizeV2() ... <omitted stack> ..."
    TargetSite: {Void AbortInternal()}

Steps to reproduce

List the steps to reproduce the behavior:

  1. Create OAuth Authorization Provider
  2. Install module
  3. Login

Details of problem

The OAuth Authorize workflow lives in the OAuthClient class of the DotNetNuke.Library. This is the class that is used to create custom OAuth Provider Modules. The Module will manually invoke var result = OAuthClient.Authorize();

(Code Truncated for brevity)

public virtual AuthorisationResult Authorize()
{
    if (OAuthVersion == "1.0")
    {
        return AuthorizeV1();
    }
    return AuthorizeV2();
}

private AuthorisationResult AuthorizeV2()
{
    string errorReason = HttpContext.Current.Request.Params["error_reason"];
    bool userDenied = (errorReason != null);
    if (userDenied)
    {
        return AuthorisationResult.Denied;
    }

    if (!HaveVerificationCode())
    {
        var parameters = new List<QueryParameter>
                                {
                                    new QueryParameter("scope", Scope),
                                    new QueryParameter(OAuthClientIdKey, APIKey),
                                    new QueryParameter(OAuthRedirectUriKey, HttpContext.Current.Server.UrlEncode(CallbackUri.ToString())),
                                    new QueryParameter("state", Service),
                                    new QueryParameter("response_type", "code")
                                };

        HttpContext.Current.Response.Redirect(AuthorizationEndpoint + "?" + parameters.ToNormalizedString(), true);
        return AuthorisationResult.RequestingCode;
    }

    ExchangeCodeForToken();

    return String.IsNullOrEmpty(AuthToken) ? AuthorisationResult.Denied : AuthorisationResult.Authorized;
}

The problem has to deal with the following line of code:

HttpContext.Current.Response.Redirect(AuthorizationEndpoint + "?" + parameters.ToNormalizedString(), true);

The parameter request if the thread aborts or not and we are passing in true. If we update this code to false the thread will not abort.

My Thoughts

Aborting the thread or continuing doesn’t really matter for an OAuth2 integration, but it makes it VERY confusing to a module developer on what is happening when the error just reads the Thread was aborted. I think we should allow the thread to continue along and finish processing any logic that may exist in the custom module.

Screenshots

N/A

Error log

N/A

Additional context

N/A

Affected version

  • 9.3.0
  • 9.2.2
  • 9.2.1
  • 9.2
  • 9.1.1
  • 9.1
  • 9.0

Affected browser

  • Chrome
  • Firefox
  • Safari
  • Internet Explorer
  • Edge

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
bdukescommented, Apr 11, 2019

I wouldn’t think it would be a problem to pass endResponse: false and avoid the ThreadAbortException here.

0reactions
valadascommented, Oct 28, 2019

Merged

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Spring security oauth, using a custom ...
These error means , that authorization request doesn't found. authorization request is stored in session, so some how session is not getting ...
Read more >
Why is OAuth still hard in 2023?
Because the documentation is bad. Oauth is really simple: Lets say you want to use google as an auth provider. You do this:...
Read more >
OAuth 2.0 identity provider API
OAuth 2.0 identity provider API. GitLab provides an API to allow third-party services to access GitLab resources on a user's behalf with the...
Read more >
How to Prevent Reactive Java Applications from Stalling
Traditional Java applications run blocking code and a common approach for scaling is to increase the number of available threads.
Read more >
Update your security provider to protect against SSL exploits
Call installIfNeeded() from background networking threads immediately when the threads are loaded, instead of waiting for the thread to try to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found