omniauth-naranya_id 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/naranya_id/{user.rb → models/user.rb} +6 -11
- data/lib/naranya_id/railtie.rb +134 -0
- data/lib/naranya_id.rb +126 -29
- data/lib/omniauth/strategies/naranya_id.rb +10 -6
- data/lib/omniauth-naranya_id/version.rb +1 -1
- data/lib/omniauth-naranya_id.rb +0 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd5d9ba8398dfc7cc94221b3828a0cf90b0073a4
|
4
|
+
data.tar.gz: 319f59cc5dbe14b92fa7467bb7620a3f40c41431
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e15cd66b4038afe486bac339400976ab12e32a2ce0dd7af3eab23390e1dd520665b039e55e906b73a625d98abd845a00bae20f2ebe09a2d1f4f841f7a69df9f8
|
7
|
+
data.tar.gz: 84b218948904ef1763772dd292751432c1afec452081de41b00a2d85e2618cd088528dea5d46f376d6f31d32e10a5c837f12a18336f181803ee89f09e83eff1e
|
@@ -12,11 +12,6 @@ module NaranyaId
|
|
12
12
|
|
13
13
|
class << self
|
14
14
|
|
15
|
-
def email_exists?(given_email_address)
|
16
|
-
Net::HTTP.get
|
17
|
-
consumer.post('/register/checkemail.php')
|
18
|
-
end
|
19
|
-
|
20
15
|
def translate_attributes(attributes)
|
21
16
|
translated_attributes = {
|
22
17
|
id: attributes[:uuid],
|
@@ -31,15 +26,15 @@ module NaranyaId
|
|
31
26
|
end
|
32
27
|
|
33
28
|
def find_one(options={})
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
raise "Token/Secret not provided" unless token.present? and secret.present?
|
29
|
+
options = options.with_indifferent_access
|
30
|
+
|
31
|
+
raise "Token/Secret not provided" unless options.has_key?(:token) and options.has_key?(:secret)
|
39
32
|
|
40
33
|
api_consumer = NaranyaId.consumer
|
41
34
|
|
42
|
-
|
35
|
+
NaranyaId.logger.info "Consumer key: '#{api_consumer.key}', Consumer secret: '#{api_consumer.secret}'"
|
36
|
+
NaranyaId.logger.info "Access token key: '#{options[:token]}', Access token secret: '#{options[:secret]}'"
|
37
|
+
api_access_token = ::OAuth::AccessToken.new api_consumer, options[:token], options[:secret]
|
43
38
|
|
44
39
|
user_info_response = api_access_token.get('/crmcapi/index.php/user')
|
45
40
|
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "naranya_id"
|
3
|
+
require "rails"
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
module NaranyaId
|
7
|
+
|
8
|
+
# Hooks NaranyaId into Rails 3 and higher.
|
9
|
+
#
|
10
|
+
# @since 2.0.0
|
11
|
+
class Railtie < Rails::Railtie
|
12
|
+
|
13
|
+
# # Determine which generator to use. app_generators was introduced after
|
14
|
+
# # 3.0.0.
|
15
|
+
# #
|
16
|
+
# # @example Get the generators method.
|
17
|
+
# # railtie.generators
|
18
|
+
# #
|
19
|
+
# # @return [ Symbol ] The method name to use.
|
20
|
+
# #
|
21
|
+
# # @since 2.0.0.rc.4
|
22
|
+
# def self.generator
|
23
|
+
# config.respond_to?(:app_generators) ? :app_generators : :generators
|
24
|
+
# end
|
25
|
+
|
26
|
+
# # Mapping of rescued exceptions to HTTP responses
|
27
|
+
# #
|
28
|
+
# # @example
|
29
|
+
# # railtie.rescue_responses
|
30
|
+
# #
|
31
|
+
# # @ return [Hash] rescued responses
|
32
|
+
# #
|
33
|
+
# # @since 2.4.3
|
34
|
+
# def self.rescue_responses
|
35
|
+
# {
|
36
|
+
# "Mongoid::Errors::DocumentNotFound" => :not_found,
|
37
|
+
# "Mongoid::Errors::Validations" => 422
|
38
|
+
# }
|
39
|
+
# end
|
40
|
+
|
41
|
+
# config.send(generator).orm :mongoid, migration: false
|
42
|
+
|
43
|
+
# if config.action_dispatch.rescue_responses
|
44
|
+
# config.action_dispatch.rescue_responses.merge!(rescue_responses)
|
45
|
+
# end
|
46
|
+
|
47
|
+
# rake_tasks do
|
48
|
+
# load "mongoid/railties/database.rake"
|
49
|
+
# end
|
50
|
+
|
51
|
+
# Exposes NaranyaId's configuration to the Rails application configuration.
|
52
|
+
#
|
53
|
+
# @example Set up configuration in the Rails app.
|
54
|
+
# module MyApplication
|
55
|
+
# class Application < Rails::Application
|
56
|
+
# config.naranya_id.logger = Logger.new($stdout, :warn)
|
57
|
+
# config.naranya_id.consumer_key = "AAAA"
|
58
|
+
# end
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# @since 2.0.0
|
62
|
+
config.naranya_id = ::NaranyaId
|
63
|
+
|
64
|
+
# Initialize NaranyaId. This will look for a naranya_id.yml in the config
|
65
|
+
# directory and configure NaranyaId appropriately.
|
66
|
+
#
|
67
|
+
# @since 2.0.0
|
68
|
+
initializer "naranya_id.load-config" do
|
69
|
+
config_file = Rails.root.join("config", "naranya_id.yml")
|
70
|
+
if config_file.file?
|
71
|
+
begin
|
72
|
+
::NaranyaId.load_config_from_yml!(config_file)
|
73
|
+
rescue ::NaranyaId::Errors::NoConsumerKeyConfig => e
|
74
|
+
handle_configuration_error(e)
|
75
|
+
rescue ::NaranyaId::Errors::NoConsumerSecretConfig => e
|
76
|
+
handle_configuration_error(e)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# # Set the proper error types for Rails. DocumentNotFound errors should be
|
82
|
+
# # 404s and not 500s, validation errors are 422s.
|
83
|
+
# #
|
84
|
+
# # @since 2.0.0
|
85
|
+
# config.after_initialize do
|
86
|
+
# unless config.action_dispatch.rescue_responses
|
87
|
+
# ActionDispatch::ShowExceptions.rescue_responses.update(Railtie.rescue_responses)
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
|
91
|
+
# # Due to all models not getting loaded and messing up inheritance queries
|
92
|
+
# # and indexing, we need to preload the models in order to address this.
|
93
|
+
# #
|
94
|
+
# # This will happen every request in development, once in ther other
|
95
|
+
# # environments.
|
96
|
+
# #
|
97
|
+
# # @since 2.0.0
|
98
|
+
# initializer "mongoid.preload-models" do |app|
|
99
|
+
# config.to_prepare do
|
100
|
+
# ::Rails::Mongoid.preload_models(app)
|
101
|
+
# end
|
102
|
+
# end
|
103
|
+
|
104
|
+
# config.after_initialize do
|
105
|
+
# # Unicorn clears the START_CTX when a worker is forked, so if we have
|
106
|
+
# # data in START_CTX then we know we're being preloaded. Unicorn does
|
107
|
+
# # not provide application-level hooks for executing code after the
|
108
|
+
# # process has forked, so we reconnect lazily.
|
109
|
+
# if defined?(Unicorn) && !Unicorn::HttpServer::START_CTX.empty?
|
110
|
+
# ::Mongoid.default_session.disconnect if ::Mongoid.configured?
|
111
|
+
# end
|
112
|
+
|
113
|
+
# # Passenger provides the :starting_worker_process event for executing
|
114
|
+
# # code after it has forked, so we use that and reconnect immediately.
|
115
|
+
# if ::Mongoid::Config.running_with_passenger?
|
116
|
+
# PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
117
|
+
# ::Mongoid.default_session.disconnect if forked
|
118
|
+
# end
|
119
|
+
# end
|
120
|
+
# end
|
121
|
+
|
122
|
+
# Rails runs all initializers first before getting into any generator
|
123
|
+
# code, so we have no way in the intitializer to know if we are
|
124
|
+
# generating a mongoid.yml. So instead of failing, we catch all the
|
125
|
+
# errors and print them out.
|
126
|
+
#
|
127
|
+
# @since 3.0.0
|
128
|
+
def handle_configuration_error(e)
|
129
|
+
puts "There is a configuration error with the current naranya_id.yml."
|
130
|
+
puts e.message
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/lib/naranya_id.rb
CHANGED
@@ -6,11 +6,21 @@ module NaranyaId
|
|
6
6
|
|
7
7
|
extend ActiveSupport::Autoload
|
8
8
|
|
9
|
-
|
9
|
+
autoload_under 'models' do
|
10
|
+
autoload :User
|
11
|
+
end
|
12
|
+
|
13
|
+
module Errors
|
14
|
+
class NoConsumerKeyConfig < StandardError; end
|
15
|
+
class NoConsumerSecretConfig < StandardError; end
|
16
|
+
class ExpectedConfigTypeMismatch < StandardError; end
|
17
|
+
end
|
10
18
|
|
11
19
|
include ActiveSupport::Configurable
|
12
20
|
|
13
|
-
|
21
|
+
config_accessor(:setup, :skip_info, :debug_oauth) { false }
|
22
|
+
config_accessor(:consumer_key, :consumer_secret)
|
23
|
+
config_accessor(:client_options) { {
|
14
24
|
# TODO: Eliminar el :signature_method cuando se solucione el problema
|
15
25
|
# con la firma del endpoint de access_token de Naranya ID:
|
16
26
|
# (Se reestablecerá el default de 'HMAC-SHA1')
|
@@ -18,51 +28,138 @@ module NaranyaId
|
|
18
28
|
|
19
29
|
# Sitio de Naranya ID:
|
20
30
|
# TODO: Sustituir con el URL de producción (https)
|
21
|
-
#site:
|
31
|
+
# site: "http://192.237.215.233:89",
|
22
32
|
site: "http://192.237.215.233",
|
23
|
-
|
24
33
|
scheme: :query_string,
|
25
34
|
http_method: :post,
|
26
35
|
request_token_path: "/oauthv1/request_token.php",
|
27
36
|
access_token_path: "/oauthv1/access_token.php",
|
28
|
-
authorize_path: "/oauthv1/authorize.php"
|
29
|
-
|
37
|
+
authorize_path: "/oauthv1/authorize.php",
|
38
|
+
debug_oauth: false
|
39
|
+
}.with_indifferent_access }
|
40
|
+
config_accessor(:open_timeout, :read_timeout) { 30 }
|
41
|
+
config_accessor(:authorize_params, :request_params) { {} }
|
42
|
+
config_accessor(:name) { "naranya_id" }
|
30
43
|
|
31
44
|
class << self
|
32
45
|
|
33
46
|
def consumer
|
34
|
-
|
35
|
-
|
36
|
-
|
47
|
+
|
48
|
+
raise Errors::NoConsumerKeyConfig unless config.consumer_key.present?
|
49
|
+
raise Errors::NoConsumerSecretConfig unless config.consumer_secret.present?
|
50
|
+
|
51
|
+
consumer = ::OAuth::Consumer.new(config.consumer_key, config.consumer_secret,
|
52
|
+
config.client_options.merge(site: "#{config.client_options[:site]}:89"))
|
53
|
+
|
54
|
+
consumer.http.open_timeout = config.open_timeout if config.open_timeout
|
55
|
+
consumer.http.read_timeout = config.read_timeout if config.read_timeout
|
56
|
+
|
57
|
+
# Se habilita el output sólo si en las opciones debug_oauth es true:
|
58
|
+
consumer.http.set_debug_output($stderr) if config.debug_oauth
|
59
|
+
consumer
|
60
|
+
end
|
61
|
+
|
62
|
+
def load_config_from_yml!(yml_path, env="production")
|
63
|
+
raise "YAML file doesn't exist" unless File.exist?(yml_path)
|
64
|
+
yml_config = YAML::load(ERB.new(File.read(yml_path)).result)
|
65
|
+
yml_config = yml_config[env] if yml_config.has_key?(env)
|
66
|
+
load_config_from_hash!(yml_config)
|
67
|
+
end
|
68
|
+
|
69
|
+
def load_config_from_hash!(given_hash)
|
70
|
+
configure do |config|
|
71
|
+
given_hash.each do |key, value|
|
72
|
+
|
73
|
+
existing_value = config.send(key.to_sym)
|
74
|
+
|
75
|
+
if existing_value.nil? || existing_value.is_a?(TrueClass) && value.is_a?(FalseClass) || existing_value.is_a?(FalseClass) && value.is_a?(TrueClass)
|
76
|
+
# Existing value was nil, or a boolean with a different value:
|
77
|
+
config.send "#{key}=".to_sym, value
|
78
|
+
else
|
79
|
+
if existing_value.is_a?(Hash) && value.is_a?(Hash)
|
80
|
+
# Merge hashes:
|
81
|
+
config.send "#{key}=".to_sym, existing_value.merge(value)
|
82
|
+
elsif existing_value.is_a?(Array) && value.is_a?(Array)
|
83
|
+
# Concat arrays:
|
84
|
+
config.send "#{key}=".to_sym, (existing_value + value).uniq
|
85
|
+
else
|
86
|
+
# Assign directly:
|
87
|
+
config.send "#{key}=".to_sym, value
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
37
92
|
end
|
38
93
|
end
|
39
94
|
|
40
|
-
|
41
|
-
|
95
|
+
# Get the logger.
|
96
|
+
#
|
97
|
+
# @note Will try to grab Rails' logger first before creating a new logger
|
98
|
+
# with stdout.
|
99
|
+
#
|
100
|
+
# @example Get the logger.
|
101
|
+
# Loggable.logger
|
102
|
+
#
|
103
|
+
# @return [ Logger ] The logger.
|
104
|
+
#
|
105
|
+
# @since 3.0.0
|
106
|
+
def logger
|
107
|
+
return @logger if defined?(@logger)
|
108
|
+
@logger = rails_logger || default_logger
|
42
109
|
end
|
43
110
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
111
|
+
# Set the logger.
|
112
|
+
#
|
113
|
+
# @example Set the logger.
|
114
|
+
# Loggable.logger = Logger.new($stdout)
|
115
|
+
#
|
116
|
+
# @param [ Logger ] The logger to set.
|
117
|
+
#
|
118
|
+
# @return [ Logger ] The new logger.
|
119
|
+
#
|
120
|
+
# @since 3.0.0
|
121
|
+
def logger=(logger)
|
122
|
+
@logger = logger
|
50
123
|
end
|
51
124
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
125
|
+
private
|
126
|
+
|
127
|
+
# Gets the default Mongoid logger - stdout.
|
128
|
+
#
|
129
|
+
# @api private
|
130
|
+
#
|
131
|
+
# @example Get the default logger.
|
132
|
+
# Loggable.default_logger
|
133
|
+
#
|
134
|
+
# @return [ Logger ] The default logger.
|
135
|
+
#
|
136
|
+
# @since 3.0.0
|
137
|
+
def default_logger
|
138
|
+
logger = Logger.new($stdout)
|
139
|
+
logger.level = Logger::INFO
|
140
|
+
logger
|
56
141
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
142
|
+
|
143
|
+
# Get the Rails logger if it's defined.
|
144
|
+
#
|
145
|
+
# @api private
|
146
|
+
#
|
147
|
+
# @example Get Rails' logger.
|
148
|
+
# Loggable.rails_logger
|
149
|
+
#
|
150
|
+
# @return [ Logger ] The Rails logger.
|
151
|
+
#
|
152
|
+
# @since 3.0.0
|
153
|
+
def rails_logger
|
154
|
+
defined?(::Rails) && ::Rails.respond_to?(:logger) && ::Rails.logger
|
65
155
|
end
|
156
|
+
|
66
157
|
end
|
67
158
|
|
159
|
+
end
|
160
|
+
|
161
|
+
# If we are using Rails then we will include the Mongoid railtie. This has all
|
162
|
+
# the nifty initializers that Mongoid needs.
|
163
|
+
if defined?(Rails)
|
164
|
+
require "naranya_id/railtie"
|
68
165
|
end
|
@@ -11,7 +11,7 @@ module OmniAuth
|
|
11
11
|
|
12
12
|
# This is where you pass the options you would pass when
|
13
13
|
# initializing your consumer from the OAuth gem.
|
14
|
-
option :client_options, ::NaranyaId
|
14
|
+
option :client_options, ::NaranyaId.client_options
|
15
15
|
|
16
16
|
# Override para habilitar/deshabilitar el output de debuggeo de HTTP:
|
17
17
|
def consumer
|
@@ -73,7 +73,7 @@ module OmniAuth
|
|
73
73
|
# Provee la informacion consultada del usuario vía el API de Naranya ID ()
|
74
74
|
def raw_info
|
75
75
|
@raw_info ||= begin
|
76
|
-
|
76
|
+
configure_sdk! if sdk_key_or_secret_missing? and consumer_key_and_secret_present?
|
77
77
|
u = ::NaranyaId::User.find_one(
|
78
78
|
token: access_token.params[:oauth_token],
|
79
79
|
secret: access_token.params[:oauth_token_secret]
|
@@ -86,17 +86,21 @@ module OmniAuth
|
|
86
86
|
|
87
87
|
# Indicates if the SDK's api key + secret are missing
|
88
88
|
def sdk_key_or_secret_missing?
|
89
|
-
!(::NaranyaId.
|
89
|
+
!(::NaranyaId.consumer_key && ::NaranyaId.consumer_secret)
|
90
90
|
end
|
91
91
|
|
92
92
|
# Indicates whether the consumer key and secret where configured in the strategy initializer
|
93
93
|
def consumer_key_and_secret_present?
|
94
|
-
options.consumer_key
|
94
|
+
options.consumer_key && options.consumer_secret
|
95
95
|
end
|
96
96
|
|
97
97
|
# Configures the SDK's key + secret using the strategy's configured key and secret
|
98
|
-
def
|
99
|
-
::NaranyaId.
|
98
|
+
def configure_sdk!
|
99
|
+
::NaranyaId.configure do |config|
|
100
|
+
%w(consumer_key consumer_secret debug_oauth).each do |method|
|
101
|
+
config.send "#{method}=".to_sym, options.send(method.to_sym)
|
102
|
+
end
|
103
|
+
end
|
100
104
|
end
|
101
105
|
|
102
106
|
end
|
data/lib/omniauth-naranya_id.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-naranya_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Quintanilla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -150,7 +150,8 @@ files:
|
|
150
150
|
- README.md
|
151
151
|
- Rakefile
|
152
152
|
- lib/naranya_id.rb
|
153
|
-
- lib/naranya_id/user.rb
|
153
|
+
- lib/naranya_id/models/user.rb
|
154
|
+
- lib/naranya_id/railtie.rb
|
154
155
|
- lib/omniauth-naranya_id.rb
|
155
156
|
- lib/omniauth-naranya_id/version.rb
|
156
157
|
- lib/omniauth/strategies/naranya_id.rb
|