Skip to content

Commit

Permalink
Merge 06b5fb0 into 96daaf5
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Petschnig committed Apr 4, 2017
2 parents 96daaf5 + 06b5fb0 commit 150799e
Show file tree
Hide file tree
Showing 30 changed files with 77 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ Style/Lambda:
Style/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space

# Disable for Ruby 1.9.3 compatibility
Style/SymbolArray:
Enabled: false

Style/TrailingCommaInLiteral:
EnforcedStyleForMultiline: 'comma'

Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'faraday', '~> 0.9.2', :platforms => [:jruby_18, :ruby_18]
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler'
Bundler::GemHelper.install_tasks

Expand Down
2 changes: 2 additions & 0 deletions lib/oauth2.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'oauth2/error'
require 'oauth2/authenticator'
require 'oauth2/client'
Expand Down
8 changes: 5 additions & 3 deletions lib/oauth2/access_token.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module OAuth2
class AccessToken
attr_reader :client, :token, :expires_in, :expires_at, :params
Expand All @@ -8,7 +10,7 @@ class << self
#
# @param [Client] the OAuth2::Client instance
# @param [Hash] a hash of AccessToken property values
# @return [AccessToken] the initalized AccessToken
# @return [AccessToken] the initialized AccessToken
def from_hash(client, hash)
hash = hash.dup
new(client, hash.delete('access_token') || hash.delete(:access_token), hash)
Expand All @@ -18,13 +20,13 @@ def from_hash(client, hash)
#
# @param [Client] client the OAuth2::Client instance
# @param [String] kvform the application/x-www-form-urlencoded string
# @return [AccessToken] the initalized AccessToken
# @return [AccessToken] the initialized AccessToken
def from_kvform(client, kvform)
from_hash(client, Rack::Utils.parse_query(kvform))
end
end

# Initalize an AccessToken
# Initialize an AccessToken
#
# @param [Client] client the OAuth2::Client instance
# @param [String] token the Access Token value
Expand Down
2 changes: 2 additions & 0 deletions lib/oauth2/authenticator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'base64'

module OAuth2
Expand Down
4 changes: 3 additions & 1 deletion lib/oauth2/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'faraday'
require 'logger'

Expand Down Expand Up @@ -130,7 +132,7 @@ def request(verb, url, opts = {}) # rubocop:disable CyclomaticComplexity, Method
# @param [Hash] params a Hash of params for the token endpoint
# @param [Hash] access token options, to pass to the AccessToken object
# @param [Class] class of access token for easier subclassing OAuth2::AccessToken
# @return [AccessToken] the initalized AccessToken
# @return [AccessToken] the initialized AccessToken
def get_token(params, access_token_opts = {}, access_token_class = AccessToken) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
params = Authenticator.new(id, secret, options[:auth_scheme]).apply(params)
opts = {:raise_errors => options[:raise_errors], :parse => params.delete(:parse)}
Expand Down
2 changes: 2 additions & 0 deletions lib/oauth2/error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module OAuth2
class Error < StandardError
attr_reader :response, :code, :description
Expand Down
4 changes: 3 additions & 1 deletion lib/oauth2/mac_token.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'base64'
require 'digest'
require 'openssl'
Expand All @@ -17,7 +19,7 @@ def self.from_access_token(token, secret, options = {})

attr_reader :secret, :algorithm

# Initalize a MACToken
# Initialize a MACToken
#
# @param [Client] client the OAuth2::Client instance
# @param [String] token the Access Token value
Expand Down
4 changes: 3 additions & 1 deletion lib/oauth2/response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'multi_json'
require 'multi_xml'
require 'rack'
Expand Down Expand Up @@ -41,7 +43,7 @@ def self.register_parser(key, mime_types, &block)
#
# @param [Faraday::Response] response The Faraday response instance
# @param [Hash] opts options in which to initialize the instance
# @option opts [Symbol] :parse (:automatic) how to parse the response body. one of :query (for x-www-form-urlencoded),
# @option opts [Symbol] :parse (:automatic) how to parse the response body. One of :query (for x-www-form-urlencoded),
# :json, or :automatic (determined by Content-Type response header)
def initialize(response, opts = {})
@response = response
Expand Down
2 changes: 2 additions & 0 deletions lib/oauth2/strategy/assertion.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'jwt'

module OAuth2
Expand Down
2 changes: 2 additions & 0 deletions lib/oauth2/strategy/auth_code.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module OAuth2
module Strategy
# The Authorization Code Strategy
Expand Down
2 changes: 2 additions & 0 deletions lib/oauth2/strategy/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module OAuth2
module Strategy
class Base
Expand Down
2 changes: 2 additions & 0 deletions lib/oauth2/strategy/client_credentials.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module OAuth2
module Strategy
# The Client Credentials Strategy
Expand Down
2 changes: 2 additions & 0 deletions lib/oauth2/strategy/implicit.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module OAuth2
module Strategy
# The Implicit Strategy
Expand Down
2 changes: 2 additions & 0 deletions lib/oauth2/strategy/password.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module OAuth2
module Strategy
# The Resource Owner Password Credentials Authorization Strategy
Expand Down
2 changes: 2 additions & 0 deletions lib/oauth2/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module OAuth2
module Version
module_function
Expand Down
8 changes: 5 additions & 3 deletions oauth2.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# coding: utf-8
# frozen_string_literal: true

lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'oauth2/version'
Expand All @@ -13,11 +15,11 @@ Gem::Specification.new do |spec|
spec.authors = ['Michael Bleigh', 'Erik Michaels-Ober']
spec.description = 'A Ruby wrapper for the OAuth 2.0 protocol built with a similar style to the original OAuth spec.'
spec.email = ['michael@intridea.com', 'sferik@gmail.com']
spec.files = %w(.document CONTRIBUTING.md LICENSE.md README.md oauth2.gemspec) + Dir['lib/**/*.rb']
spec.files = %w[.document CONTRIBUTING.md LICENSE.md README.md oauth2.gemspec] + Dir['lib/**/*.rb']
spec.homepage = 'http://github.com/intridea/oauth2'
spec.licenses = %w(MIT)
spec.licenses = %w[MIT]
spec.name = 'oauth2'
spec.require_paths = %w(lib)
spec.require_paths = %w[lib]
spec.required_rubygems_version = '>= 1.3.5'
spec.summary = 'A Ruby wrapper for the OAuth 2.0 protocol.'
spec.version = OAuth2::Version
Expand Down
2 changes: 2 additions & 0 deletions spec/helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

if RUBY_VERSION >= '1.9'
require 'simplecov'
require 'coveralls'
Expand Down
4 changes: 3 additions & 1 deletion spec/oauth2/access_token_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'helper'

describe AccessToken do
Expand Down Expand Up @@ -51,7 +53,7 @@ def assert_initialized_token(target) # rubocop:disable Metrics/AbcSize
expect(hash).to eq(hash_before)
end

it 'initalizes with a form-urlencoded key/value string' do
it 'initializes with a form-urlencoded key/value string' do
kvform = "access_token=#{token}&expires_at=#{Time.now.to_i + 200}&foo=bar"
target = AccessToken.from_kvform(client, kvform)
assert_initialized_token(target)
Expand Down
2 changes: 2 additions & 0 deletions spec/oauth2/authenticator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'helper'

describe OAuth2::Authenticator do
Expand Down
6 changes: 4 additions & 2 deletions spec/oauth2/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# coding: utf-8
# frozen_string_literal: true

require 'helper'
require 'nkf'

Expand Down Expand Up @@ -93,7 +95,7 @@
end
end

%w(authorize token).each do |url_type|
%w[authorize token].each do |url_type|
describe ":#{url_type}_url option" do
it "defaults to a path of /oauth/#{url_type}" do
expect(subject.send("#{url_type}_url")).to eq("https://api.example.com/oauth/#{url_type}")
Expand Down Expand Up @@ -215,7 +217,7 @@
expect(response.error).not_to be_nil
end

%w(/unauthorized /conflict /error /different_encoding /ascii_8bit_encoding).each do |error_path|
%w[/unauthorized /conflict /error /different_encoding /ascii_8bit_encoding].each do |error_path|
it "raises OAuth2::Error on error response to path #{error_path}" do
expect { subject.request(:get, error_path) }.to raise_error(OAuth2::Error)
end
Expand Down
2 changes: 2 additions & 0 deletions spec/oauth2/mac_token_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'helper'

describe MACToken do
Expand Down
2 changes: 2 additions & 0 deletions spec/oauth2/response_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'helper'

describe OAuth2::Response do
Expand Down
4 changes: 3 additions & 1 deletion spec/oauth2/strategy/assertion_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'helper'

describe OAuth2::Strategy::Assertion do
Expand Down Expand Up @@ -28,7 +30,7 @@
end
end

%w(json formencoded).each do |mode|
%w[json formencoded].each do |mode|
describe "#get_token (#{mode})" do
before do
@mode = mode
Expand Down
3 changes: 2 additions & 1 deletion spec/oauth2/strategy/auth_code_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: utf-8
# frozen_string_literal: true

require 'helper'

Expand Down Expand Up @@ -71,7 +72,7 @@
end
end

%w(json formencoded from_facebook).each do |mode|
%w[json formencoded from_facebook].each do |mode|
[:get, :post].each do |verb|
describe "#get_token (#{mode}, access_token_method=#{verb}" do
before do
Expand Down
2 changes: 2 additions & 0 deletions spec/oauth2/strategy/base_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'helper'

describe OAuth2::Strategy::Base do
Expand Down
4 changes: 3 additions & 1 deletion spec/oauth2/strategy/client_credentials_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'helper'

describe OAuth2::Strategy::ClientCredentials do
Expand Down Expand Up @@ -37,7 +39,7 @@
end
end

%w(json formencoded).each do |mode|
%w[json formencoded].each do |mode|
[:basic_auth, :request_body].each do |auth_scheme|
describe "#get_token (#{mode}) (#{auth_scheme})" do
before do
Expand Down
2 changes: 2 additions & 0 deletions spec/oauth2/strategy/implicit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'helper'

describe OAuth2::Strategy::Implicit do
Expand Down
4 changes: 3 additions & 1 deletion spec/oauth2/strategy/password_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'helper'

describe OAuth2::Strategy::Password do
Expand Down Expand Up @@ -25,7 +27,7 @@
end
end

%w(json formencoded).each do |mode|
%w[json formencoded].each do |mode|
describe "#get_token (#{mode})" do
before do
@mode = mode
Expand Down

0 comments on commit 150799e

Please sign in to comment.