ApiKey AuthenticateAttribute Error

Hi,

I have had API key auth repo in use for a week or two, and this afternoon I started getting the following exception on any service protected with the AuthenticateAttribute:

ServiceStack.HttpError: ApiKey does not exist
   at ServiceStack.Auth.ApiKeyAuthProvider.ValidateApiKey(ApiKey apiKey)
   at ServiceStack.Auth.ApiKeyAuthProvider.PreAuthenticateWithApiKey(IRequest req, IResponse res, ApiKey apiKey)
   at ServiceStack.Auth.ApiKeyAuthProvider.PreAuthenticate(IRequest req, IResponse res)
   at ServiceStack.ServiceStackHost.ApplyPreAuthenticateFilters(IRequest httpReq, IResponse httpRes)
   at ServiceStack.ServiceExtensions.GetSession(IRequest httpReq, Boolean reload)

If I look at SessionAs - it is showing Authenticated = true.

My Global.asax.cs hasn’t changed and has the following:

Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                            new IAuthProvider[]
                            {
                                new ApiKeyAuthProvider() {RequireSecureConnection = false, Environments = new []{"live"}, ServiceRoutes = new Dictionary<Type, string[]>()},
                                new CredentialsAuthProvider (),
                                
                            })
                );

ApiKey is not being passed as a param into the service and keys have no expiry date. Using version 5.0.3. Any ideas?

G

The Error Message indicates that the ApiKey sent with the request does not exist. Have you checked the HTTP Request Headers to see if the API Key sent with the Request exists in the database?

You can check it with:

var authRepo = (IManageApiKeys)HostContext.AppHost.GetAuthRepository();
using (authRepo as IDisposable)
{
    var apiKey = authRepo.GetApiKey(apiKeyId);
}

Sorry my mistake; IIS prompted me for username and password during a blip and as a result started sending Authorization:Basic **** header. chrome://restart sorted it.