summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-12-05 22:55:53 +0530
committerTimothy Andrew <mail@timothyandrew.net>2016-12-16 16:29:32 +0530
commitb303948ff549ce57d3b6985c2c366dfcdc5a2ca3 (patch)
tree3d286b8704e63cf8c26b10a1f0c538d77f24ab6b /lib
parentf706a973c26f9de9a1f1599d532b33e9e66a80bb (diff)
downloadgitlab-ce-b303948ff549ce57d3b6985c2c366dfcdc5a2ca3.tar.gz
Convert AccessTokenValidationService into a class.
- Previously, AccessTokenValidationService was a module, and all its public methods accepted a token. It makes sense to convert it to a class which accepts a token during initialization. - Also rename the `sufficient_scope?` method to `include_any_scope?` - Based on feedback from @rymai
Diffstat (limited to 'lib')
-rw-r--r--lib/api/api_guard.rb4
-rw-r--r--lib/gitlab/auth.rb2
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/api/api_guard.rb b/lib/api/api_guard.rb
index 563224a580f..df6db140d0e 100644
--- a/lib/api/api_guard.rb
+++ b/lib/api/api_guard.rb
@@ -47,7 +47,7 @@ module API
access_token = find_access_token
return nil unless access_token
- case AccessTokenValidationService.validate(access_token, scopes: scopes)
+ case AccessTokenValidationService.new(access_token).validate(scopes: scopes)
when AccessTokenValidationService::INSUFFICIENT_SCOPE
raise InsufficientScopeError.new(scopes)
@@ -96,7 +96,7 @@ module API
access_token = PersonalAccessToken.active.find_by_token(token_string)
return unless access_token
- if AccessTokenValidationService.sufficient_scope?(access_token, scopes)
+ if AccessTokenValidationService.new(access_token).include_any_scope?(scopes)
User.find(access_token.user_id)
end
end
diff --git a/lib/gitlab/auth.rb b/lib/gitlab/auth.rb
index c21afaa1551..2879a4d2f5d 100644
--- a/lib/gitlab/auth.rb
+++ b/lib/gitlab/auth.rb
@@ -119,7 +119,7 @@ module Gitlab
end
def token_has_scope?(token)
- AccessTokenValidationService.sufficient_scope?(token, ['api'])
+ AccessTokenValidationService.new(token).include_any_scope?(['api'])
end
def lfs_token_check(login, password)