Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nbulaj committed May 8, 2020
1 parent f47f07c commit 034d87e
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/doorkeeper/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Doorkeeper
class Engine < Rails::Engine
initializer "doorkeeper.params.filter" do |app|
parameters = %w[client_secret code authentication_token access_token refresh_token]
app.config.filter_parameters << /^(#{Regexp.union parameters})$/
app.config.filter_parameters << /^(#{Regexp.union(parameters)})$/
end

initializer "doorkeeper.routes" do
Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/oauth/authorization/code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(pre_auth, resource_owner)
@resource_owner = resource_owner
end

def issue_token
def issue_token!
return @token if defined?(@token)

@token = Doorkeeper.config.access_grant_model.create!(access_grant_attributes)
Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/oauth/authorization/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def initialize(pre_auth, resource_owner)
@resource_owner = resource_owner
end

def issue_token
def issue_token!
return @token if defined?(@token)

context = self.class.build_context(
Expand Down
4 changes: 2 additions & 2 deletions lib/doorkeeper/oauth/code_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class CodeRequest
attr_reader :pre_auth, :resource_owner

def initialize(pre_auth, resource_owner)
@pre_auth = pre_auth
@pre_auth = pre_auth
@resource_owner = resource_owner
end

def authorize
auth = Authorization::Code.new(pre_auth, resource_owner)
auth.issue_token
auth.issue_token!
CodeResponse.new(pre_auth, auth)
end

Expand Down
6 changes: 3 additions & 3 deletions lib/doorkeeper/oauth/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def from_bearer_param(request)

def from_bearer_authorization(request)
pattern = /^Bearer /i
header = request.authorization
header = request.authorization
token_from_header(header, pattern) if match?(header, pattern)
end

def from_basic_authorization(request)
pattern = /^Basic /i
header = request.authorization
header = request.authorization
token_from_basic_header(header, pattern) if match?(header, pattern)
end

Expand All @@ -54,7 +54,7 @@ def decode_basic_credentials_token(encoded_header)
end

def token_from_header(header, pattern)
header.gsub pattern, ""
header.gsub(pattern, "")
end

def match?(header, pattern)
Expand Down
6 changes: 1 addition & 5 deletions lib/doorkeeper/oauth/token_introspection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,7 @@ def token_introspection_allowed?(auth_client: nil, auth_token: nil)
allow_introspection = Doorkeeper.config.allow_token_introspection
return allow_introspection unless allow_introspection.respond_to?(:call)

allow_introspection.call(
@token,
auth_client,
auth_token,
)
allow_introspection.call(@token, auth_client, auth_token)
end

# Allows to customize introspection response.
Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/oauth/token_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(pre_auth, resource_owner)

def authorize
auth = Authorization::Token.new(pre_auth, resource_owner)
auth.issue_token
auth.issue_token!
CodeResponse.new(pre_auth, auth, response_on_fragment: true)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Doorkeeper
class Server
attr_reader :context

def initialize(context = nil)
def initialize(context)
@context = context
end

Expand Down
8 changes: 4 additions & 4 deletions lib/doorkeeper/stale_records_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def self.for(base_scope)
raise Doorkeeper::Errors::NoOrmCleaner, "'#{configured_orm}' ORM has no cleaner!"
end

def self.configured_orm
Doorkeeper.config.orm
end

def self.new(base_scope)
self.for(base_scope)
end

def self.configured_orm
Doorkeeper.config.orm
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/oauth/code_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

let :auth do
Doorkeeper::OAuth::Authorization::Token.new(pre_auth, owner).tap do |c|
c.issue_token
c.issue_token!
allow(c.token).to receive(:expires_in_seconds).and_return(3600)
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/lib/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

describe Doorkeeper::Server do
let(:fake_class) { double :fake_class }
let(:context) { double :context }

subject do
described_class.new
described_class.new(context)
end

describe ".authorization_request" do
Expand Down

0 comments on commit 034d87e

Please sign in to comment.