wordjelly-auth 1.1.3 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cb43cf177bb80797b7011f1850899c05597bd76
4
- data.tar.gz: 6ce499feaf489e896da3c2ef53c36d64415b8d4d
3
+ metadata.gz: 4d20b2fcd50ad02956b13be49b0ba68bbb9e2c7e
4
+ data.tar.gz: b4396d3e38c252a7428cec1e6c8b09b40139ca2c
5
5
  SHA512:
6
- metadata.gz: 4a4b57e6403f995eef6067bb91c68ada767461eab3305a8cafa341e4070364e7f18876d041a51ae7fc1c7f2ddf9f76eba08d8cad6a092a761ef6e3dacc2e5032
7
- data.tar.gz: 8a4c2ffcfddb90d7462ffe57a76302b2db6a5a56531f9bc6258c7e7a702dc78d904da91f3613515a91e34191ec0bd40740d44df56def5cad221dd09697884070
6
+ metadata.gz: bde2aa36e8ef34c8cfef1652a88a9da1f6b0f0089d818aebf36620b6003618bbf5df098d71b1cfc8630117e2e8033b46d9afb2168cfea85c5f26c50424581815
7
+ data.tar.gz: beb36a2874a51032543449918b38bd3225d5a40c0b1e4073ce114b9421f92102dd85a90a9fbabac089437a049fc4a5958db31b1d04e5db5018d903c3159445f1
@@ -12,7 +12,70 @@ module Auth
12
12
  end
13
13
  end
14
14
 
15
-
15
+
16
+ ######################################################################
17
+ ##
18
+ ##
19
+ ## METHODS USED ON AUTHENTICATED_CONTROLLER, and some other controllers.
20
+ ##
21
+ ##
22
+ ######################################################################
23
+
24
+ ## @return[String] model_name : given a controller with name AssembliesController -> will return assembly
25
+ ## will downcase and singularize the controller name.
26
+ def get_model_class_name
27
+
28
+ class_name = nil
29
+
30
+ self.class.name.scan(/::(?<plural_controller_name>[A-Za-z]+)Controller$/) do |ll|
31
+
32
+ jj = Regexp.last_match
33
+
34
+ plural_controller_name = jj[:plural_controller_name]
35
+
36
+ class_name = plural_controller_name.singularize.downcase
37
+
38
+ end
39
+
40
+ not_found("could not determine class name") unless class_name
41
+
42
+
43
+
44
+ return class_name
45
+
46
+ end
47
+
48
+ def instantiate_classes
49
+
50
+ if Auth.configuration.send("#{get_model_class_name}_class")
51
+
52
+ begin
53
+ instance_variable_set("@model_class",Auth.configuration.send("#{get_model_class_name}_class").constantize)
54
+ rescue
55
+ not_found("could not instantiate class #{get_model_class_name}")
56
+ end
57
+
58
+ else
59
+ not_found("#{get_model_class_name} class not defined in configuration")
60
+ end
61
+
62
+ end
63
+
64
+
65
+ def build_model_from_params
66
+ pp = permitted_params
67
+ puts "the permitted_params are:"
68
+ puts permitted_params.to_s
69
+
70
+ @model_params = pp.fetch(get_model_class_name.to_sym,{})
71
+ puts "model params are:"
72
+ puts @model_params.to_s
73
+
74
+ @model = pp[:id] ? @model_class.find_self(pp[:id],current_signed_in_resource) : @model_class.new(@model_params)
75
+
76
+ end
77
+
78
+
16
79
  def from_bson(bson_doc,klass)
17
80
 
18
81
  if !bson_doc.nil?
@@ -18,59 +18,7 @@ class Auth::AuthenticatedController < Auth::ApplicationController
18
18
 
19
19
 
20
20
 
21
- ## @return[String] model_name : given a controller with name AssembliesController -> will return assembly
22
- ## will downcase and singularize the controller name.
23
- def get_model_class_name
24
-
25
- class_name = nil
26
-
27
- self.class.name.scan(/::(?<plural_controller_name>[A-Za-z]+)Controller$/) do |ll|
28
-
29
- jj = Regexp.last_match
30
-
31
- plural_controller_name = jj[:plural_controller_name]
32
-
33
- class_name = plural_controller_name.singularize.downcase
34
-
35
- end
36
-
37
- not_found("could not determine class name") unless class_name
38
-
39
-
40
-
41
- return class_name
42
21
 
