external_credentials_controller.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class ExternalCredentialsController < ApplicationController
  3. prepend_before_action { authentication_check && authorize! }
  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. render json: { attributes: ExternalCredential.app_verify(params.permit!.to_h) }, status: :ok
  21. rescue => e
  22. logger.error 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.permit!.to_h)
  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