MCPcopy Create free account
hub / github.com/comaps/comaps / SendAuthRequest

Function SendAuthRequest

tools/python/oauth2-flow/oauth2_flow.py:128–162  ·  view source on GitHub ↗
(authToken, cookies)

Source from the content-addressed store, hash-verified

126 return SendAuthRequest(authToken, cookies)
127
128def SendAuthRequest(authToken, cookies):
129 logging.info("Accepting OAuth2 ...")
130 # Do POST
131 payload = {
132 "authenticity_token": authToken,
133 "client_id": OAuthClientId,
134 "redirect_uri": OAuthRedirectUri,
135 "response_type": OAuthResponseType,
136 "scope": OAuthScope
137 }
138
139 headers = {
140 "Content-Type": "application/x-www-form-urlencoded",
141 "Cookie": encodeCookies(cookies),
142 "Origin": f"https://{osmHost}",
143 }
144
145 conn2 = http.client.HTTPSConnection(osmHost)
146 conn2.request("POST", f"/oauth2/authorize", urllib.parse.urlencode(payload), headers=headers)
147
148 res = conn2.getresponse()
149 if res.status != 302:
150 print(res.status)
151 print(res.headers)
152 print(res.read().decode('utf-8'))
153 raise Exception("Invalid response. Expected redirect")
154
155 redirectUri = res.headers['Location']
156 logging.info(f"Accepted OAuth2: {redirectUri}")
157 oauthCode = FindOauthCode(redirectUri)
158
159 if not oauthCode:
160 raise Exception(f"Can't find 'code' in redirect URI: {redirectUri}")
161
162 return oauthCode
163
164def FinishAuthorization(code):
165 payload = urllib.parse.urlencode({

Callers 2

FetchRequestTokenFunction · 0.85
FetchRequestTokenMethod · 0.85

Calls 3

encodeCookiesFunction · 0.85
FindOauthCodeFunction · 0.70
readMethod · 0.45

Tested by

no test coverage detected