Skip to content

Commit

Permalink
fix: Proper naming of openid accounts (#533) (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon authored Feb 19, 2024
1 parent a74cb15 commit 20a7c2b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions backend/alembic/versions/6f14afa8ea47_update_auth_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ def upgrade():
type_=sa.JSON(),
existing_nullable=True,
)

# Delete conflicting rows in oauth_account before adding unique constraint
op.execute(
"""
BEGIN;
-- Create a temporary table to store the ids of the rows to keep
CREATE TEMP TABLE keep_rows AS
SELECT DISTINCT ON (oauth_name, user_id) id
FROM oauth_account;
-- Delete rows from oauth_account that are not in the keep_rows temporary table
DELETE FROM oauth_account
WHERE id NOT IN (SELECT id FROM keep_rows);
DROP TABLE keep_rows;
COMMIT;
"""
)

op.create_unique_constraint(None, "oauth_account", ["oauth_name", "user_id"])
# ### end Alembic commands ###

Expand Down
2 changes: 2 additions & 0 deletions backend/app/api/api_v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]: # pragma
client_id=config.client_id,
client_secret=config.client_secret,
openid_configuration_endpoint=str(config.config_url),
name=config.name,
base_scopes=["openid", "/read-limited"],
)
else:
oauth_client = OpenID(
client_id=config.client_id,
client_secret=config.client_secret,
openid_configuration_endpoint=str(config.config_url),
name=config.name,
)
# Add route for authentication via OAuth2 endpoint.
oauth_router = fastapi_users.get_oauth_router(
Expand Down

0 comments on commit 20a7c2b

Please sign in to comment.