Override forgery settings in controllers
ClientsController and TokenEndpointController are called from the outside, so CSRF verification prevents them from normal operation. closes #7062
This commit is contained in:
parent
1c1c9d6794
commit
cdcf2d747e
6 changed files with 38 additions and 1 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
module Api
|
module Api
|
||||||
module OpenidConnect
|
module OpenidConnect
|
||||||
class ClientsController < ApplicationController
|
class ClientsController < ApplicationController
|
||||||
|
skip_before_action :verify_authenticity_token
|
||||||
|
|
||||||
rescue_from OpenIDConnect::HttpError do |e|
|
rescue_from OpenIDConnect::HttpError do |e|
|
||||||
http_error_page_as_json(e)
|
http_error_page_as_json(e)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
module Api
|
module Api
|
||||||
module OpenidConnect
|
module OpenidConnect
|
||||||
class TokenEndpointController < ApplicationController
|
class TokenEndpointController < ApplicationController
|
||||||
|
skip_before_action :verify_authenticity_token
|
||||||
|
|
||||||
def create
|
def create
|
||||||
req = Rack::Request.new(request.env)
|
req = Rack::Request.new(request.env)
|
||||||
if req["client_assertion_type"] == "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
|
if req["client_assertion_type"] == "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
require "spec_helper"
|
require "spec_helper"
|
||||||
|
|
||||||
describe Api::OpenidConnect::ClientsController, type: :controller do
|
describe Api::OpenidConnect::ClientsController, type: :controller, suppress_csrf_verification: :none do
|
||||||
describe "#create" do
|
describe "#create" do
|
||||||
context "when valid parameters are passed" do
|
context "when valid parameters are passed" do
|
||||||
it "should return a client id" do
|
it "should return a client id" do
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe Api::OpenidConnect::TokenEndpointController, type: :controller, suppress_csrf_verification: :none do
|
||||||
|
let(:auth) { FactoryGirl.create(:auth_with_read) }
|
||||||
|
|
||||||
|
describe "#create" do
|
||||||
|
it "returns 200 on success" do
|
||||||
|
post :create,
|
||||||
|
grant_type: "authorization_code",
|
||||||
|
code: auth.create_code,
|
||||||
|
redirect_uri: auth.redirect_uri,
|
||||||
|
scope: auth.scopes.join(" "),
|
||||||
|
client_id: auth.o_auth_application.client_id,
|
||||||
|
client_secret: auth.o_auth_application.client_secret
|
||||||
|
expect(response.code).to eq("200")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -366,18 +366,27 @@ FactoryGirl.define do
|
||||||
o_auth_application
|
o_auth_application
|
||||||
user
|
user
|
||||||
scopes %w(openid sub aud profile picture nickname name read)
|
scopes %w(openid sub aud profile picture nickname name read)
|
||||||
|
after(:build) {|m|
|
||||||
|
m.redirect_uri = m.o_auth_application.redirect_uris[0]
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :auth_with_read_and_ppid, class: Api::OpenidConnect::Authorization do
|
factory :auth_with_read_and_ppid, class: Api::OpenidConnect::Authorization do
|
||||||
association :o_auth_application, factory: :o_auth_application_with_ppid
|
association :o_auth_application, factory: :o_auth_application_with_ppid
|
||||||
user
|
user
|
||||||
scopes %w(openid sub aud profile picture nickname name read)
|
scopes %w(openid sub aud profile picture nickname name read)
|
||||||
|
after(:build) {|m|
|
||||||
|
m.redirect_uri = m.o_auth_application.redirect_uris[0]
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :auth_with_read_and_write, class: Api::OpenidConnect::Authorization do
|
factory :auth_with_read_and_write, class: Api::OpenidConnect::Authorization do
|
||||||
o_auth_application
|
o_auth_application
|
||||||
user
|
user
|
||||||
scopes %w(openid sub aud profile picture nickname name read write)
|
scopes %w(openid sub aud profile picture nickname name read write)
|
||||||
|
after(:build) {|m|
|
||||||
|
m.redirect_uri = m.o_auth_application.redirect_uris[0]
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Factories for the DiasporaFederation-gem
|
# Factories for the DiasporaFederation-gem
|
||||||
|
|
|
||||||
|
|
@ -143,3 +143,9 @@ Shoulda::Matchers.configure do |config|
|
||||||
with.library :rails
|
with.library :rails
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
shared_context suppress_csrf_verification: :none do
|
||||||
|
before do
|
||||||
|
ActionController::Base.allow_forgery_protection = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue