diff options
author | Francisco Lopez <fjlopez@gitlab.com> | 2017-11-17 10:09:56 +0100 |
---|---|---|
committer | Francisco Lopez <fjlopez@gitlab.com> | 2017-11-17 10:09:56 +0100 |
commit | 7f0317917a6684189b1637ea73f90d258e8a72b6 (patch) | |
tree | 0284bebb66f663be80933d6b0d41e2b35f0c0e7c | |
parent | b810f479d55b535b31a723975926762b5ef42cbe (diff) | |
download | gitlab-ce-7f0317917a6684189b1637ea73f90d258e8a72b6.tar.gz |
Changes after rebase
-rw-r--r-- | lib/api/api_guard.rb | 21 | ||||
-rw-r--r-- | lib/gitlab/auth/user_auth_finders.rb | 8 |
2 files changed, 6 insertions, 23 deletions
diff --git a/lib/api/api_guard.rb b/lib/api/api_guard.rb index 1953a613f1d..9aeebc34525 100644 --- a/lib/api/api_guard.rb +++ b/lib/api/api_guard.rb @@ -39,7 +39,7 @@ module API # Helper Methods for Grape Endpoint module HelperMethods - include Gitlab::Utils::StrongMemoize + include Gitlab::Auth::UserAuthFinders def find_current_user! user = find_user_from_access_token || find_user_from_warden @@ -50,25 +50,6 @@ module API user end - def access_token - strong_memoize(:access_token) do - find_oauth_access_token || find_personal_access_token - end - end - - def validate_access_token!(scopes: []) - return unless access_token - - case AccessTokenValidationService.new(access_token, request: request).validate(scopes: scopes) - when AccessTokenValidationService::INSUFFICIENT_SCOPE - raise InsufficientScopeError.new(scopes) - when AccessTokenValidationService::EXPIRED - raise ExpiredError - when AccessTokenValidationService::REVOKED - raise RevokedError - end - end - private # An array of scopes that were registered (using `allow_access_with_scope`) diff --git a/lib/gitlab/auth/user_auth_finders.rb b/lib/gitlab/auth/user_auth_finders.rb index 15b54f176b9..cd497fe1cdb 100644 --- a/lib/gitlab/auth/user_auth_finders.rb +++ b/lib/gitlab/auth/user_auth_finders.rb @@ -19,6 +19,8 @@ module Gitlab end module UserAuthFinders + include Gitlab::Utils::StrongMemoize + PRIVATE_TOKEN_HEADER = 'HTTP_PRIVATE_TOKEN'.freeze PRIVATE_TOKEN_PARAM = :private_token @@ -60,9 +62,9 @@ module Gitlab private def access_token - return @access_token if defined?(@access_token) - - @access_token = find_oauth_access_token || find_personal_access_token + strong_memoize(:access_token) do + find_oauth_access_token || find_personal_access_token + end end def find_personal_access_token |