Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

be consistent about how the redirect uri is generated. #2153

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,16 @@ def generate_state(redirect_url: str, authentication_identifier: str) -> bytes:
)
return state

def get_redirect_uri_for_login_to_server(self) -> str:
host_url = request.host_url.strip("/")
login_return_path = url_for("/v1_0.spiffworkflow_backend_routes_authentication_controller_login_return")
redirect_url_to_use = f"{host_url}{login_return_path}"
return redirect_url_to_use

def get_login_redirect_url(self, state: str, authentication_identifier: str, redirect_url: str | None = None) -> str:
redirect_url_to_use = redirect_url
if redirect_url_to_use is None:
host_url = request.host_url.strip("/")
login_return_path = url_for("/v1_0.spiffworkflow_backend_routes_authentication_controller_login_return")
redirect_url_to_use = f"{host_url}{login_return_path}"
redirect_url_to_use = self.get_redirect_uri_for_login_to_server()
login_redirect_url = (
self.open_id_endpoint_for_name("authorization_endpoint", authentication_identifier=authentication_identifier)
+ f"?state={state}&"
Expand All @@ -301,20 +305,23 @@ def get_login_redirect_url(self, state: str, authentication_identifier: str, red
)
return login_redirect_url

def get_auth_token_object(self, code: str, authentication_identifier: str, redirect_url: str = "/v1.0/login_return") -> dict:
def get_auth_token_object(self, code: str, authentication_identifier: str) -> dict:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This apparently gets used in authentication_controller in the login_api_return but it's been using it wrong anyway. We may want to fix that.

backend_basic_auth_string = (
f"{self.client_id(authentication_identifier)}:{self.__class__.secret_key(authentication_identifier)}"
)
backend_basic_auth_bytes = bytes(backend_basic_auth_string, encoding="ascii")
backend_basic_auth = base64.b64encode(backend_basic_auth_bytes)
redirect_to_use = self.get_redirect_uri_for_login_to_server()

headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": f"Basic {backend_basic_auth.decode('utf-8')}",
}

data = {
"grant_type": "authorization_code",
"code": code,
"redirect_uri": f"{self.get_backend_url()}{redirect_url}",
"redirect_uri": redirect_to_use,
}

request_url = self.open_id_endpoint_for_name(
Expand Down