Initiate process of authorisation for google oauth2
()
| 88 | methods=['POST'], endpoint='verify_credentials') |
| 89 | @pga_login_required |
| 90 | def verify_credentials(): |
| 91 | """ |
| 92 | Initiate process of authorisation for google oauth2 |
| 93 | """ |
| 94 | data = json.loads(request.data) |
| 95 | client_secret_path = data['secret']['client_secret_file'] if \ |
| 96 | 'client_secret_file' in data['secret'] else None |
| 97 | status = False |
| 98 | error = None |
| 99 | res_data = {} |
| 100 | |
| 101 | client_secret_path = unquote(client_secret_path) |
| 102 | try: |
| 103 | client_secret_path = \ |
| 104 | filename_with_file_manager_path(client_secret_path) |
| 105 | except PermissionError as e: |
| 106 | return unauthorized(errormsg=sanitize_external_text(str(e))) |
| 107 | except Exception as e: |
| 108 | return bad_request(errormsg=sanitize_external_text(str(e))) |
| 109 | |
| 110 | if client_secret_path and os.path.exists(client_secret_path): |
| 111 | with open(client_secret_path, 'r') as json_file: |
| 112 | client_config = json.load(json_file) |
| 113 | |
| 114 | if 'google' not in session: |
| 115 | session['google'] = {} |
| 116 | |
| 117 | # Reuse cached Google when client_config hasn't changed; otherwise |
| 118 | # start fresh (e.g., the user picked a different secret file). |
| 119 | cached_google = _get_google_from_session() |
| 120 | if cached_google is not None and \ |
| 121 | session['google'].get('client_config') == client_config: |
| 122 | _google = cached_google |
| 123 | else: |
| 124 | _google = Google(client_config) |
| 125 | |
| 126 | # get auth url |
| 127 | host_url = request.origin + '/' |
| 128 | if request.root_path != '': |
| 129 | host_url = host_url + request.root_path + '/' |
| 130 | |
| 131 | auth_url, error_msg = _google.get_auth_url(host_url) |
| 132 | if error_msg: |
| 133 | error = error_msg |
| 134 | else: |
| 135 | status = True |
| 136 | res_data = {'auth_url': auth_url} |
| 137 | session['google']['client_config'] = client_config |
| 138 | _save_google_to_session(_google) |
| 139 | else: |
| 140 | error = 'Client secret path not found' |
| 141 | session.pop('google', None) |
| 142 | |
| 143 | return make_json_response( |
| 144 | success=status, |
| 145 | errormsg=sanitize_external_text(error), |
| 146 | data=res_data) |
| 147 |
nothing calls this directly
no test coverage detected