Module: SessionlessAuthentication

Included in:
ApplicationController
Defined in:
app/controllers/concerns/sessionless_authentication.rb

Overview

SessionlessAuthentication

Controller concern to handle PAT, RSS, and static objects token authentication methods

Instance Method Summary collapse

Instance Method Details

#authenticate_sessionless_user!(request_format) ⇒ Object

This filter handles personal access tokens, atom requests with rss tokens, and static object tokens


9
10
11
12
13
# File 'app/controllers/concerns/sessionless_authentication.rb', line 9

def authenticate_sessionless_user!(request_format)
  user = Gitlab::Auth::RequestAuthenticator.new(request).find_sessionless_user(request_format)

  (user) if user
end

#sessionless_bypass_admin_mode!(&block) ⇒ Object


29
30
31
32
33
# File 'app/controllers/concerns/sessionless_authentication.rb', line 29

def sessionless_bypass_admin_mode!(&block)
  return yield unless Feature.enabled?(:user_mode_in_session)

  Gitlab::Auth::CurrentUserMode.bypass_session!(current_user.id, &block)
end

#sessionless_sign_in(user) ⇒ Object


19
20
21
22
23
24
25
26
27
# File 'app/controllers/concerns/sessionless_authentication.rb', line 19

def (user)
  if user && can?(user, :log_in)
    # Notice we are passing store false, so the user is not
    # actually stored in the session and a token is needed
    # for every request. If you want the token to work as a
    # sign in token, you can simply remove store: false.
    (user, store: false, message: :sessionless_sign_in)
  end
end

#sessionless_user?Boolean

Returns:

  • (Boolean)

15
16
17
# File 'app/controllers/concerns/sessionless_authentication.rb', line 15

def sessionless_user?
  current_user && !session.key?('warden.user.user.key')
end