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/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
Defined Under Namespace
Modules: Helper
Classes: AuthInfo, Client, DiscordInfo, Engine, ExchangeResponse, Permissions, SerializeError, SetClientName, UserInfo
Constant Summary
collapse
- CLIENT_NAME_ENV =
"yiffspace.auth.client_name"
- DEFAULT_CLIENT_NAME =
:default
Class Method Summary
collapse
Class Method Details
.[](name) ⇒ Object
25
26
27
|
# File 'lib/yiffspace/auth.rb', line 25
def [](name)
@clients[name.to_sym] or raise(KeyError, "unknown auth client: #{name.inspect}")
end
|
.default ⇒ Object
29
30
31
|
# File 'lib/yiffspace/auth.rb', line 29
def default
@clients[DEFAULT_CLIENT_NAME] || raise("no default client configured")
end
|
.disable_debug_action! ⇒ Object
80
81
82
|
# File 'lib/yiffspace/auth.rb', line 80
def disable_debug_action!
@enable_debug_action = false
end
|
.enable_debug_action! ⇒ Object
76
77
78
|
# File 'lib/yiffspace/auth.rb', line 76
def enable_debug_action!
@enable_debug_action = true
end
|
.enable_debug_action? ⇒ Boolean
72
73
74
|
# File 'lib/yiffspace/auth.rb', line 72
def enable_debug_action?
@enable_debug_action
end
|
.find_by_client_id(client_id) ⇒ Object
33
34
35
|
# File 'lib/yiffspace/auth.rb', line 33
def find_by_client_id(client_id)
@clients.values.find { |c| c.oidc_client.identifier == client_id }
end
|
.register(name, &block) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/yiffspace/auth.rb', line 18
def register(name, &block)
client = Client.new(name)
block&.call(client)
@clients[name.to_sym] = client
client
end
|
.serialize_token(token) ⇒ Object
37
38
39
|
# File 'lib/yiffspace/auth.rb', line 37
def serialize_token(token)
{ attributes: token.raw_attributes.without("client"), client_id: token.client.identifier }
end
|
.serialize_user(user, client_id:) ⇒ Object
55
56
57
|
# File 'lib/yiffspace/auth.rb', line 55
def serialize_user(user, client_id:)
{ attributes: user.raw_attributes, client_id: client_id }
end
|
.unserialize_token(data) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/yiffspace/auth.rb', line 41
def unserialize_token(data)
raise(SerializeError, "no token data provided") if data.blank?
return data if data.is_a?(OpenIDConnect::AccessToken)
data = JSON.parse(data) if data.is_a?(String)
data = ::YiffSpace::Utils::OpenHash.from(data)
raise(SerializeError, "no client id for token, refusing to reconstruct") if data.client_id.nil?
client_config = find_by_client_id(data.client_id)
raise(SerializeError, "unknown client_id #{data.client_id.inspect}") unless client_config
OpenIDConnect::AccessToken.new(data.attributes.merge(client: client_config.oidc_client))
end
|
.unserialize_user(data) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/yiffspace/auth.rb', line 59
def unserialize_user(data)
raise(SerializeError, "no user data provided") if data.blank?
return data if data.is_a?(OpenIDConnect::ResponseObject::UserInfo)
data = JSON.parse(data) if data.is_a?(String)
data = ::YiffSpace::Utils::OpenHash.from(data)
raise(SerializeError, "no client id for user, refusing to reconstruct") if data.client_id.nil?
find_by_client_id(data.client_id) or raise(SerializeError, "unknown client_id #{data.client_id.inspect}")
OpenIDConnect::ResponseObject::UserInfo.new(data.attributes)
end
|