예제 #1
0
        internal void RemoveFromCache(string userName, string password, string providerKey)
        {
            var    securityTokenKey = GetHash(string.Format("{0}|{1}|{2}", providerKey, userName, password).ToLower());
            KZUser user             = null;

            securityTokens.TryRemove(securityTokenKey, out user);
        }
예제 #2
0
        public async Task <KZUser> Authenticate(string userName, string password, string providerKey = "default")
        {
            if (string.IsNullOrWhiteSpace(providerKey))
            {
                throw new ArgumentNullException("providerKey");
            }
            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentNullException("userName");
            }

            var securityTokenKey = GetHash(string.Format("{0}|{1}|{2}", providerKey, userName, password).ToLower());

            if (securityTokens.TryGetValue(securityTokenKey, out kidoZenUser))
            {
                if (!kidoZenUser.TokenApplication.Expired() &&
                    (kidoZenUser.TokenMarketplace == null || !kidoZenUser.TokenMarketplace.Expired()) &&
                    (kidoZenUser.TokenServiceBus == null || !kidoZenUser.TokenServiceBus.Expired()))
                {
                    return(kidoZenUser);
                }
            }

            IdentityProviderConfig provider;

            if (!identityProviders.TryGetValue(providerKey, out provider))
            {
                throw new Exception("The specified provider does not exist");
            }
            currentIP = provider.instance;
            currentIP.Configure(provider);
            currentIP.Initialize(userName, password);
            kidoZenUser = await KZUserFactory.Authenticate(provider);

            if (kidoZenUser != null)
            {
                kidoZenUser.Provider   = providerKey;
                kidoZenUser.Credential = new NetworkCredential(userName, password);
                securityTokens.AddOrUpdate(securityTokenKey, kidoZenUser, (k, current) => kidoZenUser);
            }
            return(kidoZenUser);
        }
예제 #3
0
 public void SignOut()
 {
     kidoZenUser = null;
 }