After v5 upgrade: ArgumentNullException by GetAuthProvider is thrown

I’ve just updated to v5 and am giving it a run through.

However I get the following exception with services marked with [Authenticate]:

"ResponseStatus": {
    "ErrorCode": "ArgumentNullException",
    "Message": "Value cannot be null.\r\nParameter name: provider",
    "StackTrace": "   at ServiceStack.Auth.AuthenticateService.GetAuthProvider(String provider)\r\n   at ServiceStack.AuthUserSession.IsAuthorized(String provider)\r\n   at ServiceStack.AuthenticateAttribute.<>c__DisplayClass12_0.<ExecuteAsync>b__0(IAuthProvider x)\r\n   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)\r\n   at ServiceStack.AuthenticateAttribute.<ExecuteAsync>d__12.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at ServiceStack.ServiceStackHost.<ApplyRequestFiltersSingleAsync>d__307.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at ServiceStack.ServiceStackHost.<ApplyRequestFiltersAsync>d__306.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at ServiceStack.Host.Handlers.GenericHandler.<ProcessRequestAsync>d__12.MoveNext()",
    "Errors": [
      {
        "ErrorCode": "ArgumentNullException",
        "FieldName": "provider",
        "Message": "Value cannot be null.\r\n"
      }
    ]

I have one single auth provider registered that overrides AuthProvider. Everything worked before the upgrade.

Any ideas? I did not find anything in the release notes.

When you authenticate are you providing a provider name, e.g:

/auth/{provider}

And does it match up with the Provider property for your custom AuthProvider?

Our auth works a bit differently, we do not call /auth. When a user logs in our auth layer provides them with a token.

Our services are then marked with the [Authenticate] attribute. With our auth provider registered, this used to hit the following overridden methods:

public override bool IsAuthorized(IAuthSession session, IAuthTokens tokens, Authenticate request = null)
{
    using (var authService = HostContext.ResolveService<AuthenticateService>())
    {
        var token = authService.Request.GetAuthenticationToken();
        return AuthenticationToken.IsValid(token);
    }
}

public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
{
    // should not get here
    throw new NotImplementedException();
}

However nothing is hit in the auth provider now and I get that exception for all services to be authenticated.

What is the Provider name for your Custom AuthProvider? It needs one if it doesn’t have one.

I just looked here for an updated example and saw in the ctor the Provider and AuthRealm were being set.

I was not doing this before. Everything works now I’m setting it. Did something change?

Every AuthProvider always needs its own Provider name.