Class: Authn::Tokens::GitlabSession

Inherits:
Object
  • Object
show all
Defined in:
lib/authn/tokens/gitlab_session.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plaintext, source) ⇒ GitlabSession

Returns a new instance of GitlabSession.



16
17
18
19
20
21
22
23
# File 'lib/authn/tokens/gitlab_session.rb', line 16

def initialize(plaintext, source)
  @session_id = find_session_id(plaintext)

  session = find_session
  @revocable = Warden::SessionSerializer.new('rack.session' => session).fetch(:user) if session

  @source = source
end

Instance Attribute Details

#revocableObject (readonly)

Returns the value of attribute revocable.



14
15
16
# File 'lib/authn/tokens/gitlab_session.rb', line 14

def revocable
  @revocable
end

#session_idObject (readonly)

Returns the value of attribute session_id.



14
15
16
# File 'lib/authn/tokens/gitlab_session.rb', line 14

def session_id
  @session_id
end

#sourceObject (readonly)

Returns the value of attribute source.



14
15
16
# File 'lib/authn/tokens/gitlab_session.rb', line 14

def source
  @source
end

Class Method Details

.prefix?(plaintext) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/authn/tokens/gitlab_session.rb', line 6

def self.prefix?(plaintext)
  plaintext.start_with?(session_cookie_key_prefix)
end


10
11
12
# File 'lib/authn/tokens/gitlab_session.rb', line 10

def self.session_cookie_key_prefix
  "#{Gitlab::Application.config.session_options[:key]}="
end

Instance Method Details

#present_withObject



25
26
27
# File 'lib/authn/tokens/gitlab_session.rb', line 25

def present_with
  ::API::Entities::User
end

#revoke!(current_user) ⇒ Object



29
30
31
32
33
34
# File 'lib/authn/tokens/gitlab_session.rb', line 29

def revoke!(current_user)
  raise ::Authn::AgnosticTokenIdentifier::NotFoundError, 'Not Found' if revocable.blank?

  Users::DestroySessionService.new(current_user: current_user, user: revocable,
    private_session_id: session_id.private_id).execute
end