omniauth-gust 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/..gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "./version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "."
7
+ s.version = .::VERSION
8
+ s.authors = ["Sebastian Rabuini"]
9
+ s.email = ["srabuini@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{TODO: Write a gem summary}
12
+ s.description = %q{TODO: Write a gem description}
13
+
14
+ s.rubyforge_project = "."
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # OmniAuth Gust
2
+
3
+ This gem contains the Gust strategy for OmniAuth.
4
+
5
+ Gust uses the OAuth2 flow, you can read about it here: http://angel.co/api/oauth/faq
6
+
7
+ ## How To Use It
8
+
9
+ So let's say you're using Rails, you need to add the strategy to your `Gemfile`:
10
+
11
+ gem 'omniauth-gust'
12
+
13
+ You can pull them in directly from github e.g.:
14
+
15
+ gem 'omniauth-gust', :git => 'https://github.com/wasabit/omniauth-gust.git'
16
+
17
+ Once these are in, you need to add the following to your `config/initializers/omniauth.rb`:
18
+
19
+ Rails.application.config.middleware.use OmniAuth::Builder do
20
+ provider :gust, "consumer_key", "consumer_secret"
21
+ end
22
+
23
+ You will obviously have to put in your key and secret, which you get when you register your app with Gust (they call them API Key and Secret Key).
24
+
25
+ Now just follow the README at: https://github.com/intridea/omniauth
26
+
27
+ ## License
28
+
29
+ Copyright (c) 2012 by Sebastian Rabuini
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
32
+
33
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
34
+
35
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/lib/..rb ADDED
@@ -0,0 +1,5 @@
1
+ require "./version"
2
+
3
+ module .
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,54 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Gust < OmniAuth::Strategies::OAuth2
6
+ DEFAULT_SCOPE = 'read-write'
7
+
8
+ option :name, "gust"
9
+
10
+ option :client_options, {
11
+ :site => 'https://alpha.gust.com',
12
+ :authorize_url => '/r/oauth/authorize',
13
+ :token_url => '/r/oauth/token'
14
+ }
15
+
16
+ uid {
17
+ raw_info['id']
18
+ }
19
+
20
+ info do
21
+ prune!({
22
+ 'name' => raw_info["user_name"],
23
+ 'email' => raw_info["email"],
24
+ 'company_name' => raw_info['company_name'],
25
+ 'urls' => {
26
+ 'profile' => raw_info['profile_url']
27
+ }
28
+ })
29
+ end
30
+
31
+ extra do
32
+ {
33
+ 'raw_info' => raw_info
34
+ }
35
+ end
36
+
37
+ def raw_info
38
+ return @raw_info if @raw_info
39
+ (access_token.options || {}).merge!({:header_format => 'OAuth %s'})
40
+ @raw_info = access_token.get('/r/oauth/user_details').parsed
41
+ end
42
+
43
+
44
+ private
45
+ def prune!(hash)
46
+ hash.delete_if do |_, value|
47
+ prune!(value) if value.is_a?(Hash)
48
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Gust
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-gust/version"
2
+ require "omniauth/strategies/gust"
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-gust/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-gust"
7
+ s.version = Omniauth::Gust::VERSION
8
+ s.authors = ["Sebastian Rabuini"]
9
+ s.email = ["srabuini@gmail.com"]
10
+ s.homepage = "https://github.com/wasabit/omniauth-gust"
11
+ s.summary = %q{Gust OAuth strategy for OmniAuth}
12
+ s.description = %q{Gust OAuth strategy for OmniAuth}
13
+
14
+ s.rubyforge_project = "omniauth-gust"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'omniauth', '~> 1.0'
22
+ s.add_dependency 'omniauth-oauth2', '~> 1.0'
23
+ s.add_development_dependency 'rspec', '~> 2.7'
24
+ s.add_development_dependency 'rack-test'
25
+ s.add_development_dependency 'simplecov'
26
+ s.add_development_dependency 'webmock'
27
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-gust'
3
+
4
+ # Based on tests from https://github.com/mkdynamic/omniauth-facebook
5
+ describe OmniAuth::Strategies::Gust do
6
+ before :each do
7
+ @request = double('Request')
8
+ @request.stub(:params) { {} }
9
+ @request.stub(:cookies) { {} }
10
+
11
+ @client_id = '123'
12
+ @client_secret = 'aaa'
13
+ end
14
+
15
+ subject do
16
+ args = [@client_id, @client_secret, @options].compact
17
+ OmniAuth::Strategies::Gust.new(nil, *args).tap do |strategy|
18
+ strategy.stub(:request) { @request }
19
+ end
20
+ end
21
+
22
+ it_should_behave_like 'an oauth2 strategy'
23
+
24
+ describe '#client' do
25
+ it 'has correct Gust site' do
26
+ subject.client.site.should eq('https://alpha.gust.com')
27
+ end
28
+
29
+ it 'has correct authorize url' do
30
+ subject.client.options[:authorize_url].should eq('/r/oauth/authorize')
31
+ end
32
+
33
+ it 'has correct token url' do
34
+ subject.client.options[:token_url].should eq('/r/oauth/token')
35
+ end
36
+ end
37
+
38
+ describe '#uid' do
39
+ before :each do
40
+ subject.stub(:raw_info) { { 'id' => '123' } }
41
+ end
42
+
43
+ it 'returns the id from raw_info' do
44
+ subject.uid.should eq('123')
45
+ end
46
+ end
47
+
48
+ describe '#info' do
49
+ before :each do
50
+ @raw_info ||= { 'user_name' => 'sebas' }
51
+ subject.stub(:raw_info) { @raw_info }
52
+ end
53
+
54
+ context 'when data is present in raw info' do
55
+
56
+ it 'returns the username as name' do
57
+ @raw_info['username'] = 'sebas'
58
+ subject.info['name'].should eq('sebas')
59
+ end
60
+
61
+ it 'returns email as email' do
62
+ @raw_info['email'] = 'sebas@foob.ar'
63
+ subject.info['email'].should eq('sebas@foob.ar')
64
+ end
65
+
66
+ it 'returns company_name as company_name' do
67
+ @raw_info['company_name'] = 'wasabit'
68
+ subject.info['company_name'].should eq('wasabit')
69
+ end
70
+
71
+ it 'returns the Gust profile page link as the Gust url' do
72
+ @raw_info['profile_url'] = 'https://alpha.gust.com/c/wasabit'
73
+ subject.info['urls'].should be_a(Hash)
74
+ subject.info['urls']['profile'].should eq('https://alpha.gust.com/c/wasabit')
75
+ end
76
+
77
+ end
78
+ end
79
+
80
+ describe '#raw_info' do
81
+ before :each do
82
+ @access_token = double('OAuth2::AccessToken')
83
+ subject.stub(:access_token) { @access_token }
84
+ end
85
+
86
+ it 'performs a GET to https://alpha.gust.com/r/oauth/user_details' do
87
+ @access_token.stub(:get) { double('OAuth2::Response').as_null_object }
88
+ @access_token.should_receive('options')
89
+ @access_token.should_receive(:get).with('/r/oauth/user_details')
90
+ subject.raw_info
91
+ end
92
+
93
+ it 'returns a Hash' do
94
+ @access_token.should_receive(:options)
95
+ @access_token.stub(:get).with('/r/oauth/user_details') do
96
+ raw_response = double('Faraday::Response')
97
+ raw_response.stub(:body) { '{ "foo": "bar" }' }
98
+ raw_response.stub(:status) { 200 }
99
+ raw_response.stub(:headers) { { 'Content-Type' => 'application/json' } }
100
+ OAuth2::Response.new(raw_response)
101
+ end
102
+ subject.raw_info.should be_a(Hash)
103
+ subject.raw_info['foo'].should eq('bar')
104
+ end
105
+ end
106
+
107
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
4
+
5
+ RSpec.configure do |config|
6
+ end
@@ -0,0 +1,37 @@
1
+ # NOTE it would be useful if this lived in omniauth-oauth2 eventually
2
+ shared_examples 'an oauth2 strategy' do
3
+ describe '#client' do
4
+ it 'should be initialized with symbolized client_options' do
5
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
6
+ subject.client.options[:authorize_url].should == 'https://example.com'
7
+ end
8
+ end
9
+
10
+ describe '#authorize_params' do
11
+ it 'should include any authorize params passed in the :authorize_params option' do
12
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
13
+ subject.authorize_params['foo'].should eq('bar')
14
+ subject.authorize_params['baz'].should eq('zip')
15
+ end
16
+
17
+ it 'should include top-level options that are marked as :authorize_options' do
18
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
19
+ subject.authorize_params['scope'].should eq('bar')
20
+ subject.authorize_params['foo'].should eq('baz')
21
+ end
22
+ end
23
+
24
+ describe '#token_params' do
25
+ it 'should include any authorize params passed in the :authorize_params option' do
26
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
27
+ subject.token_params['foo'].should eq('bar')
28
+ subject.token_params['baz'].should eq('zip')
29
+ end
30
+
31
+ it 'should include top-level options that are marked as :authorize_options' do
32
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
33
+ subject.token_params['scope'].should eq('bar')
34
+ subject.token_params['foo'].should eq('baz')
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-gust
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sebastian Rabuini
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: omniauth-oauth2
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.7'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rack-test
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: webmock
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Gust OAuth strategy for OmniAuth
111
+ email:
112
+ - srabuini@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - ..gemspec
118
+ - .gitignore
119
+ - README.md
120
+ - Rakefile
121
+ - lib/..rb
122
+ - lib/omniauth-gust.rb
123
+ - lib/omniauth-gust/version.rb
124
+ - lib/omniauth/strategies/gust.rb
125
+ - omniauth-gust.gemspec
126
+ - spec/omniauth/strategies/gust_spec.rb
127
+ - spec/spec_helper.rb
128
+ - spec/support/shared_examples.rb
129
+ homepage: https://github.com/wasabit/omniauth-gust
130
+ licenses: []
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project: omniauth-gust
149
+ rubygems_version: 1.8.23
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: Gust OAuth strategy for OmniAuth
153
+ test_files:
154
+ - spec/omniauth/strategies/gust_spec.rb
155
+ - spec/spec_helper.rb
156
+ - spec/support/shared_examples.rb