Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions fastapi_users_db_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ class SQLAlchemyBaseOAuthAccountTable(Generic[ID]):
oauth_name: Mapped[str] = mapped_column(
String(length=100), index=True, nullable=False
)
access_token: Mapped[str] = mapped_column(String(length=1024), nullable=False)
access_token: Mapped[str] = mapped_column(String(length=4096), nullable=False)
expires_at: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
refresh_token: Mapped[Optional[str]] = mapped_column(
String(length=1024), nullable=True
String(length=4096), nullable=True
)
account_id: Mapped[str] = mapped_column(
String(length=320), index=True, nullable=False
Expand Down
28 changes: 28 additions & 0 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,31 @@ async def test_queries_oauth(
"foo", "bar"
)
assert unknown_oauth_user is None


@pytest.mark.asyncio
async def test_oauth_long_access_token_roundtrip(
sqlalchemy_user_db_oauth: SQLAlchemyUserDatabase[UserOAuth, UUID_ID],
):
"""A long (>1024 characters) OAuth access_token should round-trip without truncation."""
user_create = {
"email": "lancelot@camelot.bt",
"hashed_password": "guinevere",
}

user = await sqlalchemy_user_db_oauth.create(user_create)
long_access_token = "a" * 2048
oauth_account = {
"oauth_name": "service1",
"access_token": long_access_token,
"expires_at": 1579000751,
"account_id": "user_oauth_long",
"account_email": "king.arthur@camelot.bt",
}

user = await sqlalchemy_user_db_oauth.add_oauth_account(user, oauth_account)
assert user.oauth_accounts[0].access_token == long_access_token

fetched_user = await sqlalchemy_user_db_oauth.get(user.id)
assert fetched_user is not None
assert fetched_user.oauth_accounts[0].access_token == long_access_token