Class: YiffSpace::Auth::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/yiffspace/auth/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/yiffspace/auth/client.rb', line 14

def initialize(name)
  @name                    = name.to_sym
  @scopes                  = %i[openid offline_access profile roles identities]
  @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   = ":"
end

Instance Attribute Details

#auth_session_keyObject

Returns the value of attribute auth_session_key.



8
9
10
# File 'lib/yiffspace/auth/client.rb', line 8

def auth_session_key
  @auth_session_key
end

#client_idObject

Returns the value of attribute client_id.



8
9
10
# File 'lib/yiffspace/auth/client.rb', line 8

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



8
9
10
# File 'lib/yiffspace/auth/client.rb', line 8

def client_secret
  @client_secret
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/yiffspace/auth/client.rb', line 12

def name
  @name
end

#permissionsObject

Returns the value of attribute permissions.



8
9
10
# File 'lib/yiffspace/auth/client.rb', line 8

def permissions
  @permissions
end

#permissions_separatorObject

Returns the value of attribute permissions_separator.



8
9
10
# File 'lib/yiffspace/auth/client.rb', line 8

def permissions_separator
  @permissions_separator
end

#redirect_uriObject

Returns the value of attribute redirect_uri.



8
9
10
# File 'lib/yiffspace/auth/client.rb', line 8

def redirect_uri
  @redirect_uri
end

#resourceObject

Returns the value of attribute resource.



8
9
10
# File 'lib/yiffspace/auth/client.rb', line 8

def resource
  @resource
end

#scopesObject

Returns the value of attribute scopes.



8
9
10
# File 'lib/yiffspace/auth/client.rb', line 8

def scopes
  @scopes
end

#server_urlObject

Returns the value of attribute server_url.



8
9
10
# File 'lib/yiffspace/auth/client.rb', line 8

def server_url
  @server_url
end

#update_discord_imagesObject

Returns the value of attribute update_discord_images.



8
9
10
# File 'lib/yiffspace/auth/client.rb', line 8

def update_discord_images
  @update_discord_images
end

#user_session_keyObject

Returns the value of attribute user_session_key.



8
9
10
# File 'lib/yiffspace/auth/client.rb', line 8

def user_session_key
  @user_session_key
end

Instance Method Details

#logto(controller) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/yiffspace/auth/client.rb', line 26

def logto(controller)
  LogtoClient.new(
    config:   LogtoClient::Config.new(
      endpoint:   server_url,
      app_id:     client_id,
      app_secret: client_secret,
      scopes:     scopes + permissions,
      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