omniauth-yahoo_auth 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +39 -35
- data/lib/omniauth/strategies/yahoo_auth.rb +32 -51
- data/lib/omniauth/yahoo_auth/version.rb +1 -1
- data/omniauth-yahoo_auth.gemspec +1 -1
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 249bf29e9672b7ce7262770c5fc486d0bff7e9a94f27819b40232ab8b9571d76
|
4
|
+
data.tar.gz: d763f58cc37cdfdb003762bfa1a6cf29c69dd3e027928d543d7cdaaf4200c121
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f65f8467d0da2e15d20ee86ef08d7711750dff03a5b4af95598609aa870709f232b12cb08a472f87e6d549a7a1672ac351e10e0d8ab4f60cf9936935dfac2b6f
|
7
|
+
data.tar.gz: 4698b2672eb24bf563d74132d7d29d8cb1b8ea7009ddfcbea58eaef4eed93c9af49b406dc48081912cc3f53ed5a91f746cccd448d6380a72fe7da58e86a57b7d
|
data/README.md
CHANGED
@@ -46,16 +46,16 @@ Option name | Default | Explanation
|
|
46
46
|
--- | --- | ---
|
47
47
|
`name` | `yahoo_auth` | It can be changed to any value, for example `yahoo`. The OmniAuth URL will thus change to /auth/yahoo .
|
48
48
|
`redirect_uri` | `/auth/yahoo/callback` | Specify a custom callback URL used during the server-side flow. Default is `https://www.your_callback_domain/auth/yahoo/callback`
|
49
|
-
`image_size` | `192x192` | Set the size for the returned image in the auth hash. Valid options include sizes: 16x16, 24x24, 32x32, 48x48, 64x64, 96x96, 128x128, 192x192
|
50
49
|
|
51
50
|
For example:
|
52
51
|
|
53
52
|
```ruby
|
54
53
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
55
|
-
provider :yahoo_auth,
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
provider :yahoo_auth,
|
55
|
+
ENV['YAHOO_APP_ID'],
|
56
|
+
ENV['YAHOO_APP_SECRET'],
|
57
|
+
name: "yahoo",
|
58
|
+
redirect_uri: "https://www.your_callback_domain/auth/yahoo/callback"
|
59
59
|
end
|
60
60
|
```
|
61
61
|
|
@@ -79,16 +79,20 @@ Here's an example *Auth Hash* available in `request.env['omniauth.auth']`:
|
|
79
79
|
expires: true # this will always be true.
|
80
80
|
},
|
81
81
|
extra: {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
82
|
+
sub: '',
|
83
|
+
name: '',
|
84
|
+
middle_name: '',
|
85
|
+
nickname: '',
|
86
|
+
gender: 'M',
|
87
|
+
language: 'en-IN',
|
88
|
+
website: '',
|
89
|
+
birth_date: '',
|
90
|
+
zone_info: '',
|
91
|
+
updated_at: '',
|
92
|
+
email_verified: true,
|
93
|
+
address: '',
|
94
|
+
phone_number: '',
|
95
|
+
phone_number_verified: false,
|
92
96
|
}
|
93
97
|
}
|
94
98
|
```
|
@@ -123,16 +127,16 @@ Then make sure your callbacks controller is setup.
|
|
123
127
|
# app/controllers/users/omniauth_callbacks_controller.rb
|
124
128
|
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
125
129
|
def yahoo_auth
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
130
|
+
# You need to implement the method below in your model (e.g. app/models/user.rb)
|
131
|
+
@user = User.from_omniauth(request.env['omniauth.auth'])
|
132
|
+
|
133
|
+
if @user.persisted?
|
134
|
+
flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'Yahoo'
|
135
|
+
sign_in_and_redirect @user, event: :authentication
|
136
|
+
else
|
137
|
+
session['devise.yahoo_data'] = request.env['omniauth.auth']
|
138
|
+
redirect_to new_user_registration_url, alert: @user.errors.full_messages.join("\n")
|
139
|
+
end
|
136
140
|
end
|
137
141
|
end
|
138
142
|
```
|
@@ -142,16 +146,16 @@ and bind to or create the user
|
|
142
146
|
```ruby
|
143
147
|
# app/models/user.rb
|
144
148
|
def self.from_omniauth(access_token)
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
149
|
+
data = access_token.info
|
150
|
+
user = User.where(email: data['email']).first
|
151
|
+
# Uncomment the section below if you want users to be created if they don't exist
|
152
|
+
# unless user
|
153
|
+
# user = User.create(name: data['nickname'],
|
154
|
+
# email: data['email'],
|
155
|
+
# password: Devise.friendly_token[0,20]
|
156
|
+
# )
|
157
|
+
# end
|
158
|
+
user
|
155
159
|
end
|
156
160
|
```
|
157
161
|
|
@@ -3,9 +3,8 @@ require 'base64'
|
|
3
3
|
|
4
4
|
module OmniAuth
|
5
5
|
module Strategies
|
6
|
-
# Main class for Yahoo Auth Startegy
|
7
6
|
class YahooAuth < OmniAuth::Strategies::OAuth2
|
8
|
-
|
7
|
+
USER_INFO_API = 'https://api.login.yahoo.com/openid/v1/userinfo'
|
9
8
|
|
10
9
|
option :name, 'yahoo_auth'
|
11
10
|
|
@@ -15,38 +14,42 @@ module OmniAuth
|
|
15
14
|
token_url: 'https://api.login.yahoo.com/oauth2/get_token'
|
16
15
|
}
|
17
16
|
|
18
|
-
uid
|
17
|
+
uid do
|
18
|
+
access_token.params['xoauth_yahoo_guid']
|
19
|
+
end
|
19
20
|
|
20
21
|
info do
|
21
22
|
prune!(
|
22
|
-
nickname: raw_info['
|
23
|
-
email:
|
24
|
-
first_name: raw_info['
|
25
|
-
last_name: raw_info['
|
26
|
-
image:
|
23
|
+
nickname: raw_info['preferred_username'],
|
24
|
+
email: raw_info['email'],
|
25
|
+
first_name: raw_info['given_name'],
|
26
|
+
last_name: raw_info['family_name'],
|
27
|
+
image: raw_info['picture'],
|
27
28
|
)
|
28
29
|
end
|
29
30
|
|
30
31
|
extra do
|
31
32
|
prune!(
|
33
|
+
sub: raw_info['sub'],
|
34
|
+
name: raw_info['name'],
|
35
|
+
middle_name: raw_info['middle_name'],
|
36
|
+
nickname: raw_info['nickname'],
|
32
37
|
gender: raw_info['gender'],
|
33
|
-
language: raw_info['
|
34
|
-
|
35
|
-
birth_year: raw_info['birthYear'],
|
38
|
+
language: raw_info['locale'],
|
39
|
+
website: raw_info['website'],
|
36
40
|
birth_date: raw_info['birthdate'],
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
zone_info: raw_info['zoneinfo'],
|
42
|
+
updated_at: raw_info['updated_at'],
|
43
|
+
email_verified: raw_info['email_verified'],
|
44
|
+
address: raw_info['address'],
|
45
|
+
phone_number: raw_info['phone_number'],
|
46
|
+
phone_number_verified: raw_info['phone_number_verified'],
|
42
47
|
)
|
43
48
|
end
|
44
49
|
|
45
50
|
def raw_info
|
46
|
-
|
47
|
-
|
48
|
-
@raw_info ||= access_token.get(raw_info_url).parsed['profile'] || {}
|
49
|
-
rescue ::Errno::ETIMEDOUT
|
51
|
+
@raw_info ||= access_token.get(USER_INFO_API).parsed
|
52
|
+
rescue ::Errno::ETIMEDOUT
|
50
53
|
raise ::Timeout::Error
|
51
54
|
end
|
52
55
|
|
@@ -58,7 +61,7 @@ module OmniAuth
|
|
58
61
|
private
|
59
62
|
|
60
63
|
def callback_url
|
61
|
-
options[:redirect_uri] ||
|
64
|
+
options[:redirect_uri] || "#{full_host}#{script_name}#{callback_path}"
|
62
65
|
end
|
63
66
|
|
64
67
|
def prune!(hash)
|
@@ -68,42 +71,20 @@ module OmniAuth
|
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
71
|
-
def get_primary_email
|
72
|
-
email = nil
|
73
|
-
email_hash = raw_info['emails']
|
74
|
-
if email_hash
|
75
|
-
email_info = email_hash.find{|e| e['primary']} || email_hash.first
|
76
|
-
email = email_info['handle']
|
77
|
-
end
|
78
|
-
email
|
79
|
-
end
|
80
|
-
|
81
|
-
def get_user_image
|
82
|
-
image_size = options[:image_size]
|
83
|
-
if image_size
|
84
|
-
image_url = "#{SOCIAL_API_URL}#{uid}/profile/image/#{image_size}?format=json"
|
85
|
-
image_hash = access_token.get(image_url).parsed["image"] || {}
|
86
|
-
image_hash["imageUrl"]
|
87
|
-
else
|
88
|
-
# Return default image
|
89
|
-
raw_info['image']['imageUrl']
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
74
|
def get_access_token(request)
|
94
|
-
|
95
|
-
auth = "Basic #{Base64.strict_encode64(
|
96
|
-
|
97
|
-
|
98
|
-
|
75
|
+
credentials = "#{options.client_id}:#{options.client_secret}"
|
76
|
+
auth = "Basic #{Base64.strict_encode64(credentials)}"
|
77
|
+
|
78
|
+
client.get_token(
|
79
|
+
{
|
80
|
+
redirect_uri: callback_url,
|
81
|
+
code: request.params['code'],
|
99
82
|
grant_type: 'authorization_code',
|
100
83
|
headers: { 'Authorization' => auth }
|
101
84
|
}.merge(token_params.to_hash(symbolize_keys: true)),
|
102
|
-
deep_symbolize(options.auth_token_params || {})
|
85
|
+
deep_symbolize(options.auth_token_params || {}),
|
103
86
|
)
|
104
|
-
token
|
105
87
|
end
|
106
|
-
|
107
88
|
end
|
108
89
|
end
|
109
90
|
end
|
data/omniauth-yahoo_auth.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = "Yahoo OAuth2 Strategy for OmniAuth."
|
13
13
|
spec.description = "Yahoo OAuth2 Strategy. Supports OAuth 2.0 client-side flow. It lets you sign-in a rails app using yahoo login."
|
14
|
-
spec.homepage = "https://github.com/
|
14
|
+
spec.homepage = "https://github.com/karan-pathak/omniauth-yahoo_auth"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-yahoo_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karan Pathak
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth
|
@@ -116,11 +116,11 @@ files:
|
|
116
116
|
- lib/omniauth/yahoo_auth.rb
|
117
117
|
- lib/omniauth/yahoo_auth/version.rb
|
118
118
|
- omniauth-yahoo_auth.gemspec
|
119
|
-
homepage: https://github.com/
|
119
|
+
homepage: https://github.com/karan-pathak/omniauth-yahoo_auth
|
120
120
|
licenses:
|
121
121
|
- MIT
|
122
122
|
metadata: {}
|
123
|
-
post_install_message:
|
123
|
+
post_install_message:
|
124
124
|
rdoc_options: []
|
125
125
|
require_paths:
|
126
126
|
- lib
|
@@ -135,9 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
|
-
|
139
|
-
|
140
|
-
signing_key:
|
138
|
+
rubygems_version: 3.1.4
|
139
|
+
signing_key:
|
141
140
|
specification_version: 4
|
142
141
|
summary: Yahoo OAuth2 Strategy for OmniAuth.
|
143
142
|
test_files: []
|