omniauth-artsy 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: 23e2d18d331fd6f514ab1d46d66ed5f8fed99284
4
+ data.tar.gz: 748de85ed89240318a648738cd05c58fb7daf86f
5
+ SHA512:
6
+ metadata.gz: e89dd42f92a7648dd67236dbd5b46f8aad0cfdd6559c5d3d73e9fd95373345966e6423d762e5e8ce6bb7bd839d7d33fca7e3f63146ba11e2b9bd4311a9bc829e
7
+ data.tar.gz: 852b0c7dd36e633e0f7267671c5fdeb61554d0c1ef39751471f7e09445e901640931bd11377c1fb67ef81cbae06f9cb7b2fb5d0cfadb9f39800f7866e942473e
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ .bundle
3
+
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,25 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-08-25 15:35:38 -0400 using RuboCop version 0.25.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 8
9
+ # Configuration parameters: AllowURI.
10
+ Metrics/LineLength:
11
+ Max: 154
12
+
13
+ # Offense count: 2
14
+ Style/Documentation:
15
+ Enabled: false
16
+
17
+ # Offense count: 7
18
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
19
+ Style/Encoding:
20
+ Enabled: false
21
+
22
+ # Offense count: 1
23
+ # Configuration parameters: Exclude.
24
+ Style/FileName:
25
+ Enabled: false
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ cache: bundler
4
+
5
+ rvm:
6
+ - 2.1.2
7
+ - 2.0.0
8
+ - 1.9.3
9
+ - rbx-2.2.10
10
+ - jruby-19mode
11
+ - ruby-head
12
+ - jruby-head
13
+
14
+ matrix:
15
+ allow_failures:
16
+ - rvm: ruby-head
17
+ - rvm: jruby-head
@@ -0,0 +1,4 @@
1
+ 0.1.0 (8/25/2014)
2
+ =================
3
+
4
+ * Initial public release - [@dylanfareed](https://github.com/dylanfareed), [@dblock](https://github.com/dblock).
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Artsy, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # omniauth-artsy
2
+
3
+ [![Build Status](https://travis-ci.org/artsy/omniauth-artsy.svg)](https://travis-ci.org/artsy/omniauth-artsy)
4
+
5
+ Artsy OAuth2 Strategy for OmniAuth.
6
+
7
+ ### Installation
8
+
9
+ Add to your Gemfile:
10
+
11
+ ``` ruby
12
+ gem 'omniauth-artsy'
13
+ ```
14
+
15
+ Then run `bundle install`.
16
+
17
+ ### Usage
18
+
19
+ OmniAuth::Strategies::Artsy is simply a Rack middleware. Read the [OmniAuth docs](https://github.com/intridea/omniauth) for detailed instructions.
20
+
21
+ Add the middleware to a Rails app in `config/initializers/omniauth.rb`:
22
+
23
+ ``` ruby
24
+ Rails.application.config.middleware.use OmniAuth::Builder do
25
+ provider :artsy, ENV['ARTSY_CLIENT_ID'], ENV['ARTSY_CLIENT_SECRET']
26
+ end
27
+ ```
28
+
29
+ #### Configuration
30
+
31
+ Set `ENV['ARTSY_API_URL']` to the location of the Artsy API, typically *https://api.artsy.net* in production. Defaults to *http://localhost:3000*.
32
+
33
+ ### License
34
+
35
+ MIT License, see [LICENSE](LICENSE) for details.
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ require 'rubocop/rake_task'
10
+ RuboCop::RakeTask.new(:rubocop)
11
+
12
+ task default: [:rubocop, :spec]
@@ -0,0 +1,2 @@
1
+ require 'omniauth-artsy/version'
2
+ require 'omniauth/strategies/artsy'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Artsy
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Artsy < OmniAuth::Strategies::OAuth2
6
+ option :client_options,
7
+ site: ENV['ARTSY_API_URL'] || ENV['gravity_url'] || 'http://localhost:3000',
8
+ authorize_url: '/oauth2/authorize?scope=offline_access&response_type=code',
9
+ token_url: '/oauth2/access_token?scope=offline_access&response_type=code&grant_type=authorization_code'
10
+
11
+ def request_phase
12
+ super
13
+ end
14
+
15
+ uid do
16
+ raw_info['id']
17
+ end
18
+
19
+ info do
20
+ { raw_info: raw_info }
21
+ end
22
+
23
+ def raw_info
24
+ # TODO: we should send the access_token with the headers,
25
+ # but it looks like the AccessToken's get request isn't sending it over
26
+ # as specified in the oauth gem's documentation.
27
+ # @raw_info ||= access_token.get('/api/v1/me',{ "X-ACCESS-TOKEN" => access_token.token }).parsed
28
+ @raw_info ||= access_token.get('/api/v1/me?access_token=' + access_token.token).parsed
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth-artsy/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-artsy'
7
+ s.version = Omniauth::Artsy::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Dylan Fareed']
10
+ s.email = ['dylan@artsy.net']
11
+ s.homepage = 'https://github.com/artsy/omniauth-artsy'
12
+ s.summary = 'Omniauth plugin for Artsy authentication. '
13
+ s.description = 'Omniauth plugin for Artsy authentication. '
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- spec/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
+ s.require_paths = ['lib']
18
+ s.license = 'MIT'
19
+
20
+ s.add_runtime_dependency 'omniauth-oauth2', '>= 1.0.2'
21
+ s.add_development_dependency 'rake'
22
+ s.add_development_dependency 'rspec'
23
+ s.add_development_dependency 'webmock'
24
+ s.add_development_dependency 'rubocop', '0.25.0'
25
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Artsy do
4
+ before :each do
5
+ @request = double('Request')
6
+ allow(@request).to receive(:params) { {} }
7
+
8
+ @client_id = '912831askljfd2'
9
+ @client_secret = 'dfallksdfoads'
10
+ @domain = 'artsy.net'
11
+ @uid = 'asdfasdfadsfcdad'
12
+ @name = 'Bobert Smithson'
13
+ @email = 'email@spiraljeezey.com'
14
+ end
15
+
16
+ subject do
17
+ OmniAuth::Strategies::Artsy.new(nil, @options || {}).tap do |strategy|
18
+ allow(strategy).to receive(:request) { @request }
19
+ end
20
+ end
21
+
22
+ describe '#client_options' do
23
+ it 'has correct Artsy API URL' do
24
+ expect(subject.options.client_options.site).to eq('http://localhost:3000')
25
+ end
26
+
27
+ it 'has correct authorize url' do
28
+ expect(subject.options.client_options.authorize_url).to eq('/oauth2/authorize?scope=offline_access&response_type=code')
29
+ end
30
+
31
+ it 'has correct token_url url' do
32
+ expect(subject.options.client_options.token_url).to eq('/oauth2/access_token?scope=offline_access&response_type=code&grant_type=authorization_code')
33
+ end
34
+ end
35
+
36
+ describe 'with raw_info' do
37
+ before :each do
38
+ @raw_info_hash = { 'id' => @uid, 'name' => @name, 'email' => @email }
39
+ allow(subject).to receive(:raw_info) { @raw_info_hash }
40
+ end
41
+
42
+ describe '#uid' do
43
+ it 'returns the uid from raw_info' do
44
+ expect(subject.uid).to eq(@uid)
45
+ end
46
+ end
47
+
48
+ describe '#info' do
49
+ context 'when data is present in raw info' do
50
+ it 'returns the name' do
51
+ expect(subject.info[:raw_info]['name']).to eq(@name)
52
+ end
53
+ it 'returns the email' do
54
+ expect(subject.info[:raw_info]['email']).to eq(@email)
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '#info' do
60
+ context 'when data is present in raw info' do
61
+ it 'returns the name' do
62
+ expect(subject.info[:raw_info]['name']).to eq(@name)
63
+ end
64
+ it 'returns the email' do
65
+ expect(subject.info[:raw_info]['email']).to eq(@email)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'omniauth-artsy'
5
+ require 'rspec'
6
+ require 'webmock/rspec'
7
+
8
+ RSpec.configure do |config|
9
+ config.raise_errors_for_deprecations!
10
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-artsy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dylan Fareed
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.2
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.25.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.25.0
83
+ description: 'Omniauth plugin for Artsy authentication. '
84
+ email:
85
+ - dylan@artsy.net
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .rubocop.yml
93
+ - .rubocop_todo.yml
94
+ - .travis.yml
95
+ - CHANGELOG.md
96
+ - Gemfile
97
+ - LICENSE
98
+ - README.md
99
+ - Rakefile
100
+ - lib/omniauth-artsy.rb
101
+ - lib/omniauth-artsy/version.rb
102
+ - lib/omniauth/strategies/artsy.rb
103
+ - omniauth-artsy.gemspec
104
+ - spec/omniauth/strategies/artsy_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/artsy/omniauth-artsy
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.1.11
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Omniauth plugin for Artsy authentication.
130
+ test_files:
131
+ - spec/omniauth/strategies/artsy_spec.rb
132
+ - spec/spec_helper.rb