43
- end
44
-
45
- def instantiate_classes
46
-
47
- if Auth.configuration.send("#{get_model_class_name}_class")
48
-
49
- begin
50
- instance_variable_set("@model_class",Auth.configuration.send("#{get_model_class_name}_class").constantize)
51
- rescue
52
- not_found("could not instantiate class #{get_model_class_name}")
53
- end
54
-
55
- else
56
- not_found("#{get_model_class_name} class not defined in configuration")
57
- end
58
-
59
- end
60
-
61
-
62
- def build_model_from_params
63
- pp = permitted_params
64
- puts "the permitted_params are:"
65
- puts permitted_params.to_s
66
-
67
- @model_params = pp.fetch(get_model_class_name.to_sym,{})
68
- puts "model params are:"
69
- puts @model_params.to_s
70
-
71
- @model = pp[:id] ? @model_class.find_self(pp[:id],current_signed_in_resource) : @model_class.new(@model_params)
72
-
73
- end
74
22
 
75
23
 
76
24
 
@@ -1,15 +1,50 @@
1
1
  class Auth::EndpointsController < Auth::ApplicationController
2
2
 
3
-
3
+ ## responds only to json.
4
+ ## got to add the thing to subscribe them to a topic as well.
5
+
4
6
  include Auth::Concerns::DeviseConcern
5
7
 
6
8
  CONDITIONS_FOR_TOKEN_AUTH = [:create,:update,:destroy,:edit,:new,:index]
7
9
  TCONDITIONS = {:only => CONDITIONS_FOR_TOKEN_AUTH}
8
10
  before_filter :do_before_request , TCONDITIONS
9
-
11
+ before_filter :instantiate_classes
12
+ before_filter :build_model_from_params
13
+ before_filter(:only => [:create]){|c| check_for_create(@model)}
14
+
15
+ ## all i have to do now is set the routes
16
+ ## and this should start saving endpoints automatically as needed.
17
+ ## so now lets try to make a new endpoint.
18
+ ## question is that what if that token already exists ?
19
+ ## so i will do a find_one_and_update.
10
20
 
11
21
  def create
22
+ or_clause = []
23
+
24
+ or_clause << {
25
+ "android_token" => self.android_token
26
+ } if self.android_token
12
27
 
28
+ or_clause << {
29
+ "ios_token" => self.ios_token
30
+ } if self.ios_token
31
+
32
+ returned_document = @model.class.where({
33
+ "$or" => or_clause
34
+ }).find_one_and_update(
35
+ {
36
+ "$set" => self.attributes,
37
+
38
+ },
39
+ {
40
+ :return_document => :after
41
+ }
42
+ )
43
+
44
+ respond_to do |format|
45
+ format.json {render json: return_document.to_json, status: }
46
+ end
47
+
13
48
  end
14
49
 
15
50
  def permitted_params
@@ -5,8 +5,13 @@ class Auth::Endpoint
5
5
  field :android_endpoint, type: String
6
6
  field :ios_endpoint, type: String
7
7
  field :android_token, type: String
8
+ field :ios_token, type: String
9
+
10
+ before_save :set_android_endpoint
11
+ before_save :set_ios_endpoint
8
12
 
9
13
  def set_android_endpoint
14
+ return unless self.android_token
10
15
  if response = $sns_client.create_platform_endpoint(platform_application_arn: ENV["ANDROID_ARN"], token: self.android_token, attributes: {})
11
16
  self.android_endpoint = response.endpoint_arn
12
17
  self.android_endpoint
@@ -16,9 +21,8 @@ class Auth::Endpoint
16
21
  end
17
22
 
18
23
  def set_ios_endpoint
19
-
24
+ return unless self.ios_token
20
25
  end
21
26
 
22
27
 
23
-
24
28
  end
@@ -82,7 +82,7 @@ module OmniAuth
82
82
  def callback_call
83
83
  #check_state
84
84
  setup_phase
85
- log :info, 'Callback phase initiated.'
85
+ puts 'Callback phase initiated.'
86
86
  @env['omniauth.origin'] = session.delete('omniauth.origin')
87
87
  @env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
88
88
  @env['omniauth.params'] = session.delete('omniauth.params') || {}
