Class: DependencyProxy::AuthTokenService

Inherits:
BaseService show all
Defined in:
app/services/dependency_proxy/auth_token_service.rb

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(token) ⇒ AuthTokenService

Returns a new instance of AuthTokenService.



7
8
9
# File 'app/services/dependency_proxy/auth_token_service.rb', line 7

def initialize(token)
  @token = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



5
6
7
# File 'app/services/dependency_proxy/auth_token_service.rb', line 5

def token
  @token
end

Class Method Details

.user_or_deploy_token_from_jwt(raw_jwt) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/dependency_proxy/auth_token_service.rb', line 15

def self.user_or_deploy_token_from_jwt(raw_jwt)
  token_payload = self.new(raw_jwt).execute

  if token_payload['user_id']
    User.find(token_payload['user_id'])
  elsif token_payload['deploy_token']
    DeployToken.active.find_by_token(token_payload['deploy_token'])
  end
rescue JWT::DecodeError, JWT::ExpiredSignature, JWT::ImmatureSignature
  nil
end

Instance Method Details

#executeObject



11
12
13
# File 'app/services/dependency_proxy/auth_token_service.rb', line 11

def execute
  JSONWebToken::HMACToken.decode(token, ::Auth::DependencyProxyAuthenticationService.secret).first
end