Fix remaining remarks
This commit is contained in:
parent
d028b5672e
commit
f1b394de0f
7 changed files with 18 additions and 28 deletions
|
|
@ -9,7 +9,7 @@ module Api
|
|||
|
||||
rescue_from OpenSSL::SSL::SSLError do |e|
|
||||
logger.info e.backtrace[0, 10].join("\n")
|
||||
handle_params_error("ssl_error", e.message)
|
||||
handle_params_error("bad_request", e.message)
|
||||
end
|
||||
|
||||
before_action :auth_user_unless_prompt_none!
|
||||
|
|
|
|||
|
|
@ -26,8 +26,7 @@ module Api
|
|||
def fetch_public_key(o_auth_app, jwt)
|
||||
public_key = fetch_public_key_from_json(o_auth_app.jwks, jwt)
|
||||
if public_key.empty? && o_auth_app.jwks_uri
|
||||
uri = URI.parse(o_auth_app.jwks_uri)
|
||||
response = Net::HTTP.get_response(uri)
|
||||
response = Faraday.get(o_auth_app.jwks_uri)
|
||||
public_key = fetch_public_key_from_json(response.body, jwt)
|
||||
end
|
||||
raise Rack::OAuth2::Server::Authorize::BadRequest(:unauthorized_client) if public_key.empty?
|
||||
|
|
|
|||
|
|
@ -67,8 +67,7 @@ module Api
|
|||
auth.destroy
|
||||
nil
|
||||
else
|
||||
auth.code_used = true
|
||||
auth.save
|
||||
auth.update!(code_used: true)
|
||||
auth
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -50,8 +50,7 @@ module Api
|
|||
def check_sector_identifier_uri(attributes)
|
||||
sector_identifier_uri = attributes[:sector_identifier_uri]
|
||||
return unless sector_identifier_uri
|
||||
uri = URI.parse(sector_identifier_uri)
|
||||
response = Net::HTTP.get_response(uri)
|
||||
response = Faraday.get(sector_identifier_uri)
|
||||
sector_identifier_uri_json = JSON.parse(response.body)
|
||||
redirect_uris = attributes[:redirect_uris]
|
||||
sector_identifier_uri_includes_redirect_uris = (redirect_uris - sector_identifier_uri_json).empty?
|
||||
|
|
@ -80,8 +79,7 @@ module Api
|
|||
if key == :subject_type
|
||||
attr[:ppid] = (value == "pairwise")
|
||||
elsif key == :jwks_uri
|
||||
uri = URI.parse(value)
|
||||
response = Net::HTTP.get_response(uri)
|
||||
response = Faraday.get(value)
|
||||
attr[:jwks] = response.body
|
||||
attr[:jwks_uri] = value
|
||||
elsif key == :jwks
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
module Api
|
||||
module OpenidConnect
|
||||
module Error
|
||||
class InvalidRedirectUri < ::ArgumentError
|
||||
def initialize
|
||||
super "Redirect uri contains fragment"
|
||||
end
|
||||
end
|
||||
class InvalidSectorIdentifierUri < ::ArgumentError
|
||||
def initialize
|
||||
super "Invalid sector identifier uri"
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
module Api
|
||||
module OpenidConnect
|
||||
module Error
|
||||
class InvalidRedirectUri < ::ArgumentError
|
||||
def initialize
|
||||
super "Redirect uri contains fragment"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -5,8 +5,8 @@ describe Api::OpenidConnect::ClientsController, type: :controller do
|
|||
context "when valid parameters are passed" do
|
||||
it "should return a client id" do
|
||||
stub_request(:get, "http://example.com/uris")
|
||||
.with(headers: {:Accept => "*/*", :"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
||||
:Host => "example.com", :"User-Agent" => "Ruby"})
|
||||
.with(headers: {Accept: "*/*", :"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
||||
:"User-Agent" => "Faraday v0.9.1"})
|
||||
.to_return(status: 200, body: "[\"http://localhost\"]", headers: {})
|
||||
post :create, redirect_uris: ["http://localhost"], client_name: "diaspora client",
|
||||
response_types: [], grant_types: [], application_type: "web", contacts: [],
|
||||
|
|
@ -22,8 +22,8 @@ describe Api::OpenidConnect::ClientsController, type: :controller do
|
|||
context "when valid parameters with jwks is passed" do
|
||||
it "should return a client id" do
|
||||
stub_request(:get, "http://example.com/uris")
|
||||
.with(headers: {:Accept => "*/*", :"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
||||
:Host => "example.com", :"User-Agent" => "Ruby"})
|
||||
.with(headers: {Accept: "*/*", :"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
||||
:"User-Agent" => "Faraday v0.9.1"})
|
||||
.to_return(status: 200, body: "[\"http://localhost\"]", headers: {})
|
||||
post :create, redirect_uris: ["http://localhost"], client_name: "diaspora client",
|
||||
response_types: [], grant_types: [], application_type: "web", contacts: [],
|
||||
|
|
@ -80,12 +80,12 @@ describe Api::OpenidConnect::ClientsController, type: :controller do
|
|||
context "when valid parameters with jwks_uri is passed" do
|
||||
it "should return a client id" do
|
||||
stub_request(:get, "http://example.com/uris")
|
||||
.with(headers: {:Accept => "*/*", :"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
||||
:Host => "example.com", :"User-Agent" => "Ruby"})
|
||||
.with(headers: {Accept: "*/*", :"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
||||
:"User-Agent" => "Faraday v0.9.1"})
|
||||
.to_return(status: 200, body: "[\"http://localhost\"]", headers: {})
|
||||
stub_request(:get, "https://kentshikama.com/api/openid_connect/jwks.json")
|
||||
.with(headers: {:Accept => "*/*", :"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
||||
:Host => "kentshikama.com", :"User-Agent" => "Ruby"})
|
||||
.with(headers: {Accept: "*/*", :"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
||||
:"User-Agent" => "Faraday v0.9.1"})
|
||||
.to_return(status: 200,
|
||||
body: "{\"keys\":[{\"kty\":\"RSA\",\"e\":\"AQAB\",\"n\":\"qpW\",\"use\":\"sig\"}]}", headers: {})
|
||||
post :create, redirect_uris: ["http://localhost"], client_name: "diaspora client",
|
||||
|
|
|
|||
Loading…
Reference in a new issue