omniauth-myvr 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be539216235569cefc79eb137a4bc8d35e20b32c
4
- data.tar.gz: bf27996d04f0d8a79d68b9d4d9637e86724912bf
3
+ metadata.gz: 5628f6edef469d955e3dd28ac5489ad566fdb50d
4
+ data.tar.gz: 9a5ca5ed3183d23ed78252b9c3f219625bf3ad26
5
5
  SHA512:
6
- metadata.gz: da15aeb66bf290238efff6d17b08b201a8f926384538f15ff197e04192dd3b65aff860bf0ae58e3e60529049c8982914cab5fdbb52b05530223cd33c3c95e948
7
- data.tar.gz: d7c4b89f958917add54f746858655e895f639d3b61e1a9b8b0afc21ab737c7d34fd51e5086e8e08984275c3bc5533a43e0aa8e152d78f786e571fea46fe1ab8c
6
+ metadata.gz: ed21c07fcc864aba84088561b3df7ff59fc3365f73ad2dbbd6d4ed5eb0ae2cae2814c4ba98cfac3bcc7d8970363c33f0852ae6010a8d096ffac2950031294bb4
7
+ data.tar.gz: 6425e315fa6970f56a9913abb47484382f222dd6e833fd785f3e35ae438dcde6e3ed0ed5353a4d8bf805c041c47934bc626d27710cf4ed4e811d748367a00fd5
@@ -6,7 +6,7 @@ require 'rubygems'
6
6
  require 'bundler'
7
7
  require 'sinatra'
8
8
  require 'omniauth'
9
- require '../lib/omniauth-myvr'
9
+ require '../lib/omniauth_myvr'
10
10
 
11
11
  # Do not use for production code.
12
12
  # This is only to make setup easier when running through the sample.
@@ -5,7 +5,7 @@ require 'uri'
5
5
 
6
6
  module OmniAuth
7
7
  module Strategies
8
- class MyVROAuth < OmniAuth::Strategies::OAuth2
8
+ class Myvr < OmniAuth::Strategies::OAuth2
9
9
  BASE_SCOPE_URL = "https://api.myvr.com/auth/"
10
10
  BASE_SCOPES = %w[profile email openid]
11
11
  DEFAULT_SCOPE = "email,profile"
@@ -30,184 +30,184 @@ module OmniAuth
30
30
  option :authorized_client_ids, []
31
31
 
32
32
  option :client_options, {
33
- :site => 'https://accounts.google.com',
34
- :authorize_url => '/o/oauth2/auth',
35
- :token_url => '/o/oauth2/token'
33
+ :site => 'https://myvr.com/',
34
+ :authorize_url => '/connect/oauth/auth',
35
+ :token_url => '/connect/oauth/token'
36
36
  }
37
37
 
