MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / verify_credentials

Function verify_credentials

web/pgadmin/misc/cloud/google/__init__.py:90–146  ·  view source on GitHub ↗

Initiate process of authorisation for google oauth2

()

Source from the content-addressed store, hash-verified

88 methods=['POST'], endpoint='verify_credentials')
89@pga_login_required
90def 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

Callers

nothing calls this directly

Calls 13

get_auth_urlMethod · 0.95
unauthorizedFunction · 0.90
sanitize_external_textFunction · 0.90
bad_requestFunction · 0.90
make_json_responseFunction · 0.90
_get_google_from_sessionFunction · 0.85
GoogleClass · 0.85
_save_google_to_sessionFunction · 0.85
popMethod · 0.80
existsMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected