omniauth-familysearch-identity 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-familysearch-identity.gemspec
4
+ gemspec
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.
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # Omniauth FamilySearchIdentity
2
+
3
+ OmniAuth strategy for FamilySearch Identity v2 API (OAuth 1.0a)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'omniauth-familysearch-identity'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install omniauth-familysearch-identity
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ use OmniAuth::Builder do
23
+ provider :familysearch_identity, ENV['FAMILYSEARCH_DEVELOPER_KEY'], ''
24
+ end
25
+ ```
26
+
27
+ ## Auth Hash
28
+
29
+ Here's an example Auth Hash available in `request.env['omniauth.auth']`:
30
+
31
+ ```ruby
32
+ {
33
+ "provider" => "familysearch_identity",
34
+ "uid" => "jdoe",
35
+ "info" => {
36
+ "name" => "John Doe",
37
+ "email" => "jdoe@example.com",
38
+ "nickname" => "jdoe",
39
+ "first_name" => "John",
40
+ "last_name" => "Doe"
41
+ },
42
+ "credentials" => {
43
+ "token" => "56421fc9ac",
44
+ "secret" => "6f532ad1bb"
45
+ },
46
+ "extra" => {
47
+ "access_token" => "56421fc9ac",
48
+ "raw_info" => {
49
+ "users" => [
50
+ "id" => "MMMM-QY4Y",
51
+ "username" => "jdoe",
52
+ "emails" => [
53
+ {
54
+ "type" => "Primary",
55
+ "value" => "noreply@ldschurch.org"
56
+ },
57
+ {
58
+ "type" => "Alternate",
59
+ "value" => nil
60
+ }
61
+ ],
62
+ "names" => [
63
+ {
64
+ "type" => "Display",
65
+ "value" => "John Doe"
66
+ },
67
+ {
68
+ "type" => "Family",
69
+ "value" => "Doe"
70
+ },
71
+ {
72
+ "type" => "Given",
73
+ "value" => "John"
74
+ }
75
+ ],
76
+ "preferences" => [
77
+ {
78
+ "name" => "language",
79
+ "value" => "en"
80
+ }
81
+ ]
82
+ ]
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ ## FamilySearch Identity v2 Docs
89
+
90
+ https://familysearch.org/developers/docs/identity-v2
91
+
92
+ ## Contributing
93
+
94
+ 1. Fork it
95
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
96
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
97
+ 4. Push to the branch (`git push origin my-new-feature`)
98
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
@@ -0,0 +1,2 @@
1
+ require 'omniauth-familysearch-identity/version'
2
+ require 'omniauth/strategies/familysearch_identity'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Familysearch
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,100 @@
1
+ require 'omniauth-oauth'
2
+ require 'oauth/signature/plaintext'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class FamilySearchIdentity < OmniAuth::Strategies::OAuth
7
+
8
+ option :name, 'familysearch_identity'
9
+
10
+ # This is where you pass the options you would pass when
11
+ # initializing your consumer from the OAuth gem.
12
+ option :client_options, {
13
+ :signature_method => 'PLAINTEXT',
14
+ :scheme => :query_string,
15
+ :http_method => :get,
16
+ :site => 'https://sandbox.familysearch.org',
17
+ :request_token_path => '/identity/v2/request_token',
18
+ :access_token_path => '/identity/v2/access_token',
19
+ :authorize_path => '/identity/v2/authorize'
20
+ }
21
+
22
+ def request_phase
23
+ super
24
+ end
25
+
26
+ def authorize_params
27
+ super
28
+ end
29
+
30
+ # These are called after authentication has succeeded. If
31
+ # possible, you should try to set the UID without making
32
+ # additional calls (if the user id is returned with the token
33
+ # or as a URI parameter). This may not be possible with all
34
+ # providers.
35
+ uid { info[:nickname] }
36
+
37
+ info do
38
+ {
39
+ :name => user_name,
40
+ :email => user_email,
41
+ :nickname => user_info['username'],
42
+ :first_name => user_first_name,
43
+ :last_name => user_last_name
44
+ }
45
+ end
46
+
47
+ extra do
48
+ { :raw_info => raw_info }
49
+ end
50
+
51
+ def raw_info
52
+ request = "/identity/v2/user?sessionId=#{access_token.token}&dataFormat=application/json"
53
+ @raw_info ||= MultiJson.decode(access_token.get(request).body)
54
+ rescue ::Errno::ETIMEDOUT
55
+ raise ::Timeout::Error
56
+ end
57
+
58
+ private
59
+
60
+ def user_info
61
+ raw_info['users'].first
62
+ end
63
+
64
+ def user_email
65
+ email = user_info['emails'].find { |email| email['type'] == 'Primary' }
66
+
67
+ unless email.nil?
68
+ email['value']
69
+ end
70
+ end
71
+
72
+ def user_name
73
+ user_names['Display']
74
+ end
75
+
76
+ def user_first_name
77
+ user_names['Given']
78
+ end
79
+
80
+ def user_last_name
81
+ user_names['Family']
82
+ end
83
+
84
+ def user_names
85
+ @user_names ||= begin
86
+ hash = {}
87
+
88
+ user_info['names'].each do |name|
89
+ hash[name['type']] = name['value']
90
+ end
91
+
92
+ hash
93
+ end
94
+ end
95
+
96
+ end
97
+ end
98
+ end
99
+
100
+ OmniAuth.config.add_camelization 'familysearch_identity', 'FamilySearchIdentity'
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-familysearch-identity/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 Identity v2 API (OAuth 1.0a)}
8
+ gem.summary = %q{OmniAuth strategy for FamilySearch Identity v2 API (OAuth 1.0a)}
9
+ gem.homepage = 'https://github.com/xrkhill/omniauth-familysearch-identity'
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-identity'
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-oauth', '~> 1.0')
20
+
21
+ gem.add_development_dependency('rspec', '~> 2.6')
22
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-familysearch-identity
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-01-01 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-oauth
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: 15
58
+ segments:
59
+ - 2
60
+ - 6
61
+ version: "2.6"
62
+ type: :development
63
+ version_requirements: *id003
64
+ description: OmniAuth strategy for FamilySearch Identity v2 API (OAuth 1.0a)
65
+ email:
66
+ - xrkhill@gmail.com
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files: []
72
+
73
+ files:
74
+ - .gitignore
75
+ - Gemfile
76
+ - LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - lib/omniauth-familysearch-identity.rb
80
+ - lib/omniauth-familysearch-identity/version.rb
81
+ - lib/omniauth/strategies/familysearch_identity.rb
82
+ - omniauth-familysearch-identity.gemspec
83
+ homepage: https://github.com/xrkhill/omniauth-familysearch-identity
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options: []
88
+
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ requirements: []
110
+
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.24
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: OmniAuth strategy for FamilySearch Identity v2 API (OAuth 1.0a)
116
+ test_files: []
117
+