diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-11-24 13:07:22 +0530 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-12-16 16:29:31 +0530 |
commit | 4d6da770de94f4bf140507cdf43461b67269ce28 (patch) | |
tree | d637ccdf6af0475af83b01e9f8371c5f06f6f880 /lib | |
parent | ac9835c602f1c9b5a35ef40df079faf1d4b91f7b (diff) | |
download | gitlab-ce-4d6da770de94f4bf140507cdf43461b67269ce28.tar.gz |
Implement minor changes from @dbalexandre's review.
- Mainly whitespace changes.
- Require the migration adding the `scope` column to the
`personal_access_tokens` table to have downtime, since API calls will
fail if the new code is in place, but the migration hasn't run.
- Minor refactoring - load `@scopes` in a `before_action`, since we're
doing it in three different places.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/api_guard.rb | 26 | ||||
-rw-r--r-- | lib/gitlab/auth.rb | 1 |
2 files changed, 15 insertions, 12 deletions
diff --git a/lib/api/api_guard.rb b/lib/api/api_guard.rb index cd266669b1e..563224a580f 100644 --- a/lib/api/api_guard.rb +++ b/lib/api/api_guard.rb @@ -44,17 +44,21 @@ module API # Defaults to empty array. # def doorkeeper_guard(scopes: []) - if access_token = find_access_token - case AccessTokenValidationService.validate(access_token, scopes: scopes) - when AccessTokenValidationService::INSUFFICIENT_SCOPE - raise InsufficientScopeError.new(scopes) - when AccessTokenValidationService::EXPIRED - raise ExpiredError - when AccessTokenValidationService::REVOKED - raise RevokedError - when AccessTokenValidationService::VALID - @current_user = User.find(access_token.resource_owner_id) - end + access_token = find_access_token + return nil unless access_token + + case AccessTokenValidationService.validate(access_token, scopes: scopes) + when AccessTokenValidationService::INSUFFICIENT_SCOPE + raise InsufficientScopeError.new(scopes) + + when AccessTokenValidationService::EXPIRED + raise ExpiredError + + when AccessTokenValidationService::REVOKED + raise RevokedError + + when AccessTokenValidationService::VALID + @current_user = User.find(access_token.resource_owner_id) end end diff --git a/lib/gitlab/auth.rb b/lib/gitlab/auth.rb index c6a23aa2bdf..c425702fd75 100644 --- a/lib/gitlab/auth.rb +++ b/lib/gitlab/auth.rb @@ -107,7 +107,6 @@ module Gitlab if token && token.user == validation && token_has_scope?(token) Gitlab::Auth::Result.new(validation, nil, :personal_token, full_authentication_abilities) end - end end |