Class: TRMNLP::OAuth::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/trmnlp/oauth/provider.rb

Overview

Provider definition from the flat oauth_* keys in src/settings.yml (which round-trip through push/pull). Credentials stay local and env-first so they are never synced or committed.

Constant Summary collapse

ENV_CLIENT_ID =
'TRMNL_OAUTH_CLIENT_ID'
ENV_CLIENT_SECRET =
'TRMNL_OAUTH_CLIENT_SECRET'

Instance Method Summary collapse

Constructor Details

#initialize(settings, env: ENV) ⇒ Provider

Returns a new instance of Provider.



12
13
14
15
# File 'lib/trmnlp/oauth/provider.rb', line 12

def initialize(settings, env: ENV)
  @settings = settings || {}
  @env = env
end

Instance Method Details

#authorize_urlObject



17
# File 'lib/trmnlp/oauth/provider.rb', line 17

def authorize_url = settings['oauth_authorize_url']

#client_idObject



24
# File 'lib/trmnlp/oauth/provider.rb', line 24

def client_id = env_first(ENV_CLIENT_ID, settings['oauth_client_id'])

#client_secretObject



25
# File 'lib/trmnlp/oauth/provider.rb', line 25

def client_secret = env_first(ENV_CLIENT_SECRET, settings['oauth_client_secret'])

#configured?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/trmnlp/oauth/provider.rb', line 27

def configured?
  return false unless enabled? && authorize_url && token_url && client_id

  pkce? || present?(client_secret)
end

#enabled?Boolean

Returns:

  • (Boolean)


23
# File 'lib/trmnlp/oauth/provider.rb', line 23

def enabled? = truthy?(settings['oauth_enabled'])

#pkce?Boolean

Returns:

  • (Boolean)


22
# File 'lib/trmnlp/oauth/provider.rb', line 22

def pkce? = truthy?(settings['oauth_pkce_enabled'])

#refresh_urlObject



19
# File 'lib/trmnlp/oauth/provider.rb', line 19

def refresh_url = settings['oauth_refresh_url'] || token_url

#scope_separatorObject



21
# File 'lib/trmnlp/oauth/provider.rb', line 21

def scope_separator = settings['oauth_scope_separator'] || ' '

#scopesObject



20
# File 'lib/trmnlp/oauth/provider.rb', line 20

def scopes = settings['oauth_scopes']

#token_urlObject



18
# File 'lib/trmnlp/oauth/provider.rb', line 18

def token_url = settings['oauth_token_url']