2018-09-14 05:42:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-22 08:57:31 +00:00
|
|
|
module OauthApplications
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2021-11-04 15:10:58 +00:00
|
|
|
CREATED_SESSION_KEY = :oauth_applications_created
|
|
|
|
|
2016-11-22 08:57:31 +00:00
|
|
|
included do
|
|
|
|
before_action :prepare_scopes, only: [:create, :update]
|
|
|
|
end
|
|
|
|
|
|
|
|
def prepare_scopes
|
2016-12-16 21:59:53 +00:00
|
|
|
scopes = params.fetch(:doorkeeper_application, {}).fetch(:scopes, nil)
|
2016-11-24 07:37:22 +00:00
|
|
|
|
2016-11-22 08:57:31 +00:00
|
|
|
if scopes
|
|
|
|
params[:doorkeeper_application][:scopes] = scopes.join(' ')
|
|
|
|
end
|
|
|
|
end
|
2016-11-24 07:37:22 +00:00
|
|
|
|
2021-11-04 15:10:58 +00:00
|
|
|
def set_created_session
|
|
|
|
session[CREATED_SESSION_KEY] = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_created_session
|
|
|
|
session.delete(CREATED_SESSION_KEY) || false
|
|
|
|
end
|
|
|
|
|
2016-11-24 07:37:22 +00:00
|
|
|
def load_scopes
|
2017-09-18 17:25:23 +00:00
|
|
|
@scopes ||= Doorkeeper.configuration.scopes
|
2016-11-24 07:37:22 +00:00
|
|
|
end
|
2021-09-17 15:11:44 +00:00
|
|
|
|
|
|
|
def permitted_params
|
2022-05-11 00:08:02 +00:00
|
|
|
%i{name redirect_uri scopes confidential}
|
2021-09-17 15:11:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def application_params
|
|
|
|
params
|
|
|
|
.require(:doorkeeper_application)
|
|
|
|
.permit(*permitted_params)
|
|
|
|
end
|
2016-11-22 08:57:31 +00:00
|
|
|
end
|