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

unable to send refresh and access tokens together in same authentication route #30

Open
yeti9990 opened this issue Jan 1, 2024 · 0 comments

Comments

@yeti9990
Copy link

yeti9990 commented Jan 1, 2024

I'm using:

fastapi              0.108.0
fastapi-jwt          0.2.0
python-jose          3.3.0

on Mac OS, python 3.10.13. I'm not able to get the refresh_token cookie set... using:

@router.post("/users/login", status_code=status.HTTP_200_OK)
def login(
        user: UserLogin,
        response: Response,
        session: Session = Depends(get_db)
):
    rec = UserService(session).authenticate_user(user=user)
    if not rec:
        raise HTTPException(status_code=404, detail="User does NOT exist in the system")
    rec = jsonable_encoder(rec)
    subject = {
        'username': rec.get('username'),
        'role': rec.get('role'),
        'departments': rec.get('departments')
    }

    access_token = access_security.create_access_token(subject=subject, expires_delta=timedelta(minutes=1))
    refresh_token = refresh_security.create_refresh_token(subject=subject, expires_delta=timedelta(minutes=2))

    access_security.set_access_cookie(response=response, access_token=access_token)
    refresh_security.set_refresh_cookie(response=response, refresh_token=refresh_token)

    return {'user': rec, 'access_token': access_token, 'refresh_token': refresh_token}

Both show up in the JSON response, but ONLY access_token_cookie cookie is set. If i switch the order of the set_*_cookie() calls, the refresh_token_cookie is set but not access_token_cookie.

I've seen it work, but can't fig. out how or why it's failing to send both now. I'm attempting to use the JwtRefreshBearerCookie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant