Class: YiffSpace::Auth::Client
- Inherits:
-
Object
- Object
- YiffSpace::Auth::Client
- Defined in:
- lib/yiffspace/auth/client.rb
Instance Attribute Summary collapse
-
#auth_session_key ⇒ Object
Returns the value of attribute auth_session_key.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#logto_webhook_secret ⇒ Object
Returns the value of attribute logto_webhook_secret.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#permissions ⇒ Object
Returns the value of attribute permissions.
-
#permissions_separator ⇒ Object
Returns the value of attribute permissions_separator.
-
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#scopes ⇒ Object
Returns the value of attribute scopes.
-
#server_url ⇒ Object
Returns the value of attribute server_url.
-
#update_discord_images ⇒ Object
Returns the value of attribute update_discord_images.
-
#user_session_key ⇒ Object
Returns the value of attribute user_session_key.
Instance Method Summary collapse
- #fetch_discord_user(id) ⇒ Object
-
#initialize(name) ⇒ Client
constructor
A new instance of Client.
- #logto(controller) ⇒ Object
- #logto_management ⇒ Object
Constructor Details
#initialize(name) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/yiffspace/auth/client.rb', line 16 def initialize(name) @name = name.to_sym @scopes = %i[openid offline_access profile roles identities custom_data] @permissions = [] @redirect_uri = "http://127.0.0.1:3000/auth/cb" @server_url = "https://auth.yiff.space" @auth_session_key = :"yiffspace_auth_#{name}" @user_session_key = :"yiffspace_user_#{name}" @update_discord_images = true @permissions_separator = ":" @logto_webhook_secret = nil end |
Instance Attribute Details
#auth_session_key ⇒ Object
Returns the value of attribute auth_session_key.
9 10 11 |
# File 'lib/yiffspace/auth/client.rb', line 9 def auth_session_key @auth_session_key end |
#client_id ⇒ Object
Returns the value of attribute client_id.
9 10 11 |
# File 'lib/yiffspace/auth/client.rb', line 9 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
9 10 11 |
# File 'lib/yiffspace/auth/client.rb', line 9 def client_secret @client_secret end |
#logto_webhook_secret ⇒ Object
Returns the value of attribute logto_webhook_secret.
9 10 11 |
# File 'lib/yiffspace/auth/client.rb', line 9 def logto_webhook_secret @logto_webhook_secret end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/yiffspace/auth/client.rb', line 14 def name @name end |
#permissions ⇒ Object
Returns the value of attribute permissions.
9 10 11 |
# File 'lib/yiffspace/auth/client.rb', line 9 def @permissions end |
#permissions_separator ⇒ Object
Returns the value of attribute permissions_separator.
9 10 11 |
# File 'lib/yiffspace/auth/client.rb', line 9 def @permissions_separator end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
9 10 11 |
# File 'lib/yiffspace/auth/client.rb', line 9 def redirect_uri @redirect_uri end |
#resource ⇒ Object
Returns the value of attribute resource.
9 10 11 |
# File 'lib/yiffspace/auth/client.rb', line 9 def resource @resource end |
#scopes ⇒ Object
Returns the value of attribute scopes.
9 10 11 |
# File 'lib/yiffspace/auth/client.rb', line 9 def scopes @scopes end |
#server_url ⇒ Object
Returns the value of attribute server_url.
9 10 11 |
# File 'lib/yiffspace/auth/client.rb', line 9 def server_url @server_url end |
#update_discord_images ⇒ Object
Returns the value of attribute update_discord_images.
9 10 11 |
# File 'lib/yiffspace/auth/client.rb', line 9 def update_discord_images @update_discord_images end |
#user_session_key ⇒ Object
Returns the value of attribute user_session_key.
9 10 11 |
# File 'lib/yiffspace/auth/client.rb', line 9 def user_session_key @user_session_key end |
Instance Method Details
#fetch_discord_user(id) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/yiffspace/auth/client.rb', line 49 def fetch_discord_user(id) response = HTTParty.get("https://discord.com/api/v10/users/#{id}", { headers: { "Authorization" => "Bot #{YiffSpace.config.discord_bot_token}" } }) return nil if response.code == 404 raise("failed to fetch discord user: #{response.code} #{response.}\n#{response.parsed_response.inspect}") if response.code != 200 DiscordInfo.new(response.parsed_response) end |
#logto(controller) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/yiffspace/auth/client.rb', line 29 def logto(controller) LogtoClient.new( config: LogtoClient::Config.new( endpoint: server_url, app_id: client_id, app_secret: client_secret, scopes: scopes + , resources: [resource].compact, ), # Allow the client to redirect to other hosts (i.e. your Logto tenant) navigate: ->(uri) { controller.redirect_to(uri, allow_other_host: true) }, # Controller has access to the session object storage: LogtoClient::NamedSessionStorage.new("yiffspace", controller.session, app_id: @name), ) end |
#logto_management ⇒ Object
45 46 47 |
# File 'lib/yiffspace/auth/client.rb', line 45 def logto_management @logto_management ||= LogtoManagementClient.new(self) end |