Пример #1
0
        public virtual async Task <IActionResult> GetScope(string id, CancellationToken cancellationToken)
        {
            var scope = await _oauthScopeRepository.GetOAuthScope(id, cancellationToken);

            if (scope == null)
            {
                return(new NotFoundResult());
            }

            return(new OkObjectResult(scope.ToDto()));
        }
        public async Task <bool> Handle(string scopeName, CancellationToken cancellationToken)
        {
            var scope = await _oauthScopeRepository.GetOAuthScope(scopeName, cancellationToken);

            if (scope == null)
            {
                _logger.LogError($"the scope '{scopeName}' doesn't exist");
                throw new OAuthScopeNotFoundException(ErrorCodes.INVALID_REQUEST, string.Format(ErrorMessages.UNKNOWN_CLIENT, scopeName));
            }

            await _oauthScopeRepository.Delete(scope, cancellationToken);

            await _oauthScopeRepository.SaveChanges(cancellationToken);

            _logger.LogError($"the scope '{scopeName}' is removed");
            return(true);
        }
Пример #3
0
        public async Task <string> Handle(JObject jObj, CancellationToken cancellationToken)
        {
            var extractedScope = jObj.ToScopeDomain();
            var result         = await _oauthScopeRepository.GetOAuthScope(extractedScope.Name, cancellationToken);

            if (result != null)
            {
                _logger.LogError($"the scope '{extractedScope.Name}' already exists");
                throw new OAuthException(ErrorCodes.INVALID_REQUEST, string.Format(ErrorMessages.SCOPE_ALREADY_EXISTS, extractedScope.Name));
            }

            var scope = OAuthScope.Create(extractedScope.Name);
            await _oauthScopeRepository.Add(scope, cancellationToken);

            await _oauthScopeRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"the scope '{extractedScope.Name}' has been added");
            return(extractedScope.Name);
        }
Пример #4
0
        public async Task <bool> Handle(string scopeName, JObject jObj, CancellationToken cancellationToken)
        {
            var scope = await _oauthScopeRepository.GetOAuthScope(scopeName, cancellationToken);

            if (scope == null)
            {
                _logger.LogError($"the scope '{scopeName}' doesn't exist");
                throw new OAuthScopeNotFoundException(ErrorCodes.INVALID_REQUEST, string.Format(ErrorMessages.UNKNOWN_CLIENT, scopeName));
            }

            var extractedScope = jObj.ToScopeDomain();

            scope.SetClaims(extractedScope.Claims);
            await _oauthScopeRepository.Update(scope, cancellationToken);

            await _oauthScopeRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"the scope '{scopeName}' has been updated");
            return(true);
        }