Skip to content

Commit

Permalink
chore: Fix rubocop warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
toupeira committed Nov 3, 2016
1 parent 14f0c13 commit 741fff2
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module OpenidConnect
class DiscoveryController < ::Doorkeeper::ApplicationController
include Doorkeeper::Helpers::Controller

WEBFINGER_RELATION = 'http://openid.net/specs/connect/1.0/issuer'
WEBFINGER_RELATION = 'http://openid.net/specs/connect/1.0/issuer'.freeze

def provider
render json: provider_response
Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/openid_connect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Doorkeeper

module OpenidConnect
# TODO: make this configurable
SIGNING_ALGORITHM = 'RS256'
SIGNING_ALGORITHM = 'RS256'.freeze

def self.signing_key
JSON::JWK.new(OpenSSL::PKey.read(configuration.jws_private_key))
Expand Down
26 changes: 11 additions & 15 deletions lib/doorkeeper/openid_connect/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ def option(name, options = {})
Builder.instance_eval do
define_method name do |*args, &block|
# TODO: is builder_class option being used?
value = unless attribute_builder
block ? block : args.first
else
value = if attribute_builder
attribute_builder.new(&block).build
else
block ? block : args.first
end

@config.instance_variable_set(:"@#{attribute}", value)
end
end

define_method attribute do |*args|
define_method attribute do |*_|
if instance_variable_defined?(:"@#{attribute}")
instance_variable_get(:"@#{attribute}")
else
Expand All @@ -106,17 +106,13 @@ def extended(base)
option :jws_public_key
option :issuer

option :resource_owner_from_access_token,
default: (lambda do
logger.warn(I18n.translate('doorkeeper.openid_connect.errors.messages.resource_owner_from_access_token_not_configured'))
nil
end)

option :subject,
default: (lambda do
logger.warn(I18n.translate('doorkeeper.openid_connect.errors.messages.subject_not_configured'))
nil
end)
option :resource_owner_from_access_token, default: lambda { |*_|
fail ConfigurationError, I18n.translate('doorkeeper.openid_connect.errors.messages.resource_owner_from_access_token_not_configured')
}

option :subject, default: lambda { |*_|
fail ConfigurationError, I18n.translate('doorkeeper.openid_connect.errors.messages.subject_not_configured')
}

option :expiration, default: 120

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class AggregatedClaim < Claim
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/doorkeeper/openid_connect/models/claims/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def initialize(options = {})
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class DistributedClaim < Claim
end
end
end
end
end
8 changes: 2 additions & 6 deletions lib/doorkeeper/openid_connect/models/claims/normal_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ def type
:normal
end

def method_missing(method_sym, *arguments, &block)
def to_proc
@value
end

def response_to?(method_sym, *arguments, &block)
method_sym.to_s == @name
end
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/doorkeeper/openid_connect/models/id_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def claims
}
end

def as_json(options = {})
def as_json(*_)
claims.reject { |_, value| value.blank? }
end

Expand Down
6 changes: 3 additions & 3 deletions lib/doorkeeper/openid_connect/models/user_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def claims
base_claims.merge resource_owner_claims
end

def as_json(options = {})
def as_json(*_)
claims
end

Expand All @@ -25,8 +25,8 @@ def base_claims
end

def resource_owner_claims
Doorkeeper::OpenidConnect.configuration.claims.to_h.map do |claim_name, claim_value|
[claim_name, @resource_owner.instance_eval(&claim_value)]
Doorkeeper::OpenidConnect.configuration.claims.to_h.map do |name, claim|
[name, @resource_owner.instance_eval(&claim)]
end.to_h
end

Expand Down
6 changes: 3 additions & 3 deletions lib/doorkeeper/openid_connect/oauth/token_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module TokenResponse

def body
if token.includes_scope? 'openid'
super.
merge({:id_token => id_token.try(:as_jws_token)}).
reject { |_, value| value.blank? }
super
.merge(id_token: id_token.try(:as_jws_token))
.reject { |_, value| value.blank? }
else
super
end
Expand Down
19 changes: 10 additions & 9 deletions lib/doorkeeper/openid_connect/rails/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def self.install!
attr_accessor :routes

def initialize(routes, &block)
@routes, @block = routes, block
@routes = routes
@block = block
end

def generate_routes!(options)
Expand All @@ -36,27 +37,27 @@ def generate_routes!(options)
private

def map_route(name, method)
unless @mapping.skipped?(name)
mapping = @mapping[name]
return if @mapping.skipped?(name)

routes.scope controller: mapping[:controllers], as: mapping[:as] do
send method, mapping
end
mapping = @mapping[name]

routes.scope controller: mapping[:controllers], as: mapping[:as] do
send method
end
end

def userinfo_routes(mapping)
def userinfo_routes
routes.get :show, path: 'userinfo', as: ''
routes.post :show, path: 'userinfo', as: nil
end

def discovery_routes(mapping)
def discovery_routes
routes.scope path: 'discovery' do
routes.get :keys
end
end

