Commit 2254669
Changed files (8)
app
controllers
helpers
spec
app/controllers/oauth/clients_controller.rb
@@ -1,13 +1,8 @@
# frozen_string_literal: true
module Oauth
- class ClientsController < ApplicationController
- skip_before_action :verify_authenticity_token
- skip_before_action :authenticate!
+ class ClientsController < ActionController::API
before_action :apply_cache_headers
- before_action do
- request.session_options[:skip] = true
- end
def create
@client = Client.create!(transform(secure_params))
app/controllers/oauth/controller.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+module Oauth
+ class Controller < ActionController::API
+ include Api
+ end
+end
app/controllers/oauth/mes_controller.rb
@@ -1,7 +1,10 @@
# frozen_string_literal: true
module Oauth
- class MesController < ApplicationController
+ class MesController < ActionController::API
+ include ActionController::HttpAuthentication::Token::ControllerMethods
+ before_action :authenticate!
+
def show
render json: @claims
end
app/controllers/oauth/metadata_controller.rb
@@ -1,12 +1,7 @@
# frozen_string_literal: true
module Oauth
- class MetadataController < ApplicationController
- skip_before_action :authenticate!
- before_action do
- request.session_options[:skip] = true
- end
-
+ class MetadataController < ActionController::API
def show
render formats: :json
end
app/controllers/oauth/tokens_controller.rb
@@ -1,11 +1,9 @@
# frozen_string_literal: true
module Oauth
- class TokensController < ApplicationController
- skip_before_action :verify_authenticity_token
- before_action do
- request.session_options[:skip] = true
- end
+ class TokensController < ActionController::API
+ include ActionController::HttpAuthentication::Basic::ControllerMethods
+ before_action :authenticate!
def create
response.headers['Cache-Control'] = 'no-store'
app/controllers/scim/controller.rb
@@ -1,12 +1,12 @@
# frozen_string_literal: true
module Scim
- class Controller < ActionController::Base
- protect_from_forgery with: :null_session
+ class Controller < ActionController::API
+ include ActionController::HttpAuthentication::Token::ControllerMethods
before_action :apply_scim_content_type
before_action :ensure_correct_content_type!
before_action :authenticate!
- helper_method :current_user
+ helper_method :current_user, :scim_type_for
rescue_from StandardError do |error|
Rails.logger.error(error)
render "server_error", status: :server_error
@@ -62,5 +62,17 @@ module Scim
def acceptable_content_type?
[:scim, :json].include?(request&.content_mime_type&.symbol)
end
+
+ def scim_type_for(error)
+ case error
+ when ActiveRecord::RecordInvalid
+ errors = error.record.errors.full_messages
+ if errors.count == 1 &&
+ errors[0].end_with?('has already been taken')
+ return 'uniqueness'
+ end
+ end
+ "invalidValue"
+ end
end
end
app/helpers/application_helper.rb
@@ -26,16 +26,4 @@ module ApplicationHelper
'🤷'
end
end
-
- def scim_type_for(error)
- case error
- when ActiveRecord::RecordInvalid
- errors = error.record.errors.full_messages
- if errors.count == 1 &&
- errors[0].end_with?('has already been taken')
- return 'uniqueness'
- end
- end
- "invalidValue"
- end
end
spec/documentation.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require File.expand_path('../../config/environment', __FILE__)
+
+require File.expand_path('../config/environment', __dir__)
require 'rspec/rails'
require 'vcr'
require 'ffaker'