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
|
|
|
|
|
2015-12-17 11:49:40 +00:00
|
|
|
def self.load_backend(provider)
|
|
|
|
adapter = "ExternalCredential::#{provider.camelcase}"
|
2018-10-18 12:22:02 +00:00
|
|
|
require_dependency adapter.to_filename.to_s
|
2019-01-06 18:41:29 +00:00
|
|
|
adapter.constantize
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|
|
|
|
|
2015-12-15 10:15:27 +00:00
|
|
|
end
|