2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2015-12-17 11:49:40 +00:00
|
|
|
class ExternalCredential < ApplicationModel
|
|
|
|
include ApplicationLib
|
|
|
|
|
2015-12-15 10:15:27 +00:00
|
|
|
validates :name, presence: true
|
|
|
|
store :credentials
|
2015-12-17 11:49:40 +00:00
|
|
|
|
|
|
|
def self.app_verify(params)
|
|
|
|
backend = load_backend(params[:provider])
|
|
|
|
backend.app_verify(params)
|
|
|
|
end
|
|
|
|
|
2015-12-30 13:24:13 +00:00
|
|
|
def self.request_account_to_link(provider)
|
2015-12-17 11:49:40 +00:00
|
|
|
backend = load_backend(provider)
|
2015-12-30 13:24:13 +00:00
|
|
|
backend.request_account_to_link
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.link_account(provider, request_token, params)
|
|
|
|
backend = load_backend(provider)
|
|
|
|
backend.link_account(request_token, params)
|
|
|
|
end
|
|
|
|
|
2015-12-30 13:24:13 +00:00
|
|
|
def self.callback_url(provider)
|
|
|
|
"#{Setting.get('http_type')}://#{Setting.get('fqdn')}#{Rails.configuration.api_path}/external_credentials/#{provider}/callback"
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.app_url(provider, channel_id)
|
|
|
|
"#{Setting.get('http_type')}://#{Setting.get('fqdn')}/#channels/#{provider}/#{channel_id}"
|
|
|
|
end
|
|
|
|
|
2020-05-28 13:28:07 +00:00
|
|
|
def self.refresh_token(provider, params)
|
|
|
|
backend = ExternalCredential.load_backend(provider)
|
|
|
|
backend.refresh_token(params)
|
|
|
|
end
|
|
|
|
|
2015-12-17 11:49:40 +00:00
|
|
|
def self.load_backend(provider)
|
2021-06-23 11:35:27 +00:00
|
|
|
"ExternalCredential::#{provider.camelcase}".constantize
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|
|
|
|
|
2015-12-15 10:15:27 +00:00
|
|
|
end
|