external_credential.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class ExternalCredential < ApplicationModel
  3. include ApplicationLib
  4. validates :name, presence: true
  5. store :credentials
  6. def self.app_verify(params)
  7. backend = load_backend(params[:provider])
  8. backend.app_verify(params)
  9. end
  10. def self.request_account_to_link(provider, params = {})
  11. backend = load_backend(provider)
  12. backend.request_account_to_link(params)
  13. end
  14. def self.link_account(provider, request_token, params)
  15. backend = load_backend(provider)
  16. backend.link_account(request_token, params)
  17. end
  18. def self.callback_url(provider)
  19. "#{Setting.get('http_type')}://#{Setting.get('fqdn')}#{Rails.configuration.api_path}/external_credentials/#{provider}/callback"
  20. end
  21. def self.app_url(provider, channel_id)
  22. "#{Setting.get('http_type')}://#{Setting.get('fqdn')}/#channels/#{provider}/#{channel_id}"
  23. end
  24. def self.refresh_token(provider, params)
  25. backend = ExternalCredential.load_backend(provider)
  26. backend.refresh_token(params)
  27. end
  28. def self.load_backend(provider)
  29. "ExternalCredential::#{provider.camelcase}".constantize
  30. end
  31. end