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

Experiment and document how to use cookies vs headers for JWT tokens #33

Closed
devraj opened this issue Aug 11, 2022 · 2 comments
Closed
Assignees
Labels
security-alert identified as a security vulnerability and requires immediate resolution and pushed downstream wontfix This will not be worked on

Comments

@devraj
Copy link
Member

devraj commented Aug 11, 2022

FastAPI-JWT docs would suggest that you are able to use cookies or headers for authentication.

This is partially being raised because I am unable to get the OTC client to pass headers properly which got me to trying to use cookies instead.

This didn't seem to work (I can see that the client is passing the cookie back and forth).

The preference would be to use headers but it will be worthwhile documenting being able to use cookies as part of FastAPI.

@devraj devraj self-assigned this Aug 11, 2022
@devraj
Copy link
Member Author

devraj commented Aug 11, 2022

Switching to cookies involves these steps note the use of

  Authorize.set_access_cookies(access_token)
  Authorize.set_refresh_cookies(refresh_token)

to set the cookies and

Authorize.unset_jwt_cookies()

to unset (logout) the cookie

Note that in the cookie example the CSRF protection is turned off

class JWTAuthConfig(BaseModel):
  """A model required by the JWT auth plugin

  The FastAPI initialiser registers a decorated instance.
  """
  authjwt_token_location: set = {"cookies"}
  authjwt_secret_key:str = config.JWT_SECRET.get_secret_value()
  authjwt_access_token_expires = False
  authjwt_cookie_csrf_protect: bool = False

@devraj
Copy link
Member Author

devraj commented Sep 21, 2022

This particular portion has to do with the client side code, the OTC api clients can be configured to send headers in the following way.

Moving away from using cookies will allow us to restore CSRF protection in a uniform way (both things being handled by headers)

OpenAPI.HEADERS = async() => {
  return {};
}

const appContext: AppContextInterface = {
  apiClient: new AcaciaApiClient(OpenAPI),
  isLoggedIn: false,
  isAdmin: false,
  isStaff: false
};

there is merit to documenting both approaches and we should weigh up pros and cons for both.

@devraj devraj added the security-alert identified as a security vulnerability and requires immediate resolution and pushed downstream label Oct 13, 2022
@devraj devraj added the wontfix This will not be worked on label Oct 15, 2022
@devraj devraj closed this as completed Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security-alert identified as a security vulnerability and requires immediate resolution and pushed downstream wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant