omniauth-positionly 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a02a94cf15ec1636e7297f5daf1b2f9f5f4c059
4
+ data.tar.gz: 6efb178cff0c850f36b8763628690cb2d0e931bd
5
+ SHA512:
6
+ metadata.gz: 0ea8108cc528dc96ad7d3736f24ef6e428c35b633b6b871c06c5a8598f115c3f39fb57ff8f7f5be4bb91d5d818860cf76fbebd68be315a2a3bbcf011e1db1f6d
7
+ data.tar.gz: d8d4d71748619b9d9cc84f4c8769cab307d7e65a966f9af308e258364a1109fcb3de7b4a29634a806dd5b4ac770ea87a397b691d78c34a798890c4bb832d9e9c
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-positionly (0.1.0)
5
+ omniauth-oauth2 (~> 1.1)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.3)
11
+ faraday (0.8.7)
12
+ multipart-post (~> 1.1)
13
+ hashie (2.0.4)
14
+ httpauth (0.2.0)
15
+ jwt (0.1.8)
16
+ multi_json (>= 1.5)
17
+ multi_json (1.7.6)
18
+ multipart-post (1.2.0)
19
+ oauth2 (0.8.1)
20
+ faraday (~> 0.8)
21
+ httpauth (~> 0.1)
22
+ jwt (~> 0.1.4)
23
+ multi_json (~> 1.0)
24
+ rack (~> 1.2)
25
+ omniauth (1.1.4)
26
+ hashie (>= 1.2, < 3)
27
+ rack
28
+ omniauth-oauth2 (1.1.1)
29
+ oauth2 (~> 0.8.0)
30
+ omniauth (~> 1.0)
31
+ rack (1.5.2)
32
+ rake (10.0.3)
33
+ rspec (2.12.0)
34
+ rspec-core (~> 2.12.0)
35
+ rspec-expectations (~> 2.12.0)
36
+ rspec-mocks (~> 2.12.0)
37
+ rspec-core (2.12.2)
38
+ rspec-expectations (2.12.1)
39
+ diff-lcs (~> 1.1.3)
40
+ rspec-mocks (2.12.2)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ omniauth-positionly!
47
+ rake
48
+ rspec
@@ -0,0 +1,16 @@
1
+ # OmniAuth Positionly
2
+
3
+ This gem contains the Positionly strategy for OmniAuth.
4
+
5
+ ## How To Use It
6
+
7
+ Usage is as per any other OmniAuth 1.0 strategy. So let's say you're using Rails, you need to add the strategy to your `Gemfile`:
8
+
9
+ gem 'omniauth-positionly', git: "git@github.com:positionly/omniauth-positionly.git", require: false
10
+
11
+ Once these are in, you need to add the following to your `config/initializers/omniauth.rb`:
12
+
13
+ require "omniauth-positionly"
14
+ Rails.application.config.middleware.use OmniAuth::Strategies::Positionly, "IDENTIFIER", "SECRET"
15
+
16
+ You will obviously have to put in your identifier and secret, which you get when you register new client app with Positionly
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require "omniauth-positionly/version"
2
+ require 'omniauth/strategies/positionly'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Positionly
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,43 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Positionly < OmniAuth::Strategies::OAuth2
6
+ DEFAULT_SCOPE = "read"
7
+
8
+ option :name, 'positionly'
9
+ option :authorize_options, [:scope, :account_domain]
10
+
11
+ option :client_options, {
12
+ :site => 'https://api.positionly.com',
13
+ :authorize_url => '/oauth2/authorize',
14
+ :token_url => '/oauth2/token'
15
+ }
16
+
17
+ def authorize_params
18
+ super.tap do |params|
19
+ %w(scope account_domain).each do |k|
20
+ params[k.to_sym] = request.params[k] unless [nil, ''].include?(request.params[k])
21
+ end
22
+ params[:scope] ||= DEFAULT_SCOPE
23
+ end
24
+ end
25
+
26
+ uid { raw_info['id'] }
27
+
28
+ info do
29
+ raw_info
30
+ end
31
+
32
+ extra do
33
+ hash = {}
34
+ hash[:raw_info] = raw_info unless skip_info?
35
+ hash
36
+ end
37
+
38
+ def raw_info
39
+ @raw_info ||= access_token.get("/v1/addons/user.json").parsed
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-positionly/version"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Piotr Chmolowski"]
7
+ gem.email = ["piotr@positionly.com"]
8
+ gem.description = %q{Omniauth plugin for Positionly API}
9
+ gem.summary = %q{Omniauth plugin for Positionly API}
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {spec}/*`.split("\n")
14
+ gem.name = "omniauth-positionly"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Omniauth::Positionly::VERSION
17
+
18
+ gem.add_development_dependency 'rspec'
19
+ gem.add_development_dependency 'rake'
20
+
21
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
22
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-positionly'
3
+
4
+ describe OmniAuth::Strategies::Positionly do
5
+ def app; lambda{|env| [200, {}, ["Hello."]]} end
6
+
7
+ before :each do
8
+ OmniAuth.config.test_mode = true
9
+ @request = double('Request')
10
+ @request.stub(:params) { {} }
11
+ @request.stub(:cookies) { {} }
12
+ @request.stub(:env) { {} }
13
+ end
14
+
15
+ after do
16
+ OmniAuth.config.test_mode = false
17
+ end
18
+
19
+ subject do
20
+ args = ['appid', 'secret', @options || {}].compact
21
+ OmniAuth::Strategies::Positionly.new(app, *args).tap do |strategy|
22
+ strategy.stub(:request) { @request }
23
+ end
24
+ end
25
+
26
+ it_should_behave_like 'an oauth2 strategy'
27
+
28
+ describe '#client' do
29
+ it 'has correct auth url' do
30
+ subject.client.site.should eq('https://api.positionly.com')
31
+ end
32
+
33
+ it 'has correct auth path' do
34
+ subject.client.options[:authorize_url].should eq('/oauth2/authorize')
35
+ end
36
+
37
+ it 'has correct token url' do
38
+ subject.client.options[:token_url].should eq('/oauth2/token')
39
+ end
40
+ end
41
+
42
+ describe '#callback_path' do
43
+ it 'has the correct callback path' do
44
+ subject.callback_path.should eq('/auth/positionly/callback')
45
+ end
46
+ end
47
+
48
+ describe '#authorize_params' do
49
+ describe 'scope' do
50
+ it 'should set default scope to "read"' do
51
+ @options = { :authorize_options => [:scope]}
52
+ subject.authorize_params['scope'].should eq('read')
53
+ end
54
+
55
+ it 'should dynamically set the scope in the request' do
56
+ @options = {:scope => 'fooscope'}
57
+ subject.stub(:request) { double('Request', {:params => { 'scope' => 'barscope' }, :env => {}}) }
58
+ subject.authorize_params['scope'].should eq('barscope')
59
+ end
60
+ end
61
+ end
62
+
63
+ describe 'raw info' do
64
+ it 'should include raw_info in extras hash by default' do
65
+ subject.stub(:raw_info) { { :foo => 'bar' } }
66
+ subject.extra[:raw_info].should eq({ :foo => 'bar' })
67
+ end
68
+
69
+ it 'should not include raw_info in extras hash when skip_info is specified' do
70
+ @options = { :skip_info => true }
71
+ subject.extra.should_not have_key(:raw_info)
72
+ end
73
+ end
74
+
75
+ end
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+
4
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
5
+
6
+ RSpec.configure do |config|
7
+ end
@@ -0,0 +1,36 @@
1
+ shared_examples 'an oauth2 strategy' do
2
+ describe '#client' do
3
+ it 'should be initialized with symbolized client_options' do
4
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
5
+ subject.client.options[:authorize_url].should == 'https://example.com'
6
+ end
7
+ end
8
+
9
+ describe '#authorize_params' do
10
+ it 'should include any authorize params passed in the :authorize_params option' do
11
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
12
+ subject.authorize_params['foo'].should eq('bar')
13
+ subject.authorize_params['baz'].should eq('zip')
14
+ end
15
+
16
+ it 'should include top-level options that are marked as :authorize_options' do
17
+ @options = { :authorize_options => [:scope, :foo], :scope => 'http://bar', :foo => 'baz' }
18
+ subject.authorize_params['scope'].should eq('http://bar')
19
+ subject.authorize_params['foo'].should eq('baz')
20
+ end
21
+ end
22
+
23
+ describe '#token_params' do
24
+ it 'should include any token params passed in the :token_params option' do
25
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
26
+ subject.token_params['foo'].should eq('bar')
27
+ subject.token_params['baz'].should eq('zip')
28
+ end
29
+
30
+ it 'should include top-level options that are marked as :token_options' do
31
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
32
+ subject.token_params['scope'].should eq('bar')
33
+ subject.token_params['foo'].should eq('baz')
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-positionly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Piotr Chmolowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: omniauth-oauth2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
55
+ description: Omniauth plugin for Positionly API
56
+ email:
57
+ - piotr@positionly.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - README.md
65
+ - Rakefile
66
+ - lib/omniauth-positionly.rb
67
+ - lib/omniauth-positionly/version.rb
68
+ - lib/omniauth/strategies/positionly.rb
69
+ - omniauth-positionly.gemspec
70
+ - spec/omniauth/strategies/positionly_spec.rb
71
+ - spec/spec_helper.rb
72
+ - spec/support/shared_examples.rb
73
+ homepage:
74
+ licenses: []
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Omniauth plugin for Positionly API
96
+ test_files: []