Module: YiffSpace::Auth

Defined in:
lib/yiffspace/auth.rb,
lib/yiffspace/auth/client.rb,
lib/yiffspace/auth/engine.rb,
lib/yiffspace/auth/helper.rb,
lib/yiffspace/auth/version.rb,
lib/yiffspace/auth/api_user.rb,
lib/yiffspace/auth/auth_info.rb,
lib/yiffspace/auth/user_info.rb,
lib/yiffspace/auth/permissions.rb,
lib/yiffspace/auth/discord_info.rb,
lib/yiffspace/auth/set_client_name.rb,
lib/yiffspace/auth/auth_info/anonymous.rb,
lib/yiffspace/auth/user_info/anonymous.rb,
app/controllers/yiff_space/auth/root_controller.rb,
app/controllers/yiff_space/auth/webhook_controller.rb,
app/controllers/yiff_space/auth/application_controller.rb

Defined Under Namespace

Modules: Helper Classes: ApiUser, ApplicationController, AuthInfo, Client, DiscordInfo, Engine, Permissions, RootController, SetClientName, UserInfo, WebhookController

Constant Summary collapse

CLIENT_NAME_ENV =
"yiffspace.auth.client_name"
DEFAULT_CLIENT_NAME =
:default
SPOOF_OVERRIDE_ENV =

Per-request override of spoof auth, keyed off the request env like CLIENT_NAME_ENV is - see Helper#spoof_override/#spoof_override= below. false disables spoofing outright; a Hash overrides individual :spoof_user_id/:spoof_permissions/:spoof_roles values.

"yiffspace.auth.spoof_override"
SESSION_CACHE_KEY =

auth/user session values (raw Discord profile + OIDC token claims) can easily exceed a cookie's ~4KB limit, so the session cookie itself only holds an opaque pointer - the real payload lives in Rails.cache (already a hard dependency of Helper, see Helper#sync_auth_if_dirty! below), keyed off that pointer.

"yiffspace:auth:session:%s"
SESSION_CACHE_TTL =
30.days
DIRTY_FLAG_KEY =
"yiffspace:auth:dirty:%s"
VERSION =
"0.0.5"

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object



49
50
51
# File 'lib/yiffspace/auth.rb', line 49

def [](name)
  @clients[name.to_sym] || raise(KeyError, "unknown auth client: #{name.inspect}")
end

.defaultObject



53
54
55
# File 'lib/yiffspace/auth.rb', line 53

def default
  @clients[DEFAULT_CLIENT_NAME] || raise("no default client configured")
end

.disable_debug_action!Object



69
70
71
# File 'lib/yiffspace/auth.rb', line 69

def disable_debug_action!
  @enable_debug_action = false
end

.disable_spoof_auth!Object



86
87
88
# File 'lib/yiffspace/auth.rb', line 86

def disable_spoof_auth!
  @spoof_auth = false
end

.enable_debug_action!Object



65
66
67
# File 'lib/yiffspace/auth.rb', line 65

def enable_debug_action!
  @enable_debug_action = true
end

.enable_debug_action?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/yiffspace/auth.rb', line 61

def enable_debug_action?
  @enable_debug_action
end

.enable_spoof_auth!Object



82
83
84
# File 'lib/yiffspace/auth.rb', line 82

def enable_spoof_auth!
  @spoof_auth = true
end

.get_by_id(id) ⇒ Object



57
58
59
# File 'lib/yiffspace/auth.rb', line 57

def get_by_id(id)
  @clients.values.find { |c| c.client_id == id } || raise(ArgumentError, "unable to find client with id: #{id}")
end

.register(name, &block) ⇒ Object



42
43
44
45
46
47
# File 'lib/yiffspace/auth.rb', line 42

def register(name, &block)
  client = Client.new(name)
  block&.call(client)
  @clients[name.to_sym] = client
  client
end

.spoof_auth?Boolean

Global kill switch for auth spoofing. When enabled, any client with a spoof_user_id configured logs every request in as that user instead of reading the real session - see Helper#auth/#user. There's no environment check here (mirrors enable_debug_action!) - it's on the host app to only ever call this from somewhere gated to development.

Returns:

  • (Boolean)


78
79
80
# File 'lib/yiffspace/auth.rb', line 78

def spoof_auth?
  @spoof_auth
end