Class: LogtoClient::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/logto/client/index_types.rb

Overview

The configuration object for the Logto client.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint:, app_id:, app_secret:, scopes: [], resources: [], prompt: , include_reserved_scopes: true) ⇒ Config

Returns a new instance of Config.

Parameters:

  • endpoint (String, URI)

    The endpoint for the Logto server.

  • app_id (String)

    The client ID of your application.

  • app_secret (String)

    The client secret of your application.

  • scopes (Array<String>) (defaults to: [])

    The scopes that your application needs to access.

  • resources (Array<String>) (defaults to: [])

    The API resources that your application needs to access.

  • prompt (String, Array<String>) (defaults to: )

    The prompt parameter to be used for the authorization request.

  • include_reserved_scopes (Boolean) (defaults to: true)

    Whether to include reserved scopes (‘openid`, `offline_access` and `profile`) in the scopes.

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/logto/client/index_types.rb', line 36

def initialize(endpoint:, app_id:, app_secret:, scopes: [], resources: [], prompt: LogtoCore::PROMPT[:consent], include_reserved_scopes: true)
  raise ArgumentError, "Scopes must be an array" if scopes && !scopes.is_a?(Array)
  raise ArgumentError, "Resources must be an array" if resources && !resources.is_a?(Array)
  raise ArgumentError, "Endpoint must not be empty" if endpoint.nil? || endpoint == ""

  computed_scopes = include_reserved_scopes ? LogtoUtils.with_reserved_scopes(scopes) : scopes

  @endpoint = endpoint.is_a?(URI) ? endpoint : URI.parse(endpoint)
  @app_id = app_id
  @app_secret = app_secret
  @scopes = computed_scopes
  @resources = computed_scopes.include?(LogtoCore::USER_SCOPE[:organizations]) ? ([LogtoCore::RESERVED_RESOURCE[:organization]] + resources).uniq : resources
  @prompt = prompt.is_a?(Array) ? prompt : [prompt]
end

Instance Attribute Details

#app_idString

The client ID of your application, you can get it from the integration guide or the application details page of the Logto Console.

Returns:

  • (String)

    the current value of app_id



26
27
28
# File 'lib/logto/client/index_types.rb', line 26

def app_id
  @app_id
end

#app_secretString

The client secret of your application, you can get it from the application details page of the Logto Console.

Returns:

  • (String)

    the current value of app_secret



26
27
28
# File 'lib/logto/client/index_types.rb', line 26

def app_secret
  @app_secret
end

#endpointURI

The endpoint for the Logto server, you can get it from the integration guide or the team settings page of the Logto Console.

Examples:

'https://foo.logto.app'

Returns:

  • (URI)

    the current value of endpoint



26
27
28
# File 'lib/logto/client/index_types.rb', line 26

def endpoint
  @endpoint
end

#promptArray<String>

The prompt parameter to be used for the authorization request.

Returns:

  • (Array<String>)

    the current value of prompt



26
27
28
# File 'lib/logto/client/index_types.rb', line 26

def prompt
  @prompt
end

#resourcesArray<String>

The API resources that your application needs to access. You can specify multiple resources by providing an array of strings.

See RBAC to learn more about how to use role-based access control (RBAC) to protect API resources.

Returns:

  • (Array<String>)

    the current value of resources



26
27
28
# File 'lib/logto/client/index_types.rb', line 26

def resources
  @resources
end

#scopesArray<String>

The scopes (permissions) that your application needs to access. Scopes that will be added by default: ‘openid`, `offline_access` and `profile`. If resources are specified, scopes will be applied to every resource.

See Scopes and claims for more information of available scopes for user information.

Returns:

  • (Array<String>)

    the current value of scopes



26
27
28
# File 'lib/logto/client/index_types.rb', line 26

def scopes
  @scopes
end