@@ -106,17 +106,29 @@ module OmniAuth
106
106
  OAuth2.class_eval do
107
107
 
108
108
  def callback_phase # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength, PerceivedComplexity
109
-
109
+ puts "came to callback phase."
110
+ puts "state is:"
111
+ puts "in request params:"
112
+ puts request.params["state"]
113
+ puts "session omniauth state."
114
+ puts session["omniauth.state"]
115
+ puts "options provider ignores state is:"
116
+ puts option.provider_ignores_state
117
+
110
118
  error = request.params["error_reason"] || request.params["error"]
119
+ puts "error : #{error}"
111
120
  if error
112
121
  fail!(error, CallbackError.new(request.params["error"], request.params["error_description"] || request.params["error_reason"], request.params["error_uri"]))
113
122
  elsif !options.provider_ignores_state && (request.params["state"].to_s.empty? || request.params["state"] != session.delete("omniauth.state"))
114
123
  #puts "STATE ISSUES."
124
+ puts "state is detected."
115
125
  headers = Hash[*env.select {|k,v| k.start_with? 'HTTP_'}
116
126
  .collect {|k,v| [k.sub(/^HTTP_/, ''), v]}
117
127
  .collect {|k,v| [k.split('_').collect(&:capitalize).join('-'), v]}
118
128
  .sort
119
129
  .flatten]
130
+ puts "headers accept is:"
131
+ puts headers["Accept"]
120
132
  if headers["Accept"] == "application/json"
121
133
  self.access_token = build_access_token
122
134
  self.access_token = access_token.refresh! if access_token.expired?
@@ -127,15 +139,20 @@ module OmniAuth
127
139
  end
128
140
  else
129
141
  #puts "didnt have any initial state issues."
142
+ puts "no state"
143
+ puts "going to build access token."
130
144
  self.access_token = build_access_token
131
145
  self.access_token = access_token.refresh! if access_token.expired?
132
146
  super
133
147
  end
134
148
  rescue ::OAuth2::Error, CallbackError => e
149
+ puts "invalid creds."
135
150
  fail!(:invalid_credentials, e)
136
151
  rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
152
+ puts "timeout."
137
153
  fail!(:timeout, e)
138
154
  rescue ::SocketError => e
155
+ puts "socket error."
139
156
  fail!(:failed_to_connect, e)
140
157
  end
141
158
 
data/lib/auth/engine.rb CHANGED
@@ -200,6 +200,10 @@ module Auth
200
200
 
201
201
  attr_accessor :currency
202
202
 
203
+ attr_accessor :endpoint_class
204
+
205
+ attr_accessor :endpoint_controller
206
+
203
207
  def initialize
204
208
 
205
209
 
@@ -409,7 +413,6 @@ module Auth
409
413
  ##
410
414
  ##
411
415
  ########################################################
412
-
413
416
  @image_class = "Auth::Image"
414
417
  @image_controller = "auth/images"
415
418
 
@@ -420,9 +423,18 @@ module Auth
420
423
  ##
421
424
  ########################################################
422
425
  @rolling_minutes = 30
423
-
424
426
  @currency = "INR"
425
427
 
428
+
429
+ ########################################################
430
+ ##
431
+ ## ENDPOINT CLASS.
432
+ ##
433
+ ########################################################
434
+ @endpoint_class = "Auth::Endpoint"
435
+ @endpoint_controller = "auth/endpoints"
436
+
437
+
426
438
  end
427
439
  end
428
440
 
@@ -99,6 +99,8 @@ module ActionDispatch::Routing
99
99
  resources :admin_create_users, :controller => "auth/admin_create_users"
100
100
 
101
101
  resources :clients, :controller => "auth/clients", :as => "auth_clients"
102
+
103
+ resources :endpoints, :controller => Auth.configuration.endpoint_controller
102
104
 
103
105
  resources :profiles, :controller => "auth/profiles" do
104
106
  collection do
@@ -130,6 +132,8 @@ module ActionDispatch::Routing
130
132
 
131
133
  if collection
132
134
 
135
+ ## what about the route for this ?
136
+
133
137
 
134
138
 
135
139
  ## okay so what and how much longer ?
data/lib/auth/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Auth
2
- VERSION = "1.1.3"
2
+ VERSION = "1.1.4"
3
3
  end