38
- def authorize_params
39
- super.tap do |params|
40
- options[:authorize_options].each do |k|
41
- params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
42
- end
43
-
44
- raw_scope = params[:scope] || DEFAULT_SCOPE
45
- scope_list = raw_scope.split(" ").map {|item| item.split(",")}.flatten
46
- scope_list.map! { |s| s =~ /^https?:\/\// || BASE_SCOPES.include?(s) ? s : "#{BASE_SCOPE_URL}#{s}" }
47
- params[:scope] = scope_list.join(" ")
48
- params[:access_type] = 'offline' if params[:access_type].nil?
49
- params['openid.realm'] = params.delete(:openid_realm) unless params[:openid_realm].nil?
50
-
51
- session['omniauth.state'] = params[:state] if params['state']
52
- end
53
- end
54
-
55
- uid { raw_info['sub'] || verified_email }
56
-
57
- info do
58
- prune!({
59
- :name => raw_info['name'],
60
- :email => verified_email,
61
- :first_name => raw_info['given_name'],
62
- :last_name => raw_info['family_name'],
63
- :image => image_url,
64
- :urls => {
65
- 'Google' => raw_info['profile']
66
- }
67
- })
68
- end
69
-
70
- extra do
71
- hash = {}
72
- hash[:id_token] = access_token['id_token']
73
- if !options[:skip_jwt] && !access_token['id_token'].nil?
74
- hash[:id_info] = JWT.decode(
75
- access_token['id_token'], nil, false, {
76
- :verify_iss => true,
77
- 'iss' => 'accounts.google.com',
78
- :verify_aud => true,
79
- 'aud' => options.client_id,
80
- :verify_sub => false,
81
- :verify_expiration => true,
82
- :verify_not_before => true,
83
- :verify_iat => true,
84
- :verify_jti => false,
85
- :leeway => options[:jwt_leeway]
86
- }).first
87
- end
88
- hash[:raw_info] = raw_info unless skip_info?
89
- hash[:raw_friend_info] = raw_friend_info(raw_info['sub']) unless skip_info? || options[:skip_friends]
90
- hash[:raw_image_info] = raw_image_info(raw_info['sub']) unless skip_info? || options[:skip_image_info]
91
- prune! hash
92
- end
93
-
94
- def raw_info
95
- @raw_info ||= access_token.get('https://www.googleapis.com/plus/v1/people/me/openIdConnect').parsed
96
- end
97
-
98
- def raw_friend_info(id)
99
- @raw_friend_info ||= access_token.get("https://www.googleapis.com/plus/v1/people/#{id}/people/visible").parsed
100
- end
101
-
102
- def raw_image_info(id)
103
- @raw_image_info ||= access_token.get("https://www.googleapis.com/plus/v1/people/#{id}?fields=image").parsed
104
- end
105
-
106
- def custom_build_access_token
107
- access_token =
108
- if request.xhr? && request.params['code']
109
- verifier = request.params['code']
110
- client.auth_code.get_token(verifier, get_token_options('postmessage'), deep_symbolize(options.auth_token_params || {}))
111
- elsif request.params['code'] && request.params['redirect_uri']
112
- verifier = request.params['code']
113
- redirect_uri = request.params['redirect_uri']
114
- client.auth_code.get_token(verifier, get_token_options(redirect_uri), deep_symbolize(options.auth_token_params || {}))
115
- elsif verify_token(request.params['access_token'])
116
- ::OAuth2::AccessToken.from_hash(client, request.params.dup)
117
- else
118
- verifier = request.params["code"]
119
- client.auth_code.get_token(verifier, get_token_options(callback_url), deep_symbolize(options.auth_token_params))
120
- end
121
-
122
- verify_hd(access_token)
123
- access_token
124
- end
125
- alias_method :build_access_token, :custom_build_access_token
126
-
127
- private
128
-
129
- def callback_url
130
- options[:redirect_uri] || (full_host + script_name + callback_path)
131
- end
132
-
133
- def get_token_options(redirect_uri)
134
- { :redirect_uri => redirect_uri }.merge(token_params.to_hash(:symbolize_keys => true))
135
- end
136
-
137
- def prune!(hash)
138
- hash.delete_if do |_, v|
139
- prune!(v) if v.is_a?(Hash)
140
- v.nil? || (v.respond_to?(:empty?) && v.empty?)
141
- end
142
- end
143
-
144
- def verified_email
145
- raw_info['email_verified'] ? raw_info['email'] : nil
146
- end
147
-
148
- def image_url
149
- return nil unless raw_info['picture']
150
-
151
- u = URI.parse(raw_info['picture'].gsub('https:https', 'https'))
152
-
153
- path_index = u.path.to_s.index('/photo.jpg')
154
-
155
- if path_index && image_size_opts_passed?
156
- u.path.insert(path_index, image_params)
157
- u.path = u.path.gsub('//', '/')
158
- end
159
-
160
- u.query = strip_unnecessary_query_parameters(u.query)
161
-
162
- u.to_s
163
- end
164
-
165
- def image_size_opts_passed?
166
- !!(options[:image_size] || options[:image_aspect_ratio])
167
- end
168
-
169
- def image_params
170
- image_params = []
171
- if options[:image_size].is_a?(Integer)
172
- image_params << "s#{options[:image_size]}"
173
- elsif options[:image_size].is_a?(Hash)
174
- image_params << "w#{options[:image_size][:width]}" if options[:image_size][:width]
175
- image_params << "h#{options[:image_size][:height]}" if options[:image_size][:height]
176
- end
177
- image_params << 'c' if options[:image_aspect_ratio] == 'square'
178
-
179
- '/' + image_params.join('-')
180
- end
181
-
182
- def strip_unnecessary_query_parameters(query_parameters)
183
- # strip `sz` parameter (defaults to sz=50) which overrides `image_size` options
184
- return nil if query_parameters.nil?
185
-
186
- params = CGI.parse(query_parameters)
187
- stripped_params = params.delete_if { |key| key == "sz" }
188
-
189
- # don't return an empty Hash since that would result
190
- # in URLs with a trailing ? character: http://image.url?
191
- return nil if stripped_params.empty?
192
-
193
- URI.encode_www_form(stripped_params)
194
- end
195
-
196
- def verify_token(access_token)
197
- return false unless access_token
198
- raw_response = client.request(:get, 'https://www.googleapis.com/oauth2/v3/tokeninfo',
199
- params: { access_token: access_token }).parsed
200
- raw_response['aud'] == options.client_id || options.authorized_client_ids.include?(raw_response['aud'])
201
- end
202
-
203
- def verify_hd(access_token)
204
- return true unless options.hd
205
- @raw_info ||= access_token.get('https://www.googleapis.com/plus/v1/people/me/openIdConnect').parsed
206
- allowed_hosted_domains = Array(options.hd)
207
-
208
- raise CallbackError.new(:invalid_hd, "Invalid Hosted Domain") unless allowed_hosted_domains.include? @raw_info['hd']
209
- true
210
- end
38
+ # def authorize_params
39
+ # super.tap do |params|
40
+ # options[:authorize_options].each do |k|
41
+ # params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
42
+ # end
43
+ #
44
+ # raw_scope = params[:scope] || DEFAULT_SCOPE
45
+ # scope_list = raw_scope.split(" ").map {|item| item.split(",")}.flatten
46
+ # scope_list.map! { |s| s =~ /^https?:\/\// || BASE_SCOPES.include?(s) ? s : "#{BASE_SCOPE_URL}#{s}" }
47
+ # params[:scope] = scope_list.join(" ")
48
+ # params[:access_type] = 'offline' if params[:access_type].nil?
49
+ # params['openid.realm'] = params.delete(:openid_realm) unless params[:openid_realm].nil?
50
+ #
51
+ # session['omniauth.state'] = params[:state] if params['state']
52
+ # end
53
+ # end
54
+
55
+ # uid { raw_info['sub'] || verified_email }
56
+ #
57
+ # info do
58
+ # prune!({
59
+ # :name => raw_info['name'],
60
+ # :email => verified_email,
61
+ # :first_name => raw_info['given_name'],
62
+ # :last_name => raw_info['family_name'],
63
+ # :image => image_url,
64
+ # :urls => {
65
+ # 'Google' => raw_info['profile']
66
+ # }
67
+ # })
68
+ # end
69
+ #
70
+ # extra do
71
+ # hash = {}
72
+ # hash[:id_token] = access_token['id_token']
73
+ # if !options[:skip_jwt] && !access_token['id_token'].nil?
74
+ # hash[:id_info] = JWT.decode(
75
+ # access_token['id_token'], nil, false, {
76
+ # :verify_iss => true,
77
+ # 'iss' => 'accounts.google.com',
78
+ # :verify_aud => true,
79
+ # 'aud' => options.client_id,
80
+ # :verify_sub => false,
81
+ # :verify_expiration => true,
82
+ # :verify_not_before => true,
83
+ # :verify_iat => true,
84
+ # :verify_jti => false,
85
+ # :leeway => options[:jwt_leeway]
86
+ # }).first
87
+ # end
88
+ # hash[:raw_info] = raw_info unless skip_info?
89
+ # hash[:raw_friend_info] = raw_friend_info(raw_info['sub']) unless skip_info? || options[:skip_friends]
90
+ # hash[:raw_image_info] = raw_image_info(raw_info['sub']) unless skip_info? || options[:skip_image_info]
91
+ # prune! hash
92
+ # end
93
+ #
94
+ # def raw_info
95
+ # @raw_info ||= access_token.get('https://www.googleapis.com/plus/v1/people/me/openIdConnect').parsed
96
+ # end
97
+ #
98
+ # def raw_friend_info(id)
99
+ # @raw_friend_info ||= access_token.get("https://www.googleapis.com/plus/v1/people/#{id}/people/visible").parsed
100
+ # end
101
+ #
102
+ # def raw_image_info(id)
103
+ # @raw_image_info ||= access_token.get("https://www.googleapis.com/plus/v1/people/#{id}?fields=image").parsed
104
+ # end
105
+ #
106
+ # def custom_build_access_token
107
+ # access_token =
108
+ # if request.xhr? && request.params['code']
109
+ # verifier = request.params['code']
110
+ # client.auth_code.get_token(verifier, get_token_options('postmessage'), deep_symbolize(options.auth_token_params || {}))
111
+ # elsif request.params['code'] && request.params['redirect_uri']
112
+ # verifier = request.params['code']
113
+ # redirect_uri = request.params['redirect_uri']
114
+ # client.auth_code.get_token(verifier, get_token_options(redirect_uri), deep_symbolize(options.auth_token_params || {}))
115
+ # elsif verify_token(request.params['access_token'])
116
+ # ::OAuth2::AccessToken.from_hash(client, request.params.dup)
117
+ # else
118
+ # verifier = request.params["code"]
119
+ # client.auth_code.get_token(verifier, get_token_options(callback_url), deep_symbolize(options.auth_token_params))
120
+ # end
121
+ #
122
+ # verify_hd(access_token)
123
+ # access_token
124
+ # end
125
+ # alias_method :build_access_token, :custom_build_access_token
126
+ #
127
+ # private
128
+ #
129
+ # def callback_url
130
+ # options[:redirect_uri] || (full_host + script_name + callback_path)
131
+ # end
132
+ #
133
+ # def get_token_options(redirect_uri)
134
+ # { :redirect_uri => redirect_uri }.merge(token_params.to_hash(:symbolize_keys => true))
135
+ # end
136
+ #
137
+ # def prune!(hash)
138
+ # hash.delete_if do |_, v|
139
+ # prune!(v) if v.is_a?(Hash)
140
+ # v.nil? || (v.respond_to?(:empty?) && v.empty?)
141
+ # end
142
+ # end
143
+ #
144
+ # def verified_email
145
+ # raw_info['email_verified'] ? raw_info['email'] : nil
146
+ # end
147
+ #
148
+ # def image_url
149
+ # return nil unless raw_info['picture']
150
+ #
151
+ # u = URI.parse(raw_info['picture'].gsub('https:https', 'https'))
152
+ #
153
+ # path_index = u.path.to_s.index('/photo.jpg')
154
+ #
155
+ # if path_index && image_size_opts_passed?
156
+ # u.path.insert(path_index, image_params)
157
+ # u.path = u.path.gsub('//', '/')
158
+ # end
159
+ #
160
+ # u.query = strip_unnecessary_query_parameters(u.query)
161
+ #
162
+ # u.to_s
163
+ # end
164
+ #
165
+ # def image_size_opts_passed?
166
+ # !!(options[:image_size] || options[:image_aspect_ratio])
167
+ # end
168
+ #
169
+ # def image_params
170
+ # image_params = []
171
+ # if options[:image_size].is_a?(Integer)
172
+ # image_params << "s#{options[:image_size]}"
173
+ # elsif options[:image_size].is_a?(Hash)
174
+ # image_params << "w#{options[:image_size][:width]}" if options[:image_size][:width]
175
+ # image_params << "h#{options[:image_size][:height]}" if options[:image_size][:height]
176
+ # end
177
+ # image_params << 'c' if options[:image_aspect_ratio] == 'square'
178
+ #
179
+ # '/' + image_params.join('-')
180
+ # end
181
+ #
182
+ # def strip_unnecessary_query_parameters(query_parameters)
183
+ # # strip `sz` parameter (defaults to sz=50) which overrides `image_size` options
184
+ # return nil if query_parameters.nil?
185
+ #
186
+ # params = CGI.parse(query_parameters)
187
+ # stripped_params = params.delete_if { |key| key == "sz" }
188
+ #
189
+ # # don't return an empty Hash since that would result
190
+ # # in URLs with a trailing ? character: http://image.url?
191
+ # return nil if stripped_params.empty?
192
+ #
193
+ # URI.encode_www_form(stripped_params)
194
+ # end
195
+ #
196
+ # def verify_token(access_token)
197
+ # return false unless access_token
198
+ # raw_response = client.request(:get, 'https://www.googleapis.com/oauth2/v3/tokeninfo',
199
+ # params: { access_token: access_token }).parsed
200
+ # raw_response['aud'] == options.client_id || options.authorized_client_ids.include?(raw_response['aud'])
201
+ # end
202
+ #
203
+ # def verify_hd(access_token)
204
+ # return true unless options.hd
205
+ # @raw_info ||= access_token.get('https://www.googleapis.com/plus/v1/people/me/openIdConnect').parsed
206
+ # allowed_hosted_domains = Array(options.hd)
207
+ #
208
+ # raise CallbackError.new(:invalid_hd, "Invalid Hosted Domain") unless allowed_hosted_domains.include? @raw_info['hd']
209
+ # true
210
+ # end
211
211
  end
212
212
  end
213
213
  end
@@ -1,7 +1,7 @@
1
1
  require File.join('omniauth', 'strategies', 'myvr')
2
2
 
3
3
  module OmniAuth
4
- module MyVROAuth
5
- VERSION = '0.0.1'
4
+ module Myvr
5
+ VERSION = '0.0.3'
6
6
  end
7
7
  end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "omniauth-myvr"
6
- s.version = "0.0.2"
6
+ s.version = "0.0.4"
7
7
  s.authors = ["CJ Avilla"]
8
8
  s.email = ["cjavilla@gmail.com"]
9
9
  s.homepage = "https://github.com/w1zeman1p/omniauth-myvr"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-myvr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - CJ Avilla