public bool Validate(object apiKey, out IPrincipal principal) { try { principal = null; string strKey = null; if (apiKey != null) { strKey = apiKey.ToString(); if (string.IsNullOrWhiteSpace(strKey)) { return(false); } } int keyId = 0; if (repository.IsValid(strKey, out keyId)) { string[] roles = SettingsAuthorizationRoleProvider.ConstructRoles(strKey); repository.SetUsed(strKey); principal = (IPrincipal) new GenericPrincipal(new ApiIdentity(apiKey.ToString(), keyId), roles.ToArray()); return(true); } return(false); } catch (Exception ex) { Log.Exception(ex); throw new AuthenticationException("Could not authenticate"); } }
public string[] GetApiRoles(string apiKey) { return(SettingsAuthorizationRoleProvider.ConstructRoles(apiKey)); }