omniauth-familysearch 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .rvmrc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-familysearch-identity.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 'terminal-notifier-guard'
12
+ end
@@ -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-github.gemspec')
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Richard Hill
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,79 @@
1
+ # Omniauth FamilySearch
2
+
3
+ OmniAuth strategy for FamilySearch OAuth2 API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'omniauth-familysearch'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install omniauth-familysearch
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ use OmniAuth::Builder do
23
+ provider :familysearch, ENV['FAMILYSEARCH_DEVELOPER_KEY'], ''
24
+ end
25
+
26
+ # To use the sandbox API
27
+ use Omniauth::Builder do
28
+ provider :familysearch, ENV['FAMILYSEARCH_DEVELOPER_KEY'], '',
29
+ :client_options => { :site => 'https://sandbox.familysearch.org' }
30
+ end
31
+ ```
32
+
33
+ ## Auth Hash
34
+
35
+ Here's an example Auth Hash available in `request.env['omniauth.auth']`:
36
+
37
+ ```ruby
38
+ {
39
+ "provider" => "familysearch",
40
+ "uid" => "MMMM-QY4Y",
41
+ "info" => {
42
+ "name" => "John Doe",
43
+ "email" => "jdoe@example.com"
44
+ },
45
+ "credentials" => {
46
+ "token" => "56421fc9ac",
47
+ "secret" => "6f532ad1bb"
48
+ },
49
+ "extra" => {
50
+ "access_token" => "56421fc9ac",
51
+ "raw_info" => {
52
+ "users" => [
53
+ {
54
+ "id" => "MMMM-QY4Y",
55
+ "contactName" => "John Doe",
56
+ "email" => "jdoe@example.com",
57
+ "links" => {
58
+ "self" => {
59
+ "href" => "https://sandbox.familysearch.org/platform/users/current?access_token=abc123"
60
+ }
61
+ }
62
+ }
63
+ ]
64
+ }
65
+ }
66
+ }
67
+ ```
68
+
69
+ ## FamilySearch OAuth 2 Docs
70
+
71
+ https://familysearch.org/developers/docs/oauth2
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
@@ -0,0 +1,2 @@
1
+ require 'omniauth-familysearch/version'
2
+ require 'omniauth/strategies/familysearch'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module FamilySearch
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,56 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class FamilySearch < OmniAuth::Strategies::OAuth2
6
+ option :client_options, {
7
+ :site => 'https://api.familysearch.org',
8
+ :authorize_url => '/cis-web/oauth2/v3/authorization',
9
+ :token_url => '/cis-web/oauth2/v3/token'
10
+ }
11
+
12
+ def request_phase
13
+ super
14
+ end
15
+
16
+ def authorize_params
17
+ super
18
+ end
19
+
20
+ uid { user_info['id'] }
21
+
22
+ info do
23
+ {
24
+ :name => user_name,
25
+ :email => user_email
26
+ }
27
+ end
28
+
29
+ extra do
30
+ { :raw_info => raw_info }
31
+ end
32
+
33
+ def raw_info
34
+ @raw_info ||= access_token.get('/platform/users/current',
35
+ :headers => { 'Accept' => 'application/x-fs-v1+json' },
36
+ :parse => :json
37
+ ).parsed
38
+ end
39
+
40
+ def user_info
41
+ @user_info ||= raw_info['users'] ? raw_info['users'].first : {}
42
+ end
43
+
44
+ def user_name
45
+ user_info['contactName']
46
+ end
47
+
48
+ def user_email
49
+ user_info['email']
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+
56
+ OmniAuth.config.add_camelization 'familysearch', 'FamilySearch'
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-familysearch/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ['Richard Hill']
6
+ gem.email = ['xrkhill@gmail.com']
7
+ gem.description = %q{OmniAuth strategy for FamilySearch OAuth2 API}
8
+ gem.summary = %q{OmniAuth strategy for FamilySearch OAuth2 API}
9
+ gem.homepage = 'https://github.com/xrkhill/omniauth-familysearch'
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = 'omniauth-familysearch'
15
+ gem.require_paths = ['lib']
16
+ gem.version = OmniAuth::FamilySearch::VERSION
17
+
18
+ gem.add_runtime_dependency('multi_json')
19
+ gem.add_runtime_dependency('omniauth-oauth2', '~> 1.0')
20
+
21
+ gem.add_development_dependency 'rspec', '~> 2.7'
22
+ gem.add_development_dependency 'rack-test'
23
+ gem.add_development_dependency 'simplecov'
24
+ gem.add_development_dependency 'webmock'
25
+ end
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::FamilySearch do
4
+ let(:access_token) { stub('AccessToken', :options => {}) }
5
+ let(:parsed_response) { stub('ParsedResponse') }
6
+ let(:response) { stub('Response', :parsed => parsed_response) }
7
+
8
+ let(:sandbox_site) { 'https://sandbox.familysearch.org' }
9
+ let(:sandbox_authorize_url) { 'https://sandbox.familysearch.org/cis-web/oauth2/v3/authorization' }
10
+ let(:sandbox_token_url) { 'https://sandbox.familysearch.org/cis-web/oauth2/v3/token' }
11
+ let(:sandbox) do
12
+ OmniAuth::Strategies::FamilySearch.new('FAMILYSEARCH_DEVELOPER_KEY', '',
13
+ {
14
+ :client_options => {
15
+ :site => sandbox_site,
16
+ :authorize_url => sandbox_authorize_url,
17
+ :token_url => sandbox_token_url
18
+ }
19
+ }
20
+ )
21
+ end
22
+
23
+ subject do
24
+ OmniAuth::Strategies::FamilySearch.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://api.familysearch.org')
34
+ end
35
+
36
+ it 'should have correct authorize url' do
37
+ subject.options.client_options.authorize_url.should eq('/cis-web/oauth2/v3/authorization')
38
+ end
39
+
40
+ it 'should have correct token url' do
41
+ subject.options.client_options.token_url.should eq('/cis-web/oauth2/v3/token')
42
+ end
43
+
44
+ describe 'should be overrideable' do
45
+ it 'for site' do
46
+ sandbox.options.client_options.site.should eq(sandbox_site)
47
+ end
48
+
49
+ it 'for authorize url' do
50
+ sandbox.options.client_options.authorize_url.should eq(sandbox_authorize_url)
51
+ end
52
+
53
+ it 'for token url' do
54
+ sandbox.options.client_options.token_url.should eq(sandbox_token_url)
55
+ end
56
+ end
57
+ end
58
+
59
+ context 'uid' do
60
+ it 'should return uid from user info if available' do
61
+ subject.stub!(:raw_info).and_return({ 'users' => [{ 'id' => 'MMDZ-85L' }] })
62
+ subject.uid.should eq('MMDZ-85L')
63
+ end
64
+
65
+ it 'should return nil if there is no raw_info' do
66
+ subject.stub!(:raw_info).and_return({})
67
+ subject.uid.should be_nil
68
+ end
69
+ end
70
+
71
+ context 'info' do
72
+ before(:each) do
73
+ subject.stub!(:raw_info).and_return({})
74
+ end
75
+
76
+ it 'should include name key' do
77
+ subject.info.should have_key(:name)
78
+ end
79
+
80
+ it 'should include email key' do
81
+ subject.info.should have_key(:email)
82
+ end
83
+ end
84
+
85
+ context 'extra' do
86
+ it 'should ' do
87
+ subject.stub!(:raw_info).and_return({})
88
+ subject.extra.should have_key(:raw_info)
89
+ end
90
+ end
91
+
92
+ context '#raw_info' do
93
+ it 'should use relative path' do
94
+ path = '/platform/users/current'
95
+ opts = { :headers => { 'Accept' => 'application/x-fs-v1+json' }, :parse => :json }
96
+ access_token.should_receive(:get).with(path, opts).and_return(response)
97
+ subject.raw_info.should eq(parsed_response)
98
+ end
99
+ end
100
+
101
+ context '#user_info' do
102
+ it 'should return first hash from users array' do
103
+ subject.stub!(:raw_info).and_return({ 'users' => [{ 'first' => 'user' }] })
104
+ subject.user_info.should eq({ 'first' => 'user' })
105
+ end
106
+ end
107
+
108
+ context '#user_name' do
109
+ it 'should return email from raw_info if available' do
110
+ subject.stub!(:raw_info).and_return({ 'users' => [{ 'contactName' => 'John Doe' }] })
111
+ subject.user_name.should eq('John Doe')
112
+ end
113
+
114
+ it 'should return nil if there is no raw_info' do
115
+ subject.stub!(:raw_info).and_return({})
116
+ subject.user_name.should be_nil
117
+ end
118
+ end
119
+
120
+ context '#user_email' do
121
+ it 'should return email from raw_info if available' do
122
+ subject.stub!(:raw_info).and_return({ 'users' => [{ 'email' => 'name@example.com' }] })
123
+ subject.user_email.should eq('name@example.com')
124
+ end
125
+
126
+ it 'should return nil if there is no raw_info' do
127
+ subject.stub!(:raw_info).and_return({})
128
+ subject.user_email.should be_nil
129
+ end
130
+ end
131
+
132
+ end
@@ -0,0 +1,15 @@
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-familysearch'
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
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-familysearch
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Richard Hill
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-02-25 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: multi_json
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: omniauth-oauth2
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 15
43
+ segments:
44
+ - 1
45
+ - 0
46
+ version: "1.0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 13
58
+ segments:
59
+ - 2
60
+ - 7
61
+ version: "2.7"
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: rack-test
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
92
+ - !ruby/object:Gem::Dependency
93
+ name: webmock
94
+ prerelease: false
95
+ requirement: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ type: :development
105
+ version_requirements: *id006
106
+ description: OmniAuth strategy for FamilySearch OAuth2 API
107
+ email:
108
+ - xrkhill@gmail.com
109
+ executables: []
110
+
111
+ extensions: []
112
+
113
+ extra_rdoc_files: []
114
+
115
+ files:
116
+ - .gitignore
117
+ - Gemfile
118
+ - Guardfile
119
+ - LICENSE
120
+ - README.md
121
+ - Rakefile
122
+ - lib/omniauth-familysearch.rb
123
+ - lib/omniauth-familysearch/version.rb
124
+ - lib/omniauth/strategies/familysearch.rb
125
+ - omniauth-familysearch.gemspec
126
+ - spec/omniauth/strategies/familysearch_spec.rb
127
+ - spec/spec_helper.rb
128
+ homepage: https://github.com/xrkhill/omniauth-familysearch
129
+ licenses: []
130
+
131
+ post_install_message:
132
+ rdoc_options: []
133
+
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ hash: 3
142
+ segments:
143
+ - 0
144
+ version: "0"
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ hash: 3
151
+ segments:
152
+ - 0
153
+ version: "0"
154
+ requirements: []
155
+
156
+ rubyforge_project:
157
+ rubygems_version: 1.8.24
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: OmniAuth strategy for FamilySearch OAuth2 API
161
+ test_files:
162
+ - spec/omniauth/strategies/familysearch_spec.rb
163
+ - spec/spec_helper.rb