external_credentials_controller.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class ExternalCredentialsController < ApplicationController
  3. prepend_before_action { authentication_check(permission: ['admin.channel_twitter', 'admin.channel_facebook']) }
  4. def index
  5. model_index_render(ExternalCredential, params)
  6. end
  7. def show
  8. model_show_render(ExternalCredential, params)
  9. end
  10. def create
  11. model_create_render(ExternalCredential, params)
  12. end
  13. def update
  14. model_update_render(ExternalCredential, params)
  15. end
  16. def destroy
  17. model_destroy_render(ExternalCredential, params)
  18. end
  19. def app_verify
  20. attributes = ExternalCredential.app_verify(params)
  21. render json: { attributes: attributes }, status: :ok
  22. rescue => e
  23. render json: { error: e.message }, status: :ok
  24. end
  25. def link_account
  26. provider = params[:provider].downcase
  27. attributes = ExternalCredential.request_account_to_link(provider)
  28. session[:request_token] = attributes[:request_token]
  29. redirect_to attributes[:authorize_url]
  30. end
  31. def callback
  32. provider = params[:provider].downcase
  33. channel = ExternalCredential.link_account(provider, session[:request_token], params)
  34. session[:request_token] = nil
  35. redirect_to app_url(provider, channel.id)
  36. end
  37. private
  38. def callback_url(provider)
  39. ExternalCredential.callback_url(provider)
  40. end
  41. def app_url(provider, channel_id)
  42. ExternalCredential.app_url(provider, channel_id)
  43. end
  44. end