omniauth-active_passport 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-active_passport.gemspec
4
+ gemspec
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-active_passport (0.0.1)
5
+ omniauth (~> 1.0)
6
+ omniauth-oauth2 (~> 1.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ addressable (2.2.6)
12
+ diff-lcs (1.1.3)
13
+ faraday (0.7.5)
14
+ addressable (~> 2.2.6)
15
+ multipart-post (~> 1.1.3)
16
+ rack (>= 1.1.0, < 2)
17
+ hashie (1.2.0)
18
+ multi_json (1.0.4)
19
+ multipart-post (1.1.4)
20
+ oauth2 (0.5.1)
21
+ faraday (~> 0.7.4)
22
+ multi_json (~> 1.0.3)
23
+ omniauth (1.0.1)
24
+ hashie (~> 1.2)
25
+ rack
26
+ omniauth-oauth2 (1.0.0)
27
+ oauth2 (~> 0.5.0)
28
+ omniauth (~> 1.0)
29
+ rack (1.3.5)
30
+ rspec (2.7.0)
31
+ rspec-core (~> 2.7.0)
32
+ rspec-expectations (~> 2.7.0)
33
+ rspec-mocks (~> 2.7.0)
34
+ rspec-core (2.7.1)
35
+ rspec-expectations (2.7.0)
36
+ diff-lcs (~> 1.1.2)
37
+ rspec-mocks (2.7.0)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ omniauth-active_passport!
44
+ rspec (~> 2.7)
@@ -0,0 +1,70 @@
1
+ # OmniAuth Active Passport
2
+
3
+ This is the official OmniAuth strategy for authenticating to Active Passport. To
4
+ use it, you'll need to sign up for an OAuth2 Application ID and Secret
5
+ on the [Active Passport Applications Page](https://passport.active.com/passport/manage).
6
+
7
+
8
+ ## Usage with Devise
9
+
10
+ Add the following code to devise.rb:
11
+
12
+ config.omniauth :active_passport, 'ACTIVE_PASSPORT_KEY', 'ACTIVE_PASSPORT_SECRET', :strategy_class => OmniAuth::Strategies::ActivePassport
13
+
14
+
15
+ Create a controller under users/omniauth_callbacks_controller.rb and add the following:
16
+
17
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
18
+ def passthru
19
+ render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
20
+ end
21
+
22
+ def active_passport
23
+ # successful logic authentication goes here
24
+ # token will be in request.env['omniauth.auth']
25
+ end
26
+ end
27
+
28
+
29
+ Modify routes.rb to include the following:
30
+
31
+ devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
32
+
33
+ devise_scope :user do
34
+ get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
35
+ end
36
+
37
+
38
+ Make sure your model (e.g. user.rb) is omniauthable:
39
+ devise :omniauthable
40
+
41
+
42
+ Devise will create the following url method for linking to the provider:
43
+
44
+ user_omniauth_authorize_path(:active_passport)
45
+
46
+
47
+ ## Testing
48
+
49
+ You will need to turn on "test mode" for OmniAuth:
50
+
51
+ OmniAuth.config.test_mode = true
52
+
53
+
54
+ Once test mode has been enabled, mock_auth will allow you to set provider authentication hash to return during testing:
55
+
56
+ OmniAuth.config.mock_auth[:active_passport] = {
57
+ :provider => 'active_passport',
58
+ :uid => '1234567890',
59
+ :info => {
60
+ :email => 'test@example.com'
61
+ }
62
+ })
63
+
64
+
65
+ The following two env variables are needed to prevent routing errors during OmniAuth controller tests:
66
+
67
+ before do
68
+ request.env["devise.mapping"] = Devise.mappings[:user]
69
+ request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:active_passport]
70
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc "Run specs"
9
+ RSpec::Core::RakeTask.new
10
+
11
+ desc 'Run specs'
12
+ task :default => :spec
@@ -0,0 +1,20 @@
1
+ # Monkeypatching to work with how Active Passport names the access token on a successful response
2
+
3
+ module OAuth2
4
+ # The OAuth2::Client class
5
+ class Client
6
+ # Initializes an AccessToken by making a request to the token endpoint
7
+ def get_token(params, access_token_opts={})
8
+ opts = {:raise_errors => true, :parse => params.delete(:parse)}
9
+ if options[:token_method] == :post
10
+ opts[:body] = params
11
+ opts[:headers] = {'Content-Type' => 'application/x-www-form-urlencoded'}
12
+ else
13
+ opts[:params] = params
14
+ end
15
+ response = request(options[:token_method], token_url, opts)
16
+ raise Error.new(response) unless response.parsed.is_a?(Hash) && (response.parsed['access_token'] || response.parsed['accessToken'])
17
+ AccessToken.from_hash(self, response.parsed.merge(access_token_opts))
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-active_passport/version"
2
+ require 'omniauth/strategies/active_passport'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module ActivePassport
3
+ VERSION = "0.0.3"
4
+ end
5
+ end
@@ -0,0 +1,42 @@
1
+ require 'omniauth-oauth2'
2
+ require 'oauth2_patch/client'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class ActivePassport < OmniAuth::Strategies::OAuth2
7
+ # Give your strategy a name.
8
+ option :name, "active_passport"
9
+
10
+ # This is where you pass the options you would pass when
11
+ # initializing your consumer from the OAuth gem.
12
+ option :client_options, {
13
+ :site => 'https://passport.active.com',
14
+ :authorize_url => '/oauth2/authorize',
15
+ :token_url => '/oauth2/token'
16
+ }
17
+
18
+ option :token_params, { :parse => :json }
19
+
20
+ uid { access_token.params['activeEnterprisePersonId'] }
21
+
22
+ info do
23
+ {
24
+ :email => access_token.params['userName'],
25
+ :expires_at => access_token.params['expireDateTime']
26
+ }
27
+ end
28
+
29
+ credentials do
30
+ {
31
+ :token => access_token.params['accessToken']
32
+ }
33
+ end
34
+
35
+ extra do
36
+ {
37
+ :access_token => access_token
38
+ }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-active_passport/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "omniauth-active_passport"
6
+ s.version = Omniauth::ActivePassport::VERSION
7
+ s.authors = ["Cesar Camacho"]
8
+ s.email = ["cesar.camacho@activenetwork.com"]
9
+ s.homepage = ""
10
+ s.summary = %q{Official OmniAuth strategy for Active Passport.}
11
+ s.description = %q{Official OmniAuth strategy for Active Passport.}
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+
18
+ s.add_dependency 'omniauth', '~> 1.0'
19
+ s.add_dependency 'omniauth-oauth2', '~> 1.0'
20
+ s.add_development_dependency 'rspec', '~> 2.7'
21
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::ActivePassport do
4
+ def app; lambda{|env| [200, {}, ["Hello."]]} end
5
+ let(:fresh_strategy){ Class.new(OmniAuth::Strategies::ActivePassport) }
6
+
7
+ describe '#client' do
8
+ subject{ fresh_strategy }
9
+
10
+ it 'should be initialized with symbolized client_options' do
11
+ instance = subject.new(app, :client_options => {'authorize_url' => 'https://example.com'})
12
+ instance.client.options[:authorize_url].should == 'https://example.com'
13
+ end
14
+ end
15
+
16
+ describe '#token_params' do
17
+ subject { fresh_strategy }
18
+
19
+ it 'should include parse => json as well as any authorize params passed in the :authorize_params option' do
20
+ instance = subject.new('abc', 'def', :token_params => {:foo => 'bar', :baz => 'zip'})
21
+ instance.token_params.should == {'foo' => 'bar', 'baz' => 'zip', 'parse' => :json}
22
+ end
23
+
24
+ it 'should include parse => json as well as any top-level options that are marked as :authorize_options' do
25
+ instance = subject.new('abc', 'def', :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz')
26
+ instance.token_params.should == {'scope' => 'bar', 'foo' => 'baz', 'parse' => :json}
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-active_passport'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ end
16
+
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-active_passport
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 3
9
+ version: 0.0.3
10
+ platform: ruby
11
+ authors:
12
+ - Cesar Camacho
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-01-23 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: omniauth
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ version: "1.0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: omniauth-oauth2
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 1
42
+ - 0
43
+ version: "1.0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 2
55
+ - 7
56
+ version: "2.7"
57
+ type: :development
58
+ version_requirements: *id003
59
+ description: Official OmniAuth strategy for Active Passport.
60
+ email:
61
+ - cesar.camacho@activenetwork.com
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ extra_rdoc_files: []
67
+
68
+ files:
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - README.md
72
+ - Rakefile
73
+ - lib/oauth2_patch/client.rb
74
+ - lib/omniauth-active_passport.rb
75
+ - lib/omniauth-active_passport/version.rb
76
+ - lib/omniauth/strategies/active_passport.rb
77
+ - omniauth-active_passport.gemspec
78
+ - spec/omniauth/strategies/active_passport_spec.rb
79
+ - spec/spec_helper.rb
80
+ has_rdoc: true
81
+ homepage: ""
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options: []
86
+
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.3.6
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Official OmniAuth strategy for Active Passport.
110
+ test_files:
111
+ - spec/omniauth/strategies/active_passport_spec.rb
112
+ - spec/spec_helper.rb