2016-03-23 18:39:41 +01:00
|
|
|
class API::AuthProvidersController < API::ApiController
|
|
|
|
|
|
|
|
before_action :set_provider, only: [:show, :update, :destroy]
|
|
|
|
|
|
|
|
def index
|
|
|
|
@providers = policy_scope(AuthProvider)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
authorize AuthProvider
|
|
|
|
@provider = AuthProvider.new(provider_params)
|
|
|
|
if @provider.save
|
|
|
|
render :show, status: :created, location: @provider
|
|
|
|
else
|
|
|
|
render json: @provider.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
authorize AuthProvider
|
|
|
|
if @provider.update(provider_params)
|
|
|
|
render :show, status: :ok, location: @provider
|
|
|
|
else
|
|
|
|
render json: @provider.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
authorize AuthProvider
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
authorize AuthProvider
|
2016-09-26 12:41:59 +02:00
|
|
|
if @provider.safe_destroy
|
|
|
|
head :no_content
|
|
|
|
else
|
|
|
|
render json: @provider.errors, status: :unprocessable_entity
|
|
|
|
end
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def mapping_fields
|
|
|
|
authorize AuthProvider
|
|
|
|
render :mapping_fields, status: :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
def active
|
|
|
|
authorize AuthProvider
|
|
|
|
@provider = AuthProvider.active
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_provider
|
|
|
|
@provider = AuthProvider.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def provider_params
|
|
|
|
if params['auth_provider']['providable_type'] == DatabaseProvider.name
|
|
|
|
params.require(:auth_provider).permit(:name, :providable_type)
|
|
|
|
elsif params['auth_provider']['providable_type'] == OAuth2Provider.name
|
|
|
|
params.require(:auth_provider).permit(:name, :providable_type, providable_attributes: [
|
2016-09-26 12:41:59 +02:00
|
|
|
:id, :base_url, :token_endpoint, :authorization_endpoint, :logout_endpoint, :profile_url, :client_id, :client_secret,
|
2016-03-23 18:39:41 +01:00
|
|
|
o_auth2_mappings_attributes: [
|
2016-09-15 15:58:21 +02:00
|
|
|
:id, :local_model, :local_field, :api_field, :api_endpoint, :api_data_type, :_destroy,
|
2016-09-15 17:10:41 +02:00
|
|
|
transformation: [:type, :format, :true_value, :false_value, mapping: [:from, :to]]
|
2016-03-23 18:39:41 +01:00
|
|
|
]
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|