|
1 |
| -# frozen_string_literal: true |
2 |
| - |
3 |
| -class SessionController < ApplicationController |
4 |
| - # GET /auth/:provider/callback |
5 |
| - def create |
6 |
| - redirect_url = if session[:eg] |
7 |
| - "/#{session[:eg]}" |
8 |
| - else |
9 |
| - root_path |
10 |
| - end |
11 |
| - |
12 |
| - # reset the session |
13 |
| - internal_destroy |
14 |
| - |
15 |
| - Rails.logger.debug "\n==> Docusign callback Authentication response:\n#{auth_hash.to_yaml}\n" |
16 |
| - Rails.logger.info "==> Login: New token for admin user which will expire at: #{Time.at(auth_hash.credentials['expires_at'])}" |
17 |
| - store_auth_hash_from_docusign_callback |
18 |
| - redirect_to redirect_url |
19 |
| - end |
20 |
| - |
21 |
| - # GET /ds/logout |
22 |
| - def destroy |
23 |
| - internal_destroy |
24 |
| - redirect_to root_path |
25 |
| - end |
26 |
| - |
27 |
| - # def switch_api |
28 |
| - # internal_destroy |
29 |
| - # end |
30 |
| - |
31 |
| - # GET /auth/failure |
32 |
| - def omniauth_failure |
33 |
| - error_msg = "OmniAuth authentication failure message: #{params[:message]} for strategy: #{params[:strategy]} and HTTP_REFERER: #{params[:origin]}" |
34 |
| - Rails.logger.warn "\n==> #{error_msg}" |
35 |
| - flash[:notice] = error_msg |
36 |
| - redirect_to root_path |
37 |
| - end |
38 |
| - |
39 |
| - def show |
40 |
| - Rails.logger.debug "==> Session:\n#{session.to_h.to_yaml}" |
41 |
| - render json: session.to_json |
42 |
| - end |
43 |
| - |
44 |
| - protected |
45 |
| - |
46 |
| - def internal_destroy |
47 |
| - session.delete :ds_expires_at |
48 |
| - session.delete :ds_user_name |
49 |
| - session.delete :ds_access_token |
50 |
| - session.delete :ds_account_id |
51 |
| - session.delete :ds_account_name |
52 |
| - session.delete :ds_base_path |
53 |
| - session.delete 'omniauth.state' |
54 |
| - session.delete 'omniauth.params' |
55 |
| - session.delete 'omniauth.origin' |
56 |
| - session.delete :envelope_id |
57 |
| - session.delete :envelope_documents |
58 |
| - session.delete :template_id |
59 |
| - session.delete :eg |
60 |
| - session.delete :manifest |
61 |
| - session.delete :status_cfr |
62 |
| - session.delete :is_workflow_published |
63 |
| - end |
64 |
| - |
65 |
| - def store_auth_hash_from_docusign_callback |
66 |
| - session[:ds_expires_at] = auth_hash.credentials['expires_at'] |
67 |
| - session[:ds_user_name] = auth_hash.info.name |
68 |
| - session[:ds_access_token] = auth_hash.credentials.token |
69 |
| - session[:ds_account_id] = auth_hash.extra.account_id |
70 |
| - session[:ds_account_name] = auth_hash.extra.account_name |
71 |
| - session[:ds_base_path] = auth_hash.extra.base_uri |
72 |
| - end |
73 |
| - |
74 |
| - # returns hash with key structure of: |
75 |
| - # - provider |
76 |
| - # - uid |
77 |
| - # - info: [name, email, first_name, last_name] |
78 |
| - # - credentials: [token, refresh_token, expires_at, expires] |
79 |
| - # - extra: [sub, account_id, account_name, base_uri] |
80 |
| - def auth_hash |
81 |
| - @auth_hash ||= request.env['omniauth.auth'] |
82 |
| - end |
83 |
| -end |
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +class SessionController < ApplicationController |
| 4 | + # GET /auth/:provider/callback |
| 5 | + def create |
| 6 | + redirect_url = if session[:eg] |
| 7 | + "/#{session[:eg]}" |
| 8 | + else |
| 9 | + root_path |
| 10 | + end |
| 11 | + |
| 12 | + # reset the session |
| 13 | + internal_destroy |
| 14 | + |
| 15 | + Rails.logger.debug "\n==> Docusign callback Authentication response:\n#{auth_hash.to_yaml}\n" |
| 16 | + Rails.logger.info "==> Login: New token for admin user which will expire at: #{Time.at(auth_hash.credentials['expires_at'])}" |
| 17 | + store_auth_hash_from_docusign_callback |
| 18 | + redirect_to redirect_url |
| 19 | + end |
| 20 | + |
| 21 | + # GET /ds/logout |
| 22 | + def destroy |
| 23 | + internal_destroy |
| 24 | + redirect_to root_path |
| 25 | + end |
| 26 | + |
| 27 | + # def switch_api |
| 28 | + # internal_destroy |
| 29 | + # end |
| 30 | + |
| 31 | + # GET /auth/failure |
| 32 | + def omniauth_failure |
| 33 | + unless session[:pkce_failed] |
| 34 | + Rails.logger.warn "PKCE Auth failed \n" |
| 35 | + session[:pkce_failed] = true |
| 36 | + return redirect_to '/auth/docusign' |
| 37 | + end |
| 38 | + |
| 39 | + error_msg = "OmniAuth authentication failure message: #{params[:message]} for strategy: #{params[:strategy]} and HTTP_REFERER: #{params[:origin]}" |
| 40 | + Rails.logger.warn "\n==> #{error_msg}" |
| 41 | + flash[:notice] = error_msg |
| 42 | + redirect_to root_path |
| 43 | + end |
| 44 | + |
| 45 | + def show |
| 46 | + Rails.logger.debug "==> Session:\n#{session.to_h.to_yaml}" |
| 47 | + render json: session.to_json |
| 48 | + end |
| 49 | + |
| 50 | + protected |
| 51 | + |
| 52 | + def internal_destroy |
| 53 | + session.delete :ds_expires_at |
| 54 | + session.delete :ds_user_name |
| 55 | + session.delete :ds_access_token |
| 56 | + session.delete :ds_account_id |
| 57 | + session.delete :ds_account_name |
| 58 | + session.delete :ds_base_path |
| 59 | + session.delete 'omniauth.state' |
| 60 | + session.delete 'omniauth.params' |
| 61 | + session.delete 'omniauth.origin' |
| 62 | + session.delete :envelope_id |
| 63 | + session.delete :envelope_documents |
| 64 | + session.delete :template_id |
| 65 | + session.delete :eg |
| 66 | + session.delete :manifest |
| 67 | + session.delete :status_cfr |
| 68 | + session.delete :is_workflow_published |
| 69 | + end |
| 70 | + |
| 71 | + def store_auth_hash_from_docusign_callback |
| 72 | + session[:ds_expires_at] = auth_hash.credentials['expires_at'] |
| 73 | + session[:ds_user_name] = auth_hash.info.name |
| 74 | + session[:ds_access_token] = auth_hash.credentials.token |
| 75 | + session[:ds_account_id] = auth_hash.extra.account_id |
| 76 | + session[:ds_account_name] = auth_hash.extra.account_name |
| 77 | + session[:ds_base_path] = auth_hash.extra.base_uri |
| 78 | + end |
| 79 | + |
| 80 | + # returns hash with key structure of: |
| 81 | + # - provider |
| 82 | + # - uid |
| 83 | + # - info: [name, email, first_name, last_name] |
| 84 | + # - credentials: [token, refresh_token, expires_at, expires] |
| 85 | + # - extra: [sub, account_id, account_name, base_uri] |
| 86 | + def auth_hash |
| 87 | + @auth_hash ||= request.env['omniauth.auth'] |
| 88 | + end |
| 89 | +end |
0 commit comments