Files
openfoodnetwork/engines/dfc_provider/app/services/api_user.rb
Maikel Linke f2f0d954c6 Move source of truth of platforms into one place
The first test tokens had an inconsistent client_id and I had to
introduce multiple mappings to get the right config. But that has been
harmonised and we can put the config in one place.
2025-10-10 16:18:22 +11:00

57 lines
1.3 KiB
Ruby

# frozen_string_literal: true
# Authorised user or client using the API
class ApiUser
PLATFORMS = {
'cqcm-dev' => {
id: "https://api.proxy-dev.cqcm.startinblox.com/profile",
tokens: "https://kc.cqcm.startinblox.com/realms/startinblox/protocol/openid-connect/token",
},
'cqcm-stg' => {
id: "https://api.proxy-stg.cqcm.startinblox.com/profile",
tokens: "https://kc.cqcm.startinblox.com/realms/startinblox/protocol/openid-connect/token",
},
'cqcm' => {
id: "https://carte.cqcm.coop/profile",
tokens: "https://authentification.cqcm.coop/realms/cqcm/protocol/openid-connect/token",
},
}.freeze
CLIENT_MAP = PLATFORMS.keys.index_by { |key| PLATFORMS.dig(key, :id) }.freeze
def self.platform_url(platform)
PLATFORMS.dig(platform, :id)
end
def self.token_endpoint(platform)
PLATFORMS.dig(platform, :tokens)
end
def self.from_client_id(client_id)
id = CLIENT_MAP[client_id]
new(id) if id
end
attr_reader :id
def initialize(id)
@id = id
end
def admin?
false
end
def customers
Customer.none
end
def enterprises
Enterprise.where(dfc_permissions: permissions("ReadEnterprise"))
end
def permissions(scope)
DfcPermission.where(grantee: id, scope:)
end
end