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

[DOP-23122] add redirect_uri to auth request #146

Merged
merged 1 commit into from
Jan 24, 2025
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
20 changes: 16 additions & 4 deletions data_rentgen/server/providers/auth/keycloak_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def __init__(

@classmethod
def setup(cls, app: FastAPI) -> FastAPI:
settings = KeycloakAuthProviderSettings.model_validate(app.state.settings.auth.dict(exclude={"provider"}))
settings = KeycloakAuthProviderSettings.model_validate(
app.state.settings.auth.dict(exclude={"provider"}),
)
logger.info("Using %s provider with settings:\n%s", cls.__name__, settings)
app.dependency_overrides[AuthProvider] = cls
app.dependency_overrides[KeycloakAuthProviderSettings] = lambda: settings
Expand All @@ -48,7 +50,9 @@ async def get_token_password_grant(
login: str,
password: str,
) -> dict[str, Any]:
raise NotImplementedError("Password grant is not supported by KeycloakAuthProvider.")
raise NotImplementedError(
"Password grant is not supported by KeycloakAuthProvider.",
)

async def get_token_authorization_code_grant(
self,
Expand All @@ -58,11 +62,16 @@ async def get_token_authorization_code_grant(
return await self.keycloak_openid.a_token(
grant_type="authorization_code",
code=code,
redirect_uri=self.settings.keycloak.redirect_uri,
)
except KeycloakOperationError as e:
raise AuthorizationError("Failed to get token") from e

async def get_current_user(self, access_token: str | None, request: Request) -> User:
async def get_current_user(
self,
access_token: str | None,
request: Request,
) -> User:
if not access_token:
logger.debug("No access token found in session.")
await self.redirect_to_auth()
Expand Down Expand Up @@ -112,4 +121,7 @@ async def redirect_to_auth(self) -> NoReturn:
)

logger.info("Redirecting user to auth url: %s", auth_url)
raise RedirectError(message="Please authorize using provided URL", details=auth_url)
raise RedirectError(
message="Please authorize using provided URL",
details=auth_url,
)
Loading