示例#1
0
        public async Task <RevocationDetails> RevokeAuthenticationAsync(UserId userId, UserAuthenticationId id)
        {
            var userAuth = await _persistence.UserAuthentications.GetAsync(id);

            if (!userAuth.UserId.Equals(userId))
            {
                return(RevocationDetails.GetFailed("Could not find specified account details"));
            }

            if (userAuth.IsRevoked)
            {
                return(RevocationDetails.GetFailed("Linked account has already been revoked"));
            }

            userAuth.IsRevoked  = true;
            userAuth.RevokeTime = DateTime.UtcNow;
            await _persistence.UserAuthentications.UpdateAsync(userAuth);

            return(RevocationDetails.GetSuccess());
        }
        public async Task <RevocationDetails> RevokeAuthenticationAsync(string userId, string identity)
        {
            var userAuth = await _persistence.Users.GetUserAuthenticationAsync(identity);

            if (!userAuth.UserId.Equals(userId))
            {
                return(RevocationDetails.GetFailed("Could not find specified API Key for your account"));
            }

            if (userAuth.Scheme == Core.Users.AuthenticationScheme.RevokedAPIKey)
            {
                return(RevocationDetails.GetFailed("APIKey has already been revoked"));
            }

            if (userAuth.Scheme != Core.Users.AuthenticationScheme.APIKey)
            {
                return(RevocationDetails.GetFailed("Could not find specified API Key for your account"));
            }

            userAuth.Scheme = Core.Users.AuthenticationScheme.RevokedAPIKey;
            await _persistence.Users.UpdateUserAuthenticationAsync(userAuth);

            return(RevocationDetails.GetSuccess());
        }