Redirection Loop on custom oauth

I setup a custom oauth provider outlined in this post. The user is redirected to the site which returns the following:

Next I can see a call to the /oath/token endpoint which returns this:


Next, in the CreateAuthInfo calls the userprofileurl to get the user information. All of this seems to work but then the user is redirected back to the authorize endpoint.

Here is a fiddler screenshot to demonstrate it:

Iā€™m not following what needs to happen to close this loop. The user is being registered correctly in the auth tables.

More info. If I override AuthenticateWithAccessToken with the same code to see what is returned the OnAuthenticated method always returns null.

protected override object AuthenticateWithAccessToken(IServiceBase authService, IAuthSession session, IAuthTokens tokens, string accessToken)
            tokens.AccessToken = accessToken;

            var authInfo = this.CreateAuthInfo(accessToken);

            session.IsAuthenticated = true;

            var a= OnAuthenticated(authService, session, tokens, authInfo);
            return a;

Turns out you need to post to the /auth/provider url from a form otherwise it just keeps redirecting back if you browse directly to /auth/provider.

OnAuthenticated() returns null if it was successful or non null to return a custom error response through any of the auth validation filters.

If AuthenticateWithAccessToken() returns null the OAuth2Provider will return the success url filter:

It uses the session.ReferrerUrl which is set on the initial request:

You can change the URL to redirect to on success by setting SuccessRedirectUrlFilter, e.g:

new MyOauth2Proivder {
    SuccessRedirectUrlFilter = url => ""

Thanks that will fix my testing headache.