Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Updated to support omniauth-2.0. #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
require: rubocop-rspec

AllCops:
NewCops: enable

Gemspec/RequiredRubyVersion:
Enabled: false

Layout/AccessModifierIndentation:
EnforcedStyle: outdent

Layout/LineLength:
AllowURI: true
Enabled: false

Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space

Lint/MissingSuper:
Enabled: false

Metrics/AbcSize:
Max: 18

Metrics/BlockNesting:
Max: 2

Metrics/ClassLength:
Max: 110

Metrics/MethodLength:
CountComments: false
Max: 10

Metrics/ParameterLists:
Max: 4
CountKeywordArgs: true

Naming/FileName:
Exclude:
- lib/omniauth-oauth2.rb

Style/CollectionMethods:
PreferredMethods:
map: 'collect'
reduce: 'inject'
find: 'detect'
find_all: 'select'

Style/Documentation:
Enabled: false

Style/DoubleNegation:
Enabled: false

Style/ExpandPathArguments:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

Style/HashSyntax:
EnforcedStyle: hash_rockets

Style/StderrPuts:
Enabled: false

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma

RSpec/SubjectStub:
Enabled: false

RSpec/FilePath:
Enabled: false
15 changes: 10 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in omniauth-asana.gemspec
gemspec

group :development, :test do
gem 'rspec'
gem 'rack-test'
gem 'webmock'
gem 'simplecov'
gem "rack-test"
gem "rspec"
gem "simplecov"
gem "webmock"
end

group :test do
gem "rubocop", ">= 1.0"
gem "rubocop-rspec"
end
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "bundler/gem_tasks"
require 'rspec/core/rake_task'
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new

desc 'Run specs'
desc "Run specs"
task :default => :spec
6 changes: 5 additions & 1 deletion lib/omniauth-asana.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# rubocop:disable Naming/FileName

require "omniauth-asana/version"
require 'omniauth/strategies/asana'
require "omniauth/strategies/asana"

# rubocop:enable Naming/FileName
2 changes: 1 addition & 1 deletion lib/omniauth-asana/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Omniauth
module Asana
VERSION = "0.0.2"
VERSION = "0.0.2".freeze
end
end
26 changes: 10 additions & 16 deletions lib/omniauth/strategies/asana.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
require 'omniauth-oauth2'
require "omniauth-oauth2"

module OmniAuth
module Strategies
class Asana < OmniAuth::Strategies::OAuth2
option :client_options, {
:site => 'https://app.asana.com',
:authorize_url => 'https://app.asana.com/-/oauth_authorize',
:token_url => 'https://app.asana.com/-/oauth_token'
:site => "https://app.asana.com",
:authorize_url => "https://app.asana.com/-/oauth_authorize",
:token_url => "https://app.asana.com/-/oauth_token",
}

def request_phase
super
end

def authorize_params
super.tap do |params|
if request.params['client_options']
params[:client_options] = request.params['client_options']
end
params[:client_options] = request.params["client_options"] if request.params["client_options"]
end
end

uid { raw_info['id'].to_s }
uid { raw_info["id"].to_s }

info do
{
'name' => raw_info['name'],
'email' => raw_info['email']
"name" => raw_info["name"],
"email" => raw_info["email"],
}
end

extra do
{ :raw_info => raw_info }
{:raw_info => raw_info}
end

def raw_info
@raw_info ||= access_token.params['data']
@raw_info ||= access_token.params["data"]
end

def callback_url
Expand Down
22 changes: 13 additions & 9 deletions omniauth-asana.gemspec
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
require "English"

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'omniauth-asana/version'
require "omniauth-asana/version"

Gem::Specification.new do |gem|
gem.name = "omniauth-asana"
gem.version = Omniauth::Asana::VERSION
gem.authors = ["Isaac Wolkerstorfer"]
gem.email = ["[email protected]"]
gem.description = %q{Official OmniAuth strategy for Asana.}
gem.summary = %q{Official OmniAuth strategy for Asana. Based on the OmniAuth strategy for GitHub.}
gem.description = "Official OmniAuth strategy for Asana."
gem.summary = "Official OmniAuth strategy for Asana. Based on the OmniAuth strategy for GitHub."
gem.homepage = "https://github.com/asana/omniauth-asana"

gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]

gem.add_dependency 'omniauth', '~> 1.0'
gem.add_dependency 'omniauth-oauth2', '~> 1.1'
gem.add_dependency "omniauth", "~> 2.0"
gem.add_dependency "omniauth-oauth2", "~> 1.1"
gem.metadata = {
"rubygems_mfa_required" => "true",
}
end
48 changes: 26 additions & 22 deletions spec/omniauth/strategies/asana_spec.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
require 'spec_helper'
# rubocop:disable Metrics/BlockLength
require "spec_helper"

describe OmniAuth::Strategies::Asana do
let(:access_token) { stub('AccessToken', :options => {}) }
let(:parsed_response) { stub('ParsedResponse') }
let(:response) { stub('Response', :parsed => parsed_response) }
subject(:strategy) { described_class.new({}) }

subject do
OmniAuth::Strategies::Asana.new({})
end
let(:access_token) { instance_double("AccessToken", :options => {}) }
let(:params) { instance_double("RackParams") }
let(:hash) { instance_double("Hash") }

before(:each) do
subject.stub!(:access_token).and_return(access_token)
before do
allow(strategy).to receive(:access_token).and_return(access_token)
end

context "client options" do
it 'should have correct site' do
subject.options.client_options.site.should eq("https://app.asana.com")
end
describe "#options" do
describe "#client_options" do
it "has correct site" do
expect(strategy.options.client_options.site).to eq("https://app.asana.com")
end

it 'should have correct authorize url' do
subject.options.client_options.authorize_url.should eq('https://app.asana.com/-/oauth_authorize')
end
it "has correct authorize url" do
expect(strategy.options.client_options.authorize_url).to eq("https://app.asana.com/-/oauth_authorize")
end

it 'should have correct token url' do
subject.options.client_options.token_url.should eq('https://app.asana.com/-/oauth_token')
it "has correct token url" do
expect(strategy.options.client_options.token_url).to eq("https://app.asana.com/-/oauth_token")
end
end
end

context "#raw_info" do
it "should use relative paths" do
access_token.should_receive(:get).with('user').and_return(response)
subject.raw_info.should eq(parsed_response)
describe "#raw_info" do
it "uses params" do
allow(access_token).to receive(:params).and_return(params)
allow(params).to receive(:[]).with("data").and_return(hash)

expect(strategy.raw_info).to eq(hash)
end
end
end
# rubocop:enable Metrics/BlockLength
16 changes: 8 additions & 8 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
$:.unshift File.expand_path('..', __FILE__)
$:.unshift File.expand_path('../../lib', __FILE__)
require 'simplecov'
$LOAD_PATH.unshift File.expand_path("..", __FILE__)
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require "simplecov"
SimpleCov.start
require 'rspec'
require 'rack/test'
require 'webmock/rspec'
require 'omniauth'
require 'omniauth-asana'
require "rspec"
require "rack/test"
require "webmock/rspec"
require "omniauth"
require "omniauth-asana"

RSpec.configure do |config|
config.include WebMock::API
Expand Down