def discovery_well_known_routes(mapping)
def discovery_well_known_routes
routes.scope path: '.well-known' do
routes.get :provider, path: 'openid-configuration'
routes.get :webfinger
Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/openid_connect/rails/routes/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(mapping = Mapping.new)
end

def map(&block)
self.instance_eval(&block) if block
instance_eval(&block) if block
@mapping
end

Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/openid_connect/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Doorkeeper
module OpenidConnect
VERSION = '1.0.3'
VERSION = '1.0.3'.freeze
end
end
20 changes: 12 additions & 8 deletions lib/generators/doorkeeper/openid_connect/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
class Doorkeeper::OpenidConnect::InstallGenerator < ::Rails::Generators::Base
include Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
desc 'Installs Doorkeeper OpenID Connect.'
module Doorkeeper
module OpenidConnect
class InstallGenerator < ::Rails::Generators::Base
include Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
desc 'Installs Doorkeeper OpenID Connect.'

def install
template 'initializer.rb', 'config/initializers/doorkeeper_openid_connect.rb'
copy_file File.expand_path('../../../../../config/locales/en.yml', __FILE__), 'config/locales/doorkeeper_openid_connect.en.yml'
route 'use_doorkeeper_openid_connect'
def install
template 'initializer.rb', 'config/initializers/doorkeeper_openid_connect.rb'
copy_file File.expand_path('../../../../../config/locales/en.yml', __FILE__), 'config/locales/doorkeeper_openid_connect.en.yml'
route 'use_doorkeeper_openid_connect'
end
end
end
end
22 changes: 13 additions & 9 deletions lib/generators/doorkeeper/openid_connect/migration_generator.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
require 'rails/generators/active_record'

class Doorkeeper::OpenidConnect::MigrationGenerator < ::Rails::Generators::Base
include Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
desc 'Installs Doorkeeper OpenID Connect migration file.'
module Doorkeeper
module OpenidConnect
class MigrationGenerator < ::Rails::Generators::Base
include Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
desc 'Installs Doorkeeper OpenID Connect migration file.'

def install
migration_template 'migration.rb', 'db/migrate/create_doorkeeper_openid_connect_tables.rb'
end
def install
migration_template 'migration.rb', 'db/migrate/create_doorkeeper_openid_connect_tables.rb'
end

def self.next_migration_number(dirname)
ActiveRecord::Generators::Base.next_migration_number(dirname)
def self.next_migration_number(dirname)
ActiveRecord::Generators::Base.next_migration_number(dirname)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Doorkeeper::OpenidConnect.configure do

issuer 'issuer string'

jws_private_key <<-EOL
Expand Down Expand Up @@ -38,4 +37,3 @@
# end
# end
end

9 changes: 8 additions & 1 deletion spec/controllers/discovery_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@
'kty' => 'RSA',
'kid' => 'IqYwZo2cE6hsyhs48cU8QHH4GanKIx0S4Dc99kgTIMA',
'e' => 'AQAB',
'n' => 'sjdnSA6UWUQQHf6BLIkIEUhMRNBJC1NN_pFt1EJmEiI88GS0ceROO5B5Ooo9Y3QOWJ_n-u1uwTHBz0HCTN4wgArWd1TcqB5GQzQRP4eYnWyPfi4CfeqAHzQp-v4VwbcK0LW4FqtW5D0dtrFtI281FDxLhARzkhU2y7fuYhL8fVw5rUhE8uwvHRZ5CEZyxf7BSHxIvOZAAymhuzNLATt2DGkDInU1BmF75tEtBJAVLzWG_j4LPZh1EpSdfezqaXQlcy9PJi916UzTl0P7Yy-ulOdUsMlB6yo8qKTY1-AbZ5jzneHbGDU_O8QjYvii1WDmJ60t0jXicmOkGrOhruOptw',
'n' => (
'sjdnSA6UWUQQHf6BLIkIEUhMRNBJC1NN_pFt1EJmEiI88GS0ceROO5B5O' \
'oo9Y3QOWJ_n-u1uwTHBz0HCTN4wgArWd1TcqB5GQzQRP4eYnWyPfi4Cfe' \
'qAHzQp-v4VwbcK0LW4FqtW5D0dtrFtI281FDxLhARzkhU2y7fuYhL8fVw' \
'5rUhE8uwvHRZ5CEZyxf7BSHxIvOZAAymhuzNLATt2DGkDInU1BmF75tEt' \
'BJAVLzWG_j4LPZh1EpSdfezqaXQlcy9PJi916UzTl0P7Yy-ulOdUsMlB6' \
'yo8qKTY1-AbZ5jzneHbGDU_O8QjYvii1WDmJ60t0jXicmOkGrOhruOptw'
),
'use' => 'sig',
'alg' => 'RS256',
}
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
# triggering implicit auto-inclusion in groups with matching metadata.
config.shared_context_metadata_behavior = :apply_to_host_groups

# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# This allows you to limit a spec run to individual examples or groups
# you care about by tagging them with `:focus` metadata. When nothing
# is tagged with `:focus`, all examples get run. RSpec also provides
Expand Down

0 comments on commit 741fff2

Please sign in to comment.