omniauth-outrightmental 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ /pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-outrightmental.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'rb-fsevent'
11
+ gem 'growl'
12
+ gem 'rake'
13
+ end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ guard 'bundler' do
8
+ watch('Gemfile')
9
+ watch('omniauth-outrightmental.gemspec')
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2011 Michael Bleigh and Intridea, Inc.
2
+
3
+ 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:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ 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/README.md ADDED
@@ -0,0 +1,32 @@
1
+ [![Build Status](https://travis-ci.org/outrightmental/omniauth-outrightmental.svg)](https://travis-ci.org/outrightmental/omniauth-outrightmental)
2
+
3
+ # OmniAuth: Outright Mental Inc.
4
+
5
+ This is the official OmniAuth strategy for authenticating to Outright Mental Inc. To use it, you'll need to have a partner account- probably because we're building something together. Then just sign in and create an OAuth2 Application ID and Secret
6
+ on the [Applications Page](https://ont.io/#/settings/applications).
7
+
8
+ ## Basic Usage
9
+
10
+ use OmniAuth::Builder do
11
+ provider :outrightmental, ENV['OUTRIGHTMENTAL_KEY'], ENV['OUTRIGHTMENTAL_SECRET']
12
+ end
13
+
14
+ ## Scopes
15
+
16
+ Outright Mental Inc. API lets you set scopes to provide granular access to different types of data:
17
+
18
+ use OmniAuth::Builder do
19
+ provider :outrightmental, ENV['OUTRIGHTMENTAL_KEY'], ENV['OUTRIGHTMENTAL_SECRET'], scope: "identity,account,contact"
20
+ end
21
+
22
+ More info on [Scopes](https://ont.io/apidoc/#scopes).
23
+
24
+ ## License
25
+
26
+ Copyright (c) 2015 Outright Mental Inc.
27
+
28
+ 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:
29
+
30
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
31
+
32
+ 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,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Run specs'
8
+ task :default => :spec
@@ -0,0 +1,76 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class OutrightMental < OmniAuth::Strategies::OAuth2
6
+ option :client_options, {
7
+ :site => 'https://ont.io/api',
8
+ :authorize_url => 'https://ont.io/login/oauth/authorize',
9
+ :token_url => 'https://ont.io/login/oauth/access_token'
10
+ }
11
+
12
+ def request_phase
13
+ super
14
+ end
15
+
16
+ def authorize_params
17
+ super.tap do |params|
18
+ %w[scope client_options].each do |v|
19
+ if request.params[v]
20
+ params[v.to_sym] = request.params[v]
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ uid { raw_info['id'].to_s }
27
+
28
+ info do
29
+ {
30
+ 'nickname' => raw_info['login'],
31
+ 'email' => email,
32
+ 'name' => raw_info['name'],
33
+ 'image' => raw_info['avatar_url'],
34
+ 'urls' => {
35
+ 'OutrightMental' => raw_info['html_url'],
36
+ 'Blog' => raw_info['blog'],
37
+ },
38
+ }
39
+ end
40
+
41
+ extra do
42
+ {:raw_info => raw_info}
43
+ end
44
+
45
+ def raw_info
46
+ access_token.options[:mode] = :query
47
+ @raw_info ||= access_token.get('user').parsed
48
+ end
49
+
50
+ def email
51
+ (email_access_allowed?) ? primary_email : raw_info['email']
52
+ end
53
+
54
+ def primary_email
55
+ primary = emails.find{|i| i['primary'] }
56
+ primary && primary['email'] || emails.first && emails.first['email']
57
+ end
58
+
59
+ # The new /user/emails API - https://ont.io/apidoc/#future-response
60
+ def emails
61
+ return [] unless email_access_allowed?
62
+ access_token.options[:mode] = :query
63
+ @emails ||= access_token.get('user/emails', :headers => { 'Accept' => 'application/vnd.outrightmental.v1' }).parsed
64
+ end
65
+
66
+ def email_access_allowed?
67
+ return false unless options['scope']
68
+ email_scopes = ['user', 'user:email']
69
+ scopes = options['scope'].split(',')
70
+ (scopes & email_scopes).any?
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ OmniAuth.config.add_camelization 'outrightmental', 'OutrightMental'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module OutrightMental
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-outrightmental/version"
2
+ require 'omniauth/strategies/outrightmental'
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-outrightmental/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Outright Mental Inc."]
6
+ gem.email = ["charney@ont.io"]
7
+ gem.description = %q{Official OmniAuth strategy for Outright Mental Inc.}
8
+ gem.summary = %q{Official OmniAuth strategy for Outright Mental Inc.}
9
+ gem.homepage = "https://github.com/outrightmental/omniauth-outrightmental"
10
+ gem.license = "MIT"
11
+
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.name = "omniauth-outrightmental"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = OmniAuth::OutrightMental::VERSION
18
+
19
+ gem.add_dependency 'omniauth', '~> 1.0'
20
+ # Nothing lower than omniauth-oauth2 1.1.1
21
+ # http://www.rubysec.com/advisories/CVE-2012-6134/
22
+ gem.add_dependency 'omniauth-oauth2', '>= 1.1.1', '< 2.0'
23
+ gem.add_development_dependency 'rspec', '~> 2.7'
24
+ gem.add_development_dependency 'rack-test'
25
+ gem.add_development_dependency 'simplecov'
26
+ gem.add_development_dependency 'webmock'
27
+ end
@@ -0,0 +1,142 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::OutrightMental do
4
+ let(:access_token) { double('AccessToken', :options => {}) }
5
+ let(:parsed_response) { double('ParsedResponse') }
6
+ let(:response) { double('Response', :parsed => parsed_response) }
7
+
8
+ let(:enterprise_site) { 'https://some.other.site.com/api/v3' }
9
+ let(:enterprise_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' }
10
+ let(:enterprise_token_url) { 'https://some.other.site.com/login/oauth/access_token' }
11
+ let(:enterprise) do
12
+ OmniAuth::Strategies::OutrightMental.new('OUTRIGHTMENTAL_KEY', 'OUTRIGHTMENTAL_SECRET',
13
+ {
14
+ :client_options => {
15
+ :site => enterprise_site,
16
+ :authorize_url => enterprise_authorize_url,
17
+ :token_url => enterprise_token_url
18
+ }
19
+ }
20
+ )
21
+ end
22
+
23
+ subject do
24
+ OmniAuth::Strategies::OutrightMental.new({})
25
+ end
26
+
27
+ before(:each) do
28
+ subject.stub(:access_token).and_return(access_token)
29
+ end
30
+
31
+ context "client options" do
32
+ it 'should have correct site' do
33
+ subject.options.client_options.site.should eq("https://ont.io/api")
34
+ end
35
+
36
+ it 'should have correct authorize url' do
37
+ subject.options.client_options.authorize_url.should eq('https://ont.io/login/oauth/authorize')
38
+ end
39
+
40
+ it 'should have correct token url' do
41
+ subject.options.client_options.token_url.should eq('https://ont.io/login/oauth/access_token')
42
+ end
43
+
44
+ describe "should be overrideable" do
45
+ it "for site" do
46
+ enterprise.options.client_options.site.should eq(enterprise_site)
47
+ end
48
+
49
+ it "for authorize url" do
50
+ enterprise.options.client_options.authorize_url.should eq(enterprise_authorize_url)
51
+ end
52
+
53
+ it "for token url" do
54
+ enterprise.options.client_options.token_url.should eq(enterprise_token_url)
55
+ end
56
+ end
57
+ end
58
+
59
+ context "#email_access_allowed?" do
60
+ it "should not allow email if scope is nil" do
61
+ subject.options['scope'].should be_nil
62
+ subject.should_not be_email_access_allowed
63
+ end
64
+
65
+ it "should allow email if scope is user" do
66
+ subject.options['scope'] = 'user'
67
+ subject.should be_email_access_allowed
68
+ end
69
+
70
+ it "should allow email if scope is a bunch of stuff including user" do
71
+ subject.options['scope'] = 'public_repo,user,repo,delete_repo,gist'
72
+ subject.should be_email_access_allowed
73
+ end
74
+
75
+ it "should not allow email if scope does not grant email access" do
76
+ subject.options['scope'] = 'repo,user:follow'
77
+ subject.should_not be_email_access_allowed
78
+ end
79
+
80
+ it "should assume email access not allowed if scope is something currently not documented " do
81
+ subject.options['scope'] = 'currently_not_documented'
82
+ subject.should_not be_email_access_allowed
83
+ end
84
+ end
85
+
86
+ context "#email" do
87
+ it "should return email from raw_info if available" do
88
+ subject.stub(:raw_info).and_return({'email' => 'you@example.com'})
89
+ subject.email.should eq('you@example.com')
90
+ end
91
+
92
+ it "should return nil if there is no raw_info and email access is not allowed" do
93
+ subject.stub(:raw_info).and_return({})
94
+ subject.email.should be_nil
95
+ end
96
+
97
+ it "should return the primary email if there is no raw_info and email access is allowed" do
98
+ emails = [
99
+ { 'email' => 'secondary@example.com', 'primary' => false },
100
+ { 'email' => 'primary@example.com', 'primary' => true }
101
+ ]
102
+ subject.stub(:raw_info).and_return({})
103
+ subject.options['scope'] = 'user'
104
+ subject.stub(:emails).and_return(emails)
105
+ subject.email.should eq('primary@example.com')
106
+ end
107
+
108
+ it "should return the first email if there is no raw_info and email access is allowed" do
109
+ emails = [
110
+ { 'email' => 'first@example.com', 'primary' => false },
111
+ { 'email' => 'second@example.com', 'primary' => false }
112
+ ]
113
+ subject.stub(:raw_info).and_return({})
114
+ subject.options['scope'] = 'user'
115
+ subject.stub(:emails).and_return(emails)
116
+ subject.email.should eq('first@example.com')
117
+ end
118
+ end
119
+
120
+ context "#raw_info" do
121
+ it "should use relative paths" do
122
+ access_token.should_receive(:get).with('user').and_return(response)
123
+ subject.raw_info.should eq(parsed_response)
124
+ end
125
+ end
126
+
127
+ context "#emails" do
128
+ it "should use relative paths" do
129
+ access_token.should_receive(:get).with('user/emails', :headers=>{"Accept"=>"application/vnd.outrightmental.v1"}).and_return(response)
130
+ subject.options['scope'] = 'user'
131
+ subject.emails.should eq(parsed_response)
132
+ end
133
+ end
134
+
135
+ context '#info.urls' do
136
+ it 'should use html_url from raw_info' do
137
+ subject.stub(:raw_info).and_return({ 'login' => 'me', 'html_url' => 'http://enterprise/me' })
138
+ subject.info['urls']['OutrightMental'].should == 'http://enterprise/me'
139
+ end
140
+ end
141
+
142
+ 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-outrightmental'
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,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-outrightmental
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Outright Mental Inc.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-05-14 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.1.1
38
+ - - <
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: 1.1.1
49
+ - - <
50
+ - !ruby/object:Gem::Version
51
+ version: '2.0'
52
+ - !ruby/object:Gem::Dependency
53
+ name: rspec
54
+ requirement: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: '2.7'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '2.7'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rack-test
70
+ requirement: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: simplecov
86
+ requirement: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: webmock
102
+ requirement: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ description: Official OmniAuth strategy for Outright Mental Inc.
117
+ email:
118
+ - charney@ont.io
119
+ executables: []
120
+ extensions: []
121
+ extra_rdoc_files: []
122
+ files:
123
+ - .gitignore
124
+ - .rspec
125
+ - Gemfile
126
+ - Guardfile
127
+ - LICENSE.txt
128
+ - README.md
129
+ - Rakefile
130
+ - lib/omniauth-outrightmental.rb
131
+ - lib/omniauth-outrightmental/version.rb
132
+ - lib/omniauth/strategies/outrightmental.rb
133
+ - omniauth-outrightmental.gemspec
134
+ - spec/omniauth/strategies/outrightmental_spec.rb
135
+ - spec/spec_helper.rb
136
+ homepage: https://github.com/outrightmental/omniauth-outrightmental
137
+ licenses:
138
+ - MIT
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 1.8.23
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: Official OmniAuth strategy for Outright Mental Inc.
161
+ test_files: []