예제 #1
0
        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");
            }
        }
예제 #2
0
 public string[] GetApiRoles(string apiKey)
 {
     return(SettingsAuthorizationRoleProvider.ConstructRoles(apiKey));
 }