Skip to content

Commit

Permalink
auth-utils: Use handle_request in python server
Browse files Browse the repository at this point in the history
it will close the server after a single request
  • Loading branch information
Akianonymus committed Aug 5, 2022
1 parent 95db89f commit 6c8eb44
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions release/bash/gdl
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ class handler(BaseHTTPRequestHandler):
self.wfile.write(bytes(message, "utf8"))
with HTTPServer(('', $server_port_check_refresh_token), handler) as server:
server.serve_forever()
server.handle_request()
EOF
_tmp_server_pid="$!"
elif command -v nc 1>/dev/null;then
Expand All @@ -962,7 +962,7 @@ URL="https://accounts.google.com/o/oauth2/auth?client_id=$CLIENT_ID&redirect_uri
printf "\n%s\n" "$URL"
"${QUIET:-_print_center}" "normal" " Press enter if you have completed the process in browser" "-"
read -r _
kill "$_tmp_server_pid"
kill "$_tmp_server_pid" 1>|/dev/null 2>&1||:
if ! authorization_code="$(grep -m1 'GET.*code.*HTTP/1.1' <"$TMPFILE.code"|sed -e 's/.*GET.*code=//' -e 's/\&.*//')"&&_assert_regex "$authorization_code_regex" "$authorization_code";then
"${QUIET:-_print_center}" "normal" " Code was not fetched properly , here is some info that maybe helpful.. " "-"
"${QUIET:-_print_center}" "normal" " Code that was grabbed: $authorization_code " "-"
Expand All @@ -975,7 +975,7 @@ fi
response_check_refresh_token="$(_curl --compressed "$CURL_PROGRESS" -X POST \
--data "code=$authorization_code&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&redirect_uri=$REDIRECT_URI%3A$server_port_check_refresh_token&grant_type=authorization_code&code_verifier=$code_challenge_check_refresh_token" "$TOKEN_URL")"||:
_clear_line 1 1>&2
refresh_token_value_check_refresh_token="$(printf "%s\n" "$response_check_refresh_token"|_json_value refresh_token 1 1)"||{ printf "%s\n" "Error: Cannot fetch refresh token, make sure the authorization code was correct."&&printf "%s\n" "$response_check_refresh_token"&&return 1;}
refresh_token_value_check_refresh_token="$(printf "%s\n" "$response_check_refresh_token"|_json_value refresh_token 1 1)"||{ printf "%s\n" "Error: Code was not fetched properly , here is some info that maybe helpful.."&&printf "%s\n" "$response_check_refresh_token"&&return 1;}
_set_value direct REFRESH_TOKEN "$refresh_token_value_check_refresh_token"
{ _check_access_token "$account_name_check_refresh_token" skip_check "$response_check_refresh_token"&&_update_config "$refresh_token_name_check_refresh_token" "$refresh_token_value_check_refresh_token" "$CONFIG";}||return 1
}
Expand Down
6 changes: 3 additions & 3 deletions release/sh/gdl
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ class handler(BaseHTTPRequestHandler):
self.wfile.write(bytes(message, "utf8"))
with HTTPServer(('', $server_port_check_refresh_token), handler) as server:
server.serve_forever()
server.handle_request()
EOF
_tmp_server_pid="$!"
elif command -v nc 1>/dev/null;then
Expand All @@ -966,7 +966,7 @@ URL="https://accounts.google.com/o/oauth2/auth?client_id=$CLIENT_ID&redirect_uri
printf "\n%s\n" "$URL"
"${QUIET:-_print_center}" "normal" " Press enter if you have completed the process in browser" "-"
read -r _
kill "$_tmp_server_pid"
kill "$_tmp_server_pid" 1>|/dev/null 2>&1||:
if ! authorization_code="$(grep -m1 'GET.*code.*HTTP/1.1' <"$TMPFILE.code"|sed -e 's/.*GET.*code=//' -e 's/\&.*//')"&&_assert_regex "$authorization_code_regex" "$authorization_code";then
"${QUIET:-_print_center}" "normal" " Code was not fetched properly , here is some info that maybe helpful.. " "-"
"${QUIET:-_print_center}" "normal" " Code that was grabbed: $authorization_code " "-"
Expand All @@ -979,7 +979,7 @@ fi
response_check_refresh_token="$(_curl --compressed "$CURL_PROGRESS" -X POST \
--data "code=$authorization_code&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&redirect_uri=$REDIRECT_URI%3A$server_port_check_refresh_token&grant_type=authorization_code&code_verifier=$code_challenge_check_refresh_token" "$TOKEN_URL")"||:
_clear_line 1 1>&2
refresh_token_value_check_refresh_token="$(printf "%s\n" "$response_check_refresh_token"|_json_value refresh_token 1 1)"||{ printf "%s\n" "Error: Cannot fetch refresh token, make sure the authorization code was correct."&&printf "%s\n" "$response_check_refresh_token"&&return 1;}
refresh_token_value_check_refresh_token="$(printf "%s\n" "$response_check_refresh_token"|_json_value refresh_token 1 1)"||{ printf "%s\n" "Error: Code was not fetched properly , here is some info that maybe helpful.."&&printf "%s\n" "$response_check_refresh_token"&&return 1;}
_set_value direct REFRESH_TOKEN "$refresh_token_value_check_refresh_token"
{ _check_access_token "$account_name_check_refresh_token" skip_check "$response_check_refresh_token"&&_update_config "$refresh_token_name_check_refresh_token" "$refresh_token_value_check_refresh_token" "$CONFIG";}||return 1
}
Expand Down
6 changes: 3 additions & 3 deletions src/common/auth-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ class handler(BaseHTTPRequestHandler):
self.wfile.write(bytes(message, "utf8"))
with HTTPServer(('', ${server_port_check_refresh_token}), handler) as server:
server.serve_forever()
server.handle_request()
EOF
_tmp_server_pid="${!}"
elif command -v nc 1> /dev/null; then
Expand All @@ -384,7 +384,7 @@ EOF

"${QUIET:-_print_center}" "normal" " Press enter if you have completed the process in browser" "-"
read -r _
kill "${_tmp_server_pid}"
kill "${_tmp_server_pid}" 1>| /dev/null 2>&1 || :

if ! authorization_code="$(grep -m1 'GET.*code.*HTTP/1.1' < "${TMPFILE}.code" | sed -e 's/.*GET.*code=//' -e 's/\&.*//')" &&
_assert_regex "${authorization_code_regex}" "${authorization_code}"; then
Expand All @@ -403,7 +403,7 @@ EOF
_clear_line 1 1>&2

refresh_token_value_check_refresh_token="$(printf "%s\n" "${response_check_refresh_token}" | _json_value refresh_token 1 1)" ||
{ printf "%s\n" "Error: Cannot fetch refresh token, make sure the authorization code was correct." && printf "%s\n" "${response_check_refresh_token}" && return 1; }
{ printf "%s\n" "Error: Code was not fetched properly , here is some info that maybe helpful.." && printf "%s\n" "${response_check_refresh_token}" && return 1; }

_set_value direct REFRESH_TOKEN "${refresh_token_value_check_refresh_token}"
{ _check_access_token "${account_name_check_refresh_token}" skip_check "${response_check_refresh_token}" &&
Expand Down

0 comments on commit 6c8eb44

Please sign in to comment.