debian-mirror-gitlab/app/services/dependency_proxy/auth_token_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

28 lines
724 B
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
module DependencyProxy
class AuthTokenService < DependencyProxy::BaseService
attr_reader :token
def initialize(token)
@token = token
end
def execute
JSONWebToken::HMACToken.decode(token, ::Auth::DependencyProxyAuthenticationService.secret).first
end
2021-11-18 22:05:49 +05:30
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'])
2021-02-22 17:27:13 +05:30
end
2021-11-18 22:05:49 +05:30
rescue JWT::DecodeError, JWT::ExpiredSignature, JWT::ImmatureSignature
nil
2021-02-22 17:27:13 +05:30
end
end
end