external_credential.rb 1011 B

123456789101112131415161718192021222324252627282930313233343536
  1. class ExternalCredential < ApplicationModel
  2. include ApplicationLib
  3. validates :name, presence: true
  4. store :credentials
  5. def self.app_verify(params)
  6. backend = load_backend(params[:provider])
  7. backend.app_verify(params)
  8. end
  9. def self.request_account_to_link(provider)
  10. backend = load_backend(provider)
  11. backend.request_account_to_link
  12. end
  13. def self.link_account(provider, request_token, params)
  14. backend = load_backend(provider)
  15. backend.link_account(request_token, params)
  16. end
  17. def self.callback_url(provider)
  18. "#{Setting.get('http_type')}://#{Setting.get('fqdn')}#{Rails.configuration.api_path}/external_credentials/#{provider}/callback"
  19. end
  20. def self.app_url(provider, channel_id)
  21. "#{Setting.get('http_type')}://#{Setting.get('fqdn')}/#channels/#{provider}/#{channel_id}"
  22. end
  23. def self.load_backend(provider)
  24. adapter = "ExternalCredential::#{provider.camelcase}"
  25. require_dependency adapter.to_filename.to_s
  26. load_adapter(adapter)
  27. end
  28. end