diff --git a/.gitignore b/.gitignore index 8b06bc2..81240ee 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,7 @@ test/version_tmp tmp *.swp example/app.log + +.ruby-gemset + +.ruby-version diff --git a/.rubocop.yml b/.rubocop.yml index 83af90c..49f3b90 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,11 @@ -Style/AlignParameters: +AllCops: + Exclude: + - 'vendor/**/*' + - 'spec/fixtures/**/*' + - 'tmp/**/*' + TargetRubyVersion: 2.2 + +Layout/AlignParameters: # Alignment of parameters in multi-line method calls. # # The `with_first_parameter` style aligns the following lines along the same @@ -32,8 +39,8 @@ Style/BracesAroundHashParameters: - context_dependent # Indentation of `when`. -Style/CaseIndentation: - IndentWhenRelativeTo: end +Layout/CaseIndentation: + EnforcedStyle: end SupportedStyles: - case - end @@ -77,11 +84,10 @@ Style/CommandLiteral: Style/HashSyntax: EnforcedStyle: hash_rockets SupportedStyles: - - ruby19 - hash_rockets # Checks the indentation of the first element in an array literal. -Style/IndentArray: +Layout/IndentArray: # The value `special_inside_parentheses` means that array literals with # brackets that have their opening bracket on the same line as a surrounding # opening round parenthesis, shall have their first element indented relative @@ -103,7 +109,7 @@ Style/IndentArray: IndentationWidth: ~ # Checks the indentation of the first key in a hash literal. -Style/IndentHash: +Layout/IndentHash: # The value `special_inside_parentheses` means that hash literals with braces # that have their opening brace on the same line as a surrounding opening # round parenthesis, shall have their first key indented relative to the @@ -116,7 +122,7 @@ Style/IndentHash: - special_inside_parentheses - consistent -Style/MultilineMethodCallIndentation: +Layout/MultilineMethodCallIndentation: EnforcedStyle: indented SupportedStyles: - aligned @@ -125,7 +131,7 @@ Style/MultilineMethodCallIndentation: # But it can be overridden by setting this parameter IndentationWidth: ~ -Style/MultilineOperationIndentation: +Layout/MultilineOperationIndentation: EnforcedStyle: indented SupportedStyles: - aligned @@ -157,12 +163,22 @@ Metrics/MethodLength: Metrics/LineLength: Max: 120 +Metrics/BlockLength: + CountComments: false + Exclude: + - 'Rakefile' + - '**/*.rake' + - 'spec/**/*.rb' + ##################### Lint ################################ Lint/AssignmentInCondition: Description: "Don't use assignment in conditions." Enabled: false +Lint/ScriptPermission: + Enabled: false + ##################### Performance ######################### # Performance improvement is negligible and the readability is poor. See: diff --git a/Rakefile b/Rakefile index 8811322..503a524 100644 --- a/Rakefile +++ b/Rakefile @@ -15,4 +15,4 @@ rescue LoadError end end -task :default => [:spec, :rubocop] +task :default => %i[spec rubocop] diff --git a/lib/omniauth/strategies/dotloop.rb b/lib/omniauth/strategies/dotloop.rb index 674c8fb..3c42553 100644 --- a/lib/omniauth/strategies/dotloop.rb +++ b/lib/omniauth/strategies/dotloop.rb @@ -19,12 +19,46 @@ class Dotloop < OmniAuth::Strategies::OAuth2 # additional calls (if the user id is returned with the token # or as a URI parameter). This may not be possible with all # providers. - uid {} + uid { raw_info['data']['id'] } # https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema#schema-10-and-later - info {} + info do + prune!( + :email => raw_info['data']['email'], + :first_name => raw_info['data']['first_name'], + :last_name => raw_info['data']['last_name'] + ) + end - extra {} + extra do + hash = {} + hash['raw_info'] = raw_info + prune! hash + end + + def raw_info + @raw_info ||= access_token.get('https://api-gateway.dotloop.com/public/v2/account').parsed || {} + end + + protected + + def build_access_token + options.token_params[:headers] = { 'Authorization' => basic_auth_header } + super + end + + def basic_auth_header + "Basic #{Base64.urlsafe_encode64("#{options[:client_id]}:#{options[:client_secret]}")}" + end + + private + + def prune!(hash) + hash.delete_if do |_, value| + prune!(value) if value.is_a?(Hash) + value.nil? || (value.respond_to?(:empty?) && value.empty?) + end + end end end end diff --git a/omniauth-dotloop.gemspec b/omniauth-dotloop.gemspec index 5892f79..ec84eb8 100644 --- a/omniauth-dotloop.gemspec +++ b/omniauth-dotloop.gemspec @@ -1,18 +1,18 @@ require File.expand_path('../lib/omniauth-dotloop/version', __FILE__) Gem::Specification.new do |gem| - gem.authors = 'Contactually' - gem.email = 'api@contactually.com' - gem.description = 'OmniAuth OAuth2 strategy for Contactually.' + gem.authors = ['Contactually', 'Mwaki Harri Magotswi'] + gem.email = ['api@contactually.com', 'magotswi@gmail.com'] + gem.description = 'OmniAuth OAuth2 strategy for Dotloop.' gem.summary = gem.description - gem.homepage = 'https://github.com/dotloop/omniauth-dotloop' - gem.licenses = %w(MIT) + gem.homepage = 'https://github.com/contactually/omniauth-dotloop' + gem.licenses = %w[MIT] gem.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) } gem.files = `git ls-files`.split("\n") gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") gem.name = 'omniauth-dotloop' - gem.require_paths = %w(lib) + gem.require_paths = %w[lib] gem.version = OmniAuth::Dotloop::VERSION # Lock at 1.3.x due to https://github.com/intridea/omniauth-oauth2/issues/81