wordjelly-auth 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +35 -0
- data/app/assets/images/auth/activity.jpg +0 -0
- data/app/assets/images/auth/facebook.svg +1 -0
- data/app/assets/images/auth/google_oauth2.svg +1 -0
- data/app/assets/images/auth/js_pic3.jpg +0 -0
- data/app/assets/images/auth/profile.jpg +0 -0
- data/app/assets/javascripts/auth/admin_create_users.js +2 -0
- data/app/assets/javascripts/auth/application.js +20 -0
- data/app/assets/javascripts/auth/auth_dependencies.js +12 -0
- data/app/assets/javascripts/auth/auth_modals_and_navbar.js +218 -0
- data/app/assets/javascripts/auth/clients.js +2 -0
- data/app/assets/javascripts/auth/search.js +2 -0
- data/app/assets/javascripts/auth/shopping/discounts.js +2 -0
- data/app/assets/javascripts/auth/users/profiles.js +188 -0
- data/app/assets/stylesheets/auth/admin_create_users.css +4 -0
- data/app/assets/stylesheets/auth/application.scss +14 -0
- data/app/assets/stylesheets/auth/auth_default_css.scss +13 -0
- data/app/assets/stylesheets/auth/common-styles.scss +579 -0
- data/app/assets/stylesheets/auth/overrides.scss +26 -0
- data/app/assets/stylesheets/auth/search.css +4 -0
- data/app/assets/stylesheets/auth/shopping/discounts.css +4 -0
- data/app/assets/stylesheets/auth/users/profiles.scss +40 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/auth/admin_create_users_controller.rb +89 -0
- data/app/controllers/auth/application_controller.rb +97 -0
- data/app/controllers/auth/clients_controller.rb +105 -0
- data/app/controllers/auth/concerns/activity_controller_concern.rb +32 -0
- data/app/controllers/auth/concerns/devise_concern.rb +193 -0
- data/app/controllers/auth/concerns/omni_concern.rb +310 -0
- data/app/controllers/auth/concerns/otp_concern.rb +251 -0
- data/app/controllers/auth/concerns/shopping/cart_controller_concern.rb +105 -0
- data/app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb +150 -0
- data/app/controllers/auth/concerns/shopping/discount_controller_concern.rb +97 -0
- data/app/controllers/auth/concerns/shopping/pay_u_money_controller_concern.rb +38 -0
- data/app/controllers/auth/concerns/shopping/payment_controller_concern.rb +101 -0
- data/app/controllers/auth/concerns/shopping/product_controller_concern.rb +68 -0
- data/app/controllers/auth/concerns/token_concern.rb +187 -0
- data/app/controllers/auth/confirmations_controller.rb +3 -0
- data/app/controllers/auth/mailgun_controller.rb +8 -0
- data/app/controllers/auth/omniauth_callbacks_controller.rb +6 -0
- data/app/controllers/auth/passwords_controller.rb +4 -0
- data/app/controllers/auth/profiles_controller.rb +156 -0
- data/app/controllers/auth/registrations_controller.rb +99 -0
- data/app/controllers/auth/search_controller.rb +61 -0
- data/app/controllers/auth/sessions_controller.rb +20 -0
- data/app/controllers/auth/shopping/cart_items_controller.rb +14 -0
- data/app/controllers/auth/shopping/carts_controller.rb +13 -0
- data/app/controllers/auth/shopping/discounts_controller.rb +19 -0
- data/app/controllers/auth/shopping/payments_controller.rb +13 -0
- data/app/controllers/auth/shopping/products_controller.rb +17 -0
- data/app/controllers/auth/shopping/shopping_controller.rb +86 -0
- data/app/controllers/auth/unlocks_controller.rb +3 -0
- data/app/controllers/auth/webhooks_controller.rb +3 -0
- data/app/helpers/auth/admin_create_users_helper.rb +2 -0
- data/app/helpers/auth/application_helper.rb +136 -0
- data/app/helpers/auth/clients_helper.rb +4 -0
- data/app/helpers/auth/resource_helper.rb +10 -0
- data/app/helpers/auth/search_helper.rb +2 -0
- data/app/helpers/auth/shopping/cart_items/cart_items_helper.rb +29 -0
- data/app/helpers/auth/shopping/carts/carts_helper.rb +25 -0
- data/app/helpers/auth/shopping/discounts/discounts_helper.rb +39 -0
- data/app/helpers/auth/shopping/payments/pay_u_money_helper.rb +56 -0
- data/app/helpers/auth/shopping/payments/payments_helper.rb +54 -0
- data/app/helpers/auth/shopping/products/products_helper.rb +52 -0
- data/app/helpers/auth/shopping/shopping_helper.rb +3 -0
- data/app/helpers/auth/users/profiles_helper.rb +12 -0
- data/app/jobs/otp_job.rb +92 -0
- data/app/mailers/application_mailer.rb +4 -0
- data/app/mailers/auth/notifier.rb +9 -0
- data/app/models/auth/admin_create_user.rb +3 -0
- data/app/models/auth/client.rb +52 -0
- data/app/models/auth/concerns/activity_concern.rb +112 -0
- data/app/models/auth/concerns/chief_model_concern.rb +73 -0
- data/app/models/auth/concerns/es_concern.rb +21 -0
- data/app/models/auth/concerns/notification_concern.rb +232 -0
- data/app/models/auth/concerns/notification_response_concern.rb +71 -0
- data/app/models/auth/concerns/owner_concern.rb +81 -0
- data/app/models/auth/concerns/shopping/cart_concern.rb +329 -0
- data/app/models/auth/concerns/shopping/cart_item_concern.rb +437 -0
- data/app/models/auth/concerns/shopping/discount_concern.rb +482 -0
- data/app/models/auth/concerns/shopping/discount_flow.txt +11 -0
- data/app/models/auth/concerns/shopping/pay_u_money_concern.rb +184 -0
- data/app/models/auth/concerns/shopping/payment_concern.rb +613 -0
- data/app/models/auth/concerns/shopping/product_concern.rb +102 -0
- data/app/models/auth/concerns/sms_otp_concern.rb +68 -0
- data/app/models/auth/concerns/user_concern.rb +788 -0
- data/app/models/auth/identity.rb +23 -0
- data/app/models/auth/shopping/cart.rb +3 -0
- data/app/models/auth/shopping/cart_item.rb +6 -0
- data/app/models/auth/shopping/cart_item_payment_result.rb +7 -0
- data/app/models/auth/shopping/discount.rb +4 -0
- data/app/models/auth/shopping/payment.rb +5 -0
- data/app/models/auth/shopping/product.rb +5 -0
- data/app/models/auth/user.rb +3 -0
- data/app/views/auth/admin_create_users/_admin_actions.html.erb +46 -0
- data/app/views/auth/admin_create_users/_form.html.erb +19 -0
- data/app/views/auth/admin_create_users/edit.html.erb +6 -0
- data/app/views/auth/admin_create_users/index.html.erb +25 -0
- data/app/views/auth/admin_create_users/new.html.erb +5 -0
- data/app/views/auth/admin_create_users/show.html.erb +8 -0
- data/app/views/auth/clients/_form.html.erb +41 -0
- data/app/views/auth/clients/edit.html.erb +6 -0
- data/app/views/auth/clients/index.html.erb +33 -0
- data/app/views/auth/clients/new.html.erb +5 -0
- data/app/views/auth/clients/show.html.erb +21 -0
- data/app/views/auth/confirmations/_enter_otp.html.erb +27 -0
- data/app/views/auth/confirmations/_get_otp_status.html.erb +25 -0
- data/app/views/auth/confirmations/_new_otp_input.js.erb +11 -0
- data/app/views/auth/confirmations/_resend_otp.js.erb +8 -0
- data/app/views/auth/confirmations/_resend_sms_otp.html.erb +18 -0
- data/app/views/auth/confirmations/_verify_otp.js.erb +64 -0
- data/app/views/auth/confirmations/create.js.erb +8 -0
- data/app/views/auth/confirmations/enter_otp.html.erb +7 -0
- data/app/views/auth/confirmations/get_otp_status.html.erb +3 -0
- data/app/views/auth/confirmations/new.html.erb +1 -0
- data/app/views/auth/confirmations/new.js.erb +16 -0
- data/app/views/auth/confirmations/otp_status_result.html.erb +20 -0
- data/app/views/auth/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/auth/mailer/password_change.html.erb +3 -0
- data/app/views/auth/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/auth/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/auth/modals/_ajax_error_modal.html.erb +3 -0
- data/app/views/auth/modals/_ajax_error_modal_content.html.erb +0 -0
- data/app/views/auth/modals/_edit_account_content.html.erb +68 -0
- data/app/views/auth/modals/_edit_account_success_content.html.erb +5 -0
- data/app/views/auth/modals/_error_notification.html.erb +8 -0
- data/app/views/auth/modals/_forgot_password_content.html.erb +18 -0
- data/app/views/auth/modals/_forgot_password_success_content.html.erb +8 -0
- data/app/views/auth/modals/_login_default_content.html.erb +3 -0
- data/app/views/auth/modals/_login_forms.html.erb +13 -0
- data/app/views/auth/modals/_login_navigation_options.html.erb +12 -0
- data/app/views/auth/modals/_new_otp_input.html.erb +28 -0
- data/app/views/auth/modals/_oauth_and_submit.html.erb +21 -0
- data/app/views/auth/modals/_recaptcha_tags.html.erb +4 -0
- data/app/views/auth/modals/_resend_confirmation_content.html.erb +17 -0
- data/app/views/auth/modals/_resend_confirmation_success_content.html.erb +8 -0
- data/app/views/auth/modals/_resend_otp.html.erb +23 -0
- data/app/views/auth/modals/_resource_errors.js.erb +24 -0
- data/app/views/auth/modals/_sign_in_inputs.html.erb +10 -0
- data/app/views/auth/modals/_sign_in_needed_modal.html.erb +3 -0
- data/app/views/auth/modals/_sign_in_success_content.html.erb +5 -0
- data/app/views/auth/modals/_sign_up_inputs.html.erb +9 -0
- data/app/views/auth/modals/_sign_up_success_content.html.erb +1 -0
- data/app/views/auth/modals/_sign_up_success_inactive_content.html.erb +2 -0
- data/app/views/auth/modals/_unlock_content.html.erb +17 -0
- data/app/views/auth/modals/_verify_otp.html.erb +1 -0
- data/app/views/auth/modals/base_modal/_base.html.erb +25 -0
- data/app/views/auth/modals/login.js.erb +120 -0
- data/app/views/auth/modals/unlock_success_content.html.erb +8 -0
- data/app/views/auth/notifier/_email.html.erb +3 -0
- data/app/views/auth/notifier/notification.html.erb +2 -0
- data/app/views/auth/notifier/notification.text.erb +1 -0
- data/app/views/auth/omniauth_callbacks/failure.html.erb +4 -0
- data/app/views/auth/passwords/create.js.erb +12 -0
- data/app/views/auth/passwords/edit.html.erb +25 -0
- data/app/views/auth/passwords/new.html.erb +16 -0
- data/app/views/auth/passwords/new.js.erb +19 -0
- data/app/views/auth/profiles/_proxy_resource.html.erb +5 -0
- data/app/views/auth/profiles/set_proxy_resource.js.erb +1 -0
- data/app/views/auth/profiles/show.html.erb +8 -0
- data/app/views/auth/registrations/create.js.erb +40 -0
- data/app/views/auth/registrations/edit.html.erb +2 -0
- data/app/views/auth/registrations/edit.js.erb +5 -0
- data/app/views/auth/registrations/new.html.erb +33 -0
- data/app/views/auth/registrations/update.js.erb +47 -0
- data/app/views/auth/search/_search_bar.html.erb +11 -0
- data/app/views/auth/search/_search_result.html.erb +7 -0
- data/app/views/auth/search/_search_results.html.erb +4 -0
- data/app/views/auth/search/authenticated_user_search.js.erb +45 -0
- data/app/views/auth/search/authenticated_user_search.json +7 -0
- data/app/views/auth/sessions/create.js.erb +5 -0
- data/app/views/auth/sessions/new.html.erb +4 -0
- data/app/views/auth/sessions/new.js.erb +20 -0
- data/app/views/auth/shared/_devise_error_messages.html.erb +9 -0
- data/app/views/auth/shared/_links.html.erb +25 -0
- data/app/views/auth/shared/_object_errors.html.erb +12 -0
- data/app/views/auth/shared/_proxy_resource.html.erb +18 -0
- data/app/views/auth/shopping/cart_items/_form.html.erb +34 -0
- data/app/views/auth/shopping/cart_items/_show_cart_items_collection.html.erb +31 -0
- data/app/views/auth/shopping/cart_items/create_multiple.html.erb +6 -0
- data/app/views/auth/shopping/cart_items/create_multiple.json.erb +9 -0
- data/app/views/auth/shopping/cart_items/edit.html.erb +6 -0
- data/app/views/auth/shopping/cart_items/index.html.erb +52 -0
- data/app/views/auth/shopping/cart_items/new.html.erb +5 -0
- data/app/views/auth/shopping/cart_items/show.html.erb +13 -0
- data/app/views/auth/shopping/carts/_form.html.erb +35 -0
- data/app/views/auth/shopping/carts/_payment_links.html.erb +27 -0
- data/app/views/auth/shopping/carts/_remove_cart_item.html.erb +11 -0
- data/app/views/auth/shopping/carts/_show_cart_balance_info.html.erb +35 -0
- data/app/views/auth/shopping/carts/edit.html.erb +6 -0
- data/app/views/auth/shopping/carts/index.html.erb +43 -0
- data/app/views/auth/shopping/carts/new.html.erb +5 -0
- data/app/views/auth/shopping/carts/show.html.erb +46 -0
- data/app/views/auth/shopping/discounts/_form.html.erb +18 -0
- data/app/views/auth/shopping/discounts/_form_for_create_multiple_cart_items.html.erb +17 -0
- data/app/views/auth/shopping/discounts/_show_pending_discount_request.html.erb +17 -0
- data/app/views/auth/shopping/discounts/destroy.html.erb +2 -0
- data/app/views/auth/shopping/discounts/edit.html.erb +29 -0
- data/app/views/auth/shopping/discounts/index.html.erb +40 -0
- data/app/views/auth/shopping/discounts/new.html.erb +1 -0
- data/app/views/auth/shopping/discounts/show.html.erb +18 -0
- data/app/views/auth/shopping/discounts/update.html.erb +2 -0
- data/app/views/auth/shopping/payments/_approve_payment.html.erb +7 -0
- data/app/views/auth/shopping/payments/_cash_card_cheque.html.erb +24 -0
- data/app/views/auth/shopping/payments/_create_discount_coupon.html.erb +5 -0
- data/app/views/auth/shopping/payments/_form.html.erb +19 -0
- data/app/views/auth/shopping/payments/_gateway.html.erb +21 -0
- data/app/views/auth/shopping/payments/_proceed_to_gateway_or_verify_payment.html.erb +18 -0
- data/app/views/auth/shopping/payments/_refresh_payment.html.erb +7 -0
- data/app/views/auth/shopping/payments/_refund.html.erb +10 -0
- data/app/views/auth/shopping/payments/_show_payment_receipt.html.erb +12 -0
- data/app/views/auth/shopping/payments/edit.html.erb +6 -0
- data/app/views/auth/shopping/payments/index.html.erb +43 -0
- data/app/views/auth/shopping/payments/new.html.erb +13 -0
- data/app/views/auth/shopping/payments/show.html.erb +36 -0
- data/app/views/auth/shopping/products/_form.html.erb +27 -0
- data/app/views/auth/shopping/products/edit.html.erb +6 -0
- data/app/views/auth/shopping/products/index.html.erb +48 -0
- data/app/views/auth/shopping/products/index.json.erb +7 -0
- data/app/views/auth/shopping/products/new.html.erb +5 -0
- data/app/views/auth/shopping/products/show.html.erb +12 -0
- data/app/views/auth/shopping/products/show.json.erb +1 -0
- data/app/views/auth/unlocks/create.js.erb +12 -0
- data/app/views/auth/unlocks/new.html.erb +14 -0
- data/app/views/auth/unlocks/new.js.erb +17 -0
- data/app/views/auth/users/_search_result.html.erb +8 -0
- data/app/views/auth/users/profiles/_user_data.html.erb +4 -0
- data/app/views/auth/users/profiles/show.html.erb +54 -0
- data/app/views/layouts/auth/_modals.html.erb +2 -0
- data/app/views/layouts/auth/application.html.erb +17 -0
- data/app/views/layouts/auth/navbar/_navbar.html.erb +49 -0
- data/app/views/layouts/auth/navbar/_personalization.html.erb +17 -0
- data/app/views/layouts/auth/navbar/_progress_spinner.html.erb +11 -0
- data/app/views/layouts/mailer.html.erb +5 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/config/initializers/active_model.rb +36 -0
- data/config/initializers/devise.rb +623 -0
- data/config/initializers/json.rb +10 -0
- data/config/initializers/omniauth.rb +447 -0
- data/config/initializers/redis.rb +2 -0
- data/config/initializers/redis.yml +14 -0
- data/config/locales/devise.en.yml +63 -0
- data/config/routes.rb +1 -0
- data/lib/assets/javascripts/data.js +126 -0
- data/lib/assets/javascripts/jquery.calendario.js +394 -0
- data/lib/assets/javascripts/jquery.tagcloud.js +92 -0
- data/lib/assets/javascripts/leanModal.js +236 -0
- data/lib/assets/javascripts/main.js +668 -0
- data/lib/assets/javascripts/modernizr.custom.63321.js +4 -0
- data/lib/assets/javascripts/payumoney.js +9 -0
- data/lib/assets/javascripts/search.js +36 -0
- data/lib/assets/javascripts/spinner.js +77 -0
- data/lib/assets/javascripts/trianglify.min.js +2 -0
- data/lib/assets/javascripts/you_need_to_sign_in.js.erb +478 -0
- data/lib/assets/stylesheets/calendar.css +111 -0
- data/lib/assets/stylesheets/calendar_modifications.scss +276 -0
- data/lib/auth.rb +32 -0
- data/lib/auth/custom_failure.rb +3 -0
- data/lib/auth/engine.rb +231 -0
- data/lib/auth/job_exception_handler.rb +7 -0
- data/lib/auth/mailgun.rb +28 -0
- data/lib/auth/notify.rb +8 -0
- data/lib/auth/omniauth/path.rb +104 -0
- data/lib/auth/partials.rb +12 -0
- data/lib/auth/rails/routes.rb +169 -0
- data/lib/auth/search/main.rb +97 -0
- data/lib/auth/sidekiq_up.rb +16 -0
- data/lib/auth/two_factor_otp.rb +202 -0
- data/lib/auth/url_shortener.rb +29 -0
- data/lib/auth/version.rb +3 -0
- data/lib/tasks/auth_tasks.rake +4 -0
- metadata +863 -0
@@ -0,0 +1,447 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module Strategy
|
3
|
+
##abilitiy to pass models.
|
4
|
+
##returns the models that are passed in / for which we are using omniauth.
|
5
|
+
def models
|
6
|
+
options[:models] || OmniAuth.config.models
|
7
|
+
end
|
8
|
+
|
9
|
+
##a modification of the on path method to check if we are on any of the defined request or callback paths.
|
10
|
+
##tests each of the provided paths to see if we are on it.
|
11
|
+
def on_any_path?(paths)
|
12
|
+
path_found = false
|
13
|
+
paths.each do |path|
|
14
|
+
path_found = on_path?(path) ? true : path_found
|
15
|
+
end
|
16
|
+
return path_found
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def request_paths
|
21
|
+
paths = []
|
22
|
+
models.each do |model|
|
23
|
+
paths << Auth::OmniAuth::Path.omniauth_request_path(model,name)
|
24
|
+
end
|
25
|
+
paths
|
26
|
+
end
|
27
|
+
|
28
|
+
def callback_paths
|
29
|
+
paths = []
|
30
|
+
models.each do |model|
|
31
|
+
paths << Auth::OmniAuth::Path.omniauth_callback_path(model,name)
|
32
|
+
end
|
33
|
+
paths
|
34
|
+
end
|
35
|
+
|
36
|
+
##THESE ARE THE ONLY TWO METHODS THAT ARE ACTUALLY OVERRIDDEN.
|
37
|
+
def on_request_path?
|
38
|
+
on_any_path?(request_paths)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
##modified to use Auth::OmniAuth::Path
|
43
|
+
def callback_path
|
44
|
+
@callback_path ||= begin
|
45
|
+
path = options[:callback_path] if options[:callback_path].is_a?(String)
|
46
|
+
path ||= current_path if options[:callback_path].respond_to?(:call) && options[:callback_path].call(env)
|
47
|
+
path ||= custom_path(:request_path)
|
48
|
+
path ||= Auth::OmniAuth::Path.common_callback_path(name)
|
49
|
+
path
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
##request call - modified to setup the model.
|
54
|
+
def request_call
|
55
|
+
##gets.chomp
|
56
|
+
setup_phase
|
57
|
+
log :info, 'Request phase initiated.'
|
58
|
+
|
59
|
+
# store query params from the request url, extracted in the callback_phase
|
60
|
+
session['omniauth.params'] = request.params
|
61
|
+
session['omniauth.model'] = request.url
|
62
|
+
OmniAuth.config.before_request_phase.call(env) if OmniAuth.config.before_request_phase
|
63
|
+
|
64
|
+
if options.form.respond_to?(:call)
|
65
|
+
log :info, 'Rendering form from supplied Rack endpoint.'
|
66
|
+
options.form.call(env)
|
67
|
+
elsif options.form
|
68
|
+
log :info, 'Rendering form from underlying application.'
|
69
|
+
call_app!
|
70
|
+
else
|
71
|
+
if request.params['origin']
|
72
|
+
env['rack.session']['omniauth.origin'] = request.params['origin']
|
73
|
+
elsif env['HTTP_REFERER'] && !env['HTTP_REFERER'].match(/#{request_path}$/)
|
74
|
+
env['rack.session']['omniauth.origin'] = env['HTTP_REFERER']
|
75
|
+
end
|
76
|
+
request_phase
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
##now the callback call
|
81
|
+
# Performs the steps necessary to run the callback phase of a strategy.
|
82
|
+
def callback_call
|
83
|
+
#check_state
|
84
|
+
setup_phase
|
85
|
+
log :info, 'Callback phase initiated.'
|
86
|
+
@env['omniauth.origin'] = session.delete('omniauth.origin')
|
87
|
+
@env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
|
88
|
+
@env['omniauth.params'] = session.delete('omniauth.params') || {}
|
89
|
+
##FOR THE WEB BASED SYSTEM, remember this was set in the request call.
|
90
|
+
if !session['omniauth.model'].blank?
|
91
|
+
@env['omniauth.model'] = session.delete('omniauth.model')
|
92
|
+
end
|
93
|
+
OmniAuth.config.before_callback_phase.call(@env) if OmniAuth.config.before_callback_phase
|
94
|
+
callback_phase
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
module OmniAuth
|
104
|
+
module Strategies
|
105
|
+
OAuth2.class_eval do
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
def callback_phase # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength, PerceivedComplexity
|
110
|
+
|
111
|
+
error = request.params["error_reason"] || request.params["error"]
|
112
|
+
if error
|
113
|
+
fail!(error, CallbackError.new(request.params["error"], request.params["error_description"] || request.params["error_reason"], request.params["error_uri"]))
|
114
|
+
elsif !options.provider_ignores_state && (request.params["state"].to_s.empty? || request.params["state"] != session.delete("omniauth.state"))
|
115
|
+
#puts "STATE ISSUES."
|
116
|
+
headers = Hash[*env.select {|k,v| k.start_with? 'HTTP_'}
|
117
|
+
.collect {|k,v| [k.sub(/^HTTP_/, ''), v]}
|
118
|
+
.collect {|k,v| [k.split('_').collect(&:capitalize).join('-'), v]}
|
119
|
+
.sort
|
120
|
+
.flatten]
|
121
|
+
if headers["Accept"] == "application/json"
|
122
|
+
self.access_token = build_access_token
|
123
|
+
self.access_token = access_token.refresh! if access_token.expired?
|
124
|
+
super
|
125
|
+
else
|
126
|
+
#puts "came to csrf detected."
|
127
|
+
fail!(:csrf_detected, CallbackError.new(:csrf_detected, "CSRF detected"))
|
128
|
+
end
|
129
|
+
else
|
130
|
+
#puts "didnt have any initial state issues."
|
131
|
+
self.access_token = build_access_token
|
132
|
+
self.access_token = access_token.refresh! if access_token.expired?
|
133
|
+
super
|
134
|
+
end
|
135
|
+
rescue ::OAuth2::Error, CallbackError => e
|
136
|
+
fail!(:invalid_credentials, e)
|
137
|
+
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
|
138
|
+
fail!(:timeout, e)
|
139
|
+
rescue ::SocketError => e
|
140
|
+
fail!(:failed_to_connect, e)
|
141
|
+
end
|
142
|
+
|
143
|
+
protected
|
144
|
+
class CallbackError < StandardError
|
145
|
+
attr_accessor :error, :error_reason, :error_uri
|
146
|
+
|
147
|
+
def initialize(error, error_reason = nil, error_uri = nil)
|
148
|
+
self.error = error
|
149
|
+
self.error_reason = error_reason
|
150
|
+
self.error_uri = error_uri
|
151
|
+
end
|
152
|
+
|
153
|
+
def message
|
154
|
+
[error, error_reason, error_uri].compact.join(" | ")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
Facebook.class_eval do
|
159
|
+
protected
|
160
|
+
def build_access_token
|
161
|
+
if request.params["fb_exchange_token"]
|
162
|
+
##make the get request.
|
163
|
+
verify_exchange_token(request.params["fb_exchange_token"])
|
164
|
+
else
|
165
|
+
verifier = request.params["code"]
|
166
|
+
a_t = client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize(options.auth_token_params))
|
167
|
+
a_t.options.merge!(access_token_options)
|
168
|
+
a_t
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
private
|
173
|
+
def verify_exchange_token(exchange_token)
|
174
|
+
return false unless exchange_token
|
175
|
+
params = {:grant_type => "fb_exchange_token", "fb_exchange_token" => exchange_token}.merge({"client_id" => options.client_id, "client_secret" => options.client_secret})
|
176
|
+
a_t = client.get_token(params)
|
177
|
+
a_t
|
178
|
+
end
|
179
|
+
|
180
|
+
def with_authorization_code!
|
181
|
+
if request.params.key?('code') || request.params.key?('fb_exchange_token')
|
182
|
+
yield
|
183
|
+
elsif code_from_signed_request = signed_request_from_cookie && signed_request_from_cookie['code']
|
184
|
+
request.params['code'] = code_from_signed_request
|
185
|
+
@authorization_code_from_signed_request_in_cookie = true
|
186
|
+
# NOTE The code from the signed fbsr_XXX cookie is set by the FB JS SDK will confirm that the identity of the
|
187
|
+
# user contained in the signed request matches the user loading the app.
|
188
|
+
original_provider_ignores_state = options.provider_ignores_state
|
189
|
+
options.provider_ignores_state = true
|
190
|
+
begin
|
191
|
+
yield
|
192
|
+
ensure
|
193
|
+
request.params.delete('code')
|
194
|
+
@authorization_code_from_signed_request_in_cookie = false
|
195
|
+
options.provider_ignores_state = original_provider_ignores_state
|
196
|
+
end
|
197
|
+
else
|
198
|
+
raise NoAuthorizationCodeError, 'must pass either a `code` (via URL or by an `fbsr_XXX` signed request cookie)'
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
GoogleOauth2.class_eval do
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
def custom_build_access_token
|
209
|
+
#puts "Came to custome build access token."
|
210
|
+
#puts "is the request xhr?"
|
211
|
+
#puts request.xhr?
|
212
|
+
access_token =
|
213
|
+
if verify_id_token(request.params['id_token'])
|
214
|
+
## ANDROID APP USES THIS
|
215
|
+
##in this case the access token is pointless, because we dont really get any kind of access for the api, so we just build a dummy token to satisfy the way this method works, since the method is exepcte to return an access token.
|
216
|
+
##refer to
|
217
|
+
##@link: https://developers.google.com/identity/sign-in/android/backend-auth
|
218
|
+
##@ref: also refer to the signInActivity.java in the android app, where we pass in 'id_token.'
|
219
|
+
::OAuth2::AccessToken.new(client,"")
|
220
|
+
elsif request.xhr? && request.params['code']
|
221
|
+
##THIS IS FOR WEB BASED JAVASCRIPT API.
|
222
|
+
verifier = request.params['code']
|
223
|
+
client.auth_code.get_token(verifier, get_token_options('postmessage'), deep_symbolize(options.auth_token_params || {}))
|
224
|
+
elsif request.params['code'] && request.params['redirect_uri']
|
225
|
+
## THIS IS FOR WEB BASED HTML API
|
226
|
+
verifier = request.params['code']
|
227
|
+
redirect_uri = request.params['redirect_uri']
|
228
|
+
client.auth_code.get_token(verifier, get_token_options(redirect_uri), deep_symbolize(options.auth_token_params || {}))
|
229
|
+
elsif verify_token(request.params['access_token'])
|
230
|
+
#puts "came to option 4"
|
231
|
+
#puts "this is the access token passing verified."
|
232
|
+
::OAuth2::AccessToken.from_hash(client, request.params.dup)
|
233
|
+
else
|
234
|
+
## ANDROID APP USES THIS IF THE REQUEST IS FOR OFFLINE ACCESS.
|
235
|
+
##puts "came to CODE ANALYSIS"
|
236
|
+
##in this case refer to
|
237
|
+
##@link: https://developers.google.com/identity/sign-in/android/offline-access
|
238
|
+
##@ref: also refer to the signInActivity.java in the android app where we pass in 'code'
|
239
|
+
## this callback url has to match the one registerd in the credentials on google oauth console.
|
240
|
+
|
241
|
+
## the host name for this is taken from configuration.
|
242
|
+
## the default is to call the method
|
243
|
+
## #callback_url -> ref to it in #http://www.rubydoc.info/github/intridea/omniauth-oauth2/OmniAuth/Strategies/OAuth2#callback_url-instance_method
|
244
|
+
## that method calls 'full_host', but that may be the wrong host, especially in case of above mentioned android issue.
|
245
|
+
## make sure that the host you specify in Auth.configuration
|
246
|
+
url_to_pass_as_callback = Auth.configuration.host_name + script_name + callback_path
|
247
|
+
|
248
|
+
verifier = request.params["code"]
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
client.auth_code.get_token(verifier, get_token_options(url_to_pass_as_callback), deep_symbolize(options.auth_token_params))
|
253
|
+
#client.auth_code.get_token(verifier, get_token_options(url_to_pass_as_callback), deep_symbolize(options.auth_token_params))
|
254
|
+
end
|
255
|
+
|
256
|
+
verify_hd(access_token)
|
257
|
+
access_token
|
258
|
+
end
|
259
|
+
alias_method :build_access_token, :custom_build_access_token
|
260
|
+
|
261
|
+
|
262
|
+
private
|
263
|
+
|
264
|
+
def verify_id_token(id_token)
|
265
|
+
|
266
|
+
return false unless id_token
|
267
|
+
raw_response = client.request(:get, 'https://www.googleapis.com/oauth2/v3/tokeninfo',
|
268
|
+
params: { id_token: id_token }).parsed
|
269
|
+
|
270
|
+
|
271
|
+
#puts "verify id token raw response is:"
|
272
|
+
#puts raw_response
|
273
|
+
if raw_response['aud'] == options.client_id || options.authorized_client_ids.include?(raw_response['aud'])
|
274
|
+
@raw_info ||= raw_response
|
275
|
+
true
|
276
|
+
else
|
277
|
+
false
|
278
|
+
end
|
279
|
+
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
|
289
|
+
module SimpleTokenAuthentication
|
290
|
+
module Configuration
|
291
|
+
mattr_accessor :additional_identifiers
|
292
|
+
@@additional_identifiers = {}
|
293
|
+
end
|
294
|
+
|
295
|
+
## had to include option force true because otherwise devise does not throw a 401 if you try to do token_authentication inside a devise controller.
|
296
|
+
## took 3 hours to sort this mess out.
|
297
|
+
DeviseFallbackHandler.class_eval do
|
298
|
+
|
299
|
+
def authenticate_entity!(controller, entity)
|
300
|
+
controller.send("authenticate_#{entity.name_underscore}!".to_sym,{:force => true})
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
Entity.class_eval do
|
306
|
+
def header_names_for_additional_identifiers
|
307
|
+
if additional_identifiers = SimpleTokenAuthentication.additional_identifiers["#{name_underscore}".to_sym]
|
308
|
+
#puts additional_identifiers.to_s
|
309
|
+
additional_identifiers.map{|c| c = "X-#{name_underscore.camelize}-#{c.to_s.camelize}"}
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
def get_additional_identifiers_from_headers(controller)
|
314
|
+
Hash[header_names_for_additional_identifiers.map{|c| c = [c,controller.request.headers[c]]}]
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
module ActsAsTokenAuthenticatable
|
319
|
+
##this method is called whenever the email or the additional_login_param or the password is changed.
|
320
|
+
def regenerate_token
|
321
|
+
self.authentication_token = generate_authentication_token(token_generator)
|
322
|
+
self.authentication_token_expires_at = Time.now.to_i + Auth.configuration.token_regeneration_time
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
module TokenAuthenticationHandler
|
327
|
+
|
328
|
+
## here added the first line, so that it doesnt do any fallback in case we are already signed in.
|
329
|
+
## this needed to be done, in case for example:
|
330
|
+
## there are two models for which authentication is being done.
|
331
|
+
## first one authenticates,
|
332
|
+
## but then the gem attempts authentication of the second model also, and failing that, triggers the not authenticated fallback.
|
333
|
+
## to prevent that from happening, we ignore the fallback if we are already signed in.
|
334
|
+
def fallback!(entity, fallback_handler)
|
335
|
+
|
336
|
+
return if self.signed_in?
|
337
|
+
fallback_handler.fallback!(self, entity)
|
338
|
+
end
|
339
|
+
|
340
|
+
##how the token authentication works:
|
341
|
+
##the function regenerate_token is called whenever a change is made to the email/password/additional_login_param
|
342
|
+
##this sets a new authentication_token and also makes the expires at now + 1.day(default)
|
343
|
+
##when you try to sign in with tokens, if the token has expired, then regenerate_token is called, and then the record is saved.
|
344
|
+
##as a result a new token is generated.
|
345
|
+
##this will only happen at the first token auth attempt with expired tokens, because on the subsequenty try, the record will not be found(since the auth token will have changed)
|
346
|
+
##thereafter signinng in to the accoutn with the username and password,(by json/or by web if using a redirect_url which is valid), will return the auth token and es.
|
347
|
+
##this can then be used to sign in.
|
348
|
+
##token_correct function was modified to check additional parameters that maybe used for token auth.
|
349
|
+
##for the moment these are X-App-Id, and X-Es, dont yet know how I defined these.
|
350
|
+
def authenticate_entity_from_token!(entity)
|
351
|
+
##here we should find the record by the authentication token.
|
352
|
+
##then we should find
|
353
|
+
|
354
|
+
record = find_record_from_identifier(entity)
|
355
|
+
|
356
|
+
if token_correct?(record, entity, token_comparator)
|
357
|
+
return false if record.token_expired?
|
358
|
+
perform_sign_in!(record, sign_in_handler)
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
def find_record_from_identifier(entity)
|
363
|
+
|
364
|
+
token = entity.get_token_from_params_or_headers(self)
|
365
|
+
token && entity.model.find_for_authentication("authentication_token" => token)
|
366
|
+
end
|
367
|
+
|
368
|
+
def token_correct?(record, entity, token_comparator)
|
369
|
+
return false unless record
|
370
|
+
additional_identifiers = entity.get_additional_identifiers_from_headers(self)
|
371
|
+
|
372
|
+
identifier_param_value = entity.get_identifier_from_params_or_headers(self).presence
|
373
|
+
|
374
|
+
identifier_param_value = integrate_with_devise_case_insensitive_keys(identifier_param_value, entity)
|
375
|
+
|
376
|
+
additional_identifiers.each do |key,value|
|
377
|
+
a = record.client_authentication[value]
|
378
|
+
if !token_comparator.compare(a,identifier_param_value)
|
379
|
+
return false
|
380
|
+
end
|
381
|
+
end
|
382
|
+
return true
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
end
|
387
|
+
|
388
|
+
|
389
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
390
|
+
|
391
|
+
if Auth.configuration
|
392
|
+
|
393
|
+
##want to generate a hash that shows:
|
394
|
+
##{:user => 'es', :admin => 'es',......other_models => 'es'}
|
395
|
+
##this es is the additional identifier in addition to the authentication_token.
|
396
|
+
##so it has to be defined for each model.
|
397
|
+
##will also need to add app_id, and client id specific shit here.
|
398
|
+
if Auth.configuration.enable_token_auth
|
399
|
+
SimpleTokenAuthentication.configure do |cf|
|
400
|
+
q = Hash[Auth.configuration.auth_resources.keys.map{|c| c = [c.downcase.to_sym,'es']}]
|
401
|
+
cf.identifiers = q
|
402
|
+
q2 = Hash[Auth.configuration.auth_resources.keys.map{|c| c = [c.downcase.to_sym,['aid']]}]
|
403
|
+
cf.additional_identifiers = q2
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
|
408
|
+
on_failure { |env|
|
409
|
+
#puts "came to on faliure."
|
410
|
+
#puts JSON.pretty_generate(env)
|
411
|
+
Auth::OmniauthCallbacksController.action(:failure).call(env) }
|
412
|
+
|
413
|
+
oauth_credentials = Auth.configuration.oauth_credentials.map{|k,v| [OmniAuth::Utils.camelize(k).downcase, v]}.to_h
|
414
|
+
oauth_keys = oauth_credentials.keys
|
415
|
+
|
416
|
+
|
417
|
+
##determine which models are oauthable, we need to pass this into the builder.
|
418
|
+
oauthable_models = Auth.configuration.auth_resources.keys.reject{|m|
|
419
|
+
|
420
|
+
if Auth.configuration.auth_resources[m][:skip].nil?
|
421
|
+
false
|
422
|
+
elsif (Auth.configuration.auth_resources[m][:skip].include? :omniauthable)
|
423
|
+
true
|
424
|
+
else
|
425
|
+
false
|
426
|
+
end
|
427
|
+
}
|
428
|
+
|
429
|
+
|
430
|
+
OmniAuth::Strategies.constants.each do |constant|
|
431
|
+
puts "Constant is: #{constant}"
|
432
|
+
provider_key = constant.to_s.downcase
|
433
|
+
|
434
|
+
|
435
|
+
if oauth_keys.include? provider_key
|
436
|
+
|
437
|
+
|
438
|
+
provider(constant.to_s, oauth_credentials[provider_key]["app_id"], oauth_credentials[provider_key]["app_secret"],oauth_credentials[provider_key]["options"].merge!({:path_prefix => Auth::OmniAuth::Path.omniauth_prefix_path, :models => oauthable_models}))
|
439
|
+
|
440
|
+
end
|
441
|
+
|
442
|
+
|
443
|
+
end
|
444
|
+
|
445
|
+
end
|
446
|
+
|
447
|
+
end
|