2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2015-12-17 11:49:40 +00:00
|
|
|
|
|
|
|
class ExternalCredentialsController < ApplicationController
|
2020-03-19 09:39:51 +00:00
|
|
|
prepend_before_action { authentication_check && authorize! }
|
2015-12-17 11:49:40 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
model_index_render(ExternalCredential, params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
model_show_render(ExternalCredential, params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-12-21 00:48:49 +00:00
|
|
|
model_create_render(ExternalCredential, params)
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-12-21 00:48:49 +00:00
|
|
|
model_update_render(ExternalCredential, params)
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2016-11-30 10:30:03 +00:00
|
|
|
model_destroy_render(ExternalCredential, params)
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|
|
|
|
|
2015-12-21 00:48:49 +00:00
|
|
|
def app_verify
|
2018-12-03 14:10:36 +00:00
|
|
|
render json: { attributes: ExternalCredential.app_verify(params.permit!.to_h) }, status: :ok
|
2015-12-21 00:48:49 +00:00
|
|
|
rescue => e
|
2019-09-03 18:23:29 +00:00
|
|
|
logger.error e
|
2015-12-21 00:48:49 +00:00
|
|
|
render json: { error: e.message }, status: :ok
|
|
|
|
end
|
|
|
|
|
2015-12-17 11:49:40 +00:00
|
|
|
def link_account
|
|
|
|
provider = params[:provider].downcase
|
2015-12-30 13:24:13 +00:00
|
|
|
attributes = ExternalCredential.request_account_to_link(provider)
|
2015-12-17 11:49:40 +00:00
|
|
|
session[:request_token] = attributes[:request_token]
|
2020-11-20 13:58:57 +00:00
|
|
|
session[:channel_id] = params[:channel_id]
|
2015-12-17 11:49:40 +00:00
|
|
|
redirect_to attributes[:authorize_url]
|
|
|
|
end
|
|
|
|
|
|
|
|
def callback
|
|
|
|
provider = params[:provider].downcase
|
2020-11-20 13:58:57 +00:00
|
|
|
channel = ExternalCredential.link_account(provider, session[:request_token], link_params)
|
2015-12-17 11:49:40 +00:00
|
|
|
session[:request_token] = nil
|
2020-11-20 13:58:57 +00:00
|
|
|
session[:channel_id] = nil
|
2015-12-21 00:48:49 +00:00
|
|
|
redirect_to app_url(provider, channel.id)
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-11-20 13:58:57 +00:00
|
|
|
def link_params
|
|
|
|
params.permit!.to_h.merge(channel_id: session[:channel_id])
|
|
|
|
end
|
|
|
|
|
2015-12-17 11:49:40 +00:00
|
|
|
def callback_url(provider)
|
2015-12-30 13:24:13 +00:00
|
|
|
ExternalCredential.callback_url(provider)
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|
|
|
|
|
2015-12-21 00:48:49 +00:00
|
|
|
def app_url(provider, channel_id)
|
2015-12-30 13:24:13 +00:00
|
|
|
ExternalCredential.app_url(provider, channel_id)
|
2015-12-21 00:48:49 +00:00
|
|
|
end
|
2015-12-17 11:49:40 +00:00
|
|
|
end
|