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

feat(server-auth): Update getAuthenticationContext to support cookies and tokens both #10465

Merged
merged 18 commits into from
Apr 17, 2024

Conversation

dac09
Copy link
Collaborator

@dac09 dac09 commented Apr 16, 2024

Relates to: https://github.com/orgs/redwoodjs/projects/18/views/1?pane=issue&itemId=59446357

1. Updates getAuthenticationContext to parse the cookie header and pass it to authDecoder.

Note that the authentication context itself does not pull out the token from cookies, because with some providers (e.g. supabase) - we don't know the name of the cookie. This is left to the authDecoder implementation.

The return type from this function is actually just a deserialized cookie header i.e.
cookie: auth-provider=one; session=xx/yy/zz; somethingElse=bsbs => { 'auth-provider': 'one', session: 'xx/yy/zz', somethingElse: 'bsbs'

2. Retains support for header/token based auth
See test on line 259 of packages/api/src/auth/__tests__/getAuthenticationContext.test.ts. If a the authorization and auth-provider headers are passed in the request (as we do for SPA based auth) - then cookies will take precedence

The end result is that graphql requests will now work with middleware-based auth providers!

@dac09 dac09 requested a review from dthyresson April 16, 2024 09:08
@dac09 dac09 added this to the SSR milestone Apr 16, 2024
@dac09 dac09 added the release:feature This PR introduces a new feature label Apr 16, 2024
Copy link
Contributor

@dthyresson dthyresson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dac09 let's chat re schema vs scheme

packages/api/src/auth/index.ts Show resolved Hide resolved
packages/api/src/auth/index.ts Show resolved Hide resolved
packages/api/src/auth/index.ts Outdated Show resolved Hide resolved
packages/api/src/auth/index.ts Show resolved Hide resolved
packages/api/src/auth/index.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dthyresson dthyresson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with @dac09 and we'll keep the rw-isms of toke and schema (even though token may have cookie info and schema has scheme info).

Just need the cookie vs Cookie in event header update.

@dac09 dac09 enabled auto-merge (squash) April 16, 2024 13:44
@dac09 dac09 disabled auto-merge April 17, 2024 06:14
@dac09
Copy link
Collaborator Author

dac09 commented Apr 17, 2024

@dthyresson I realised we need to be more careful about this change here. Technically changing the FetchConfigProvider like we have would be a breaking change (if you use a gql client like react-query for example).

UPDATE ✅: implemented in a different way!

@dac09 dac09 merged commit 0442c39 into redwoodjs:main Apr 17, 2024
46 checks passed
@dac09 dac09 deleted the feat/gql-auth-context-cookie branch April 17, 2024 09:10
dac09 added a commit to dac09/redwood that referenced this pull request Apr 18, 2024
* 'main' of github.com:redwoodjs/redwood:
  Revert "chore(location): Accept URL-like object" (redwoodjs#10473)
  RSC: Be consistent about inlining rollup input (redwoodjs#10472)
  chore(paths): Remove outdated comment (redwoodjs#10471)
  feat(server-auth): Update getAuthenticationContext to support cookies and tokens both (redwoodjs#10465)
  chore(location): Accept URL-like object (redwoodjs#10467)
  fix(router): Remove barrel exports from router.tsx (redwoodjs#10464)
  chore(dbauth-mw): Refactor web side dbAuth creation (redwoodjs#10460)
  chore(router): Prevent circular dependency for namedRoutes (redwoodjs#10463)
  chore(router): route-validators: Better types and clean up comments (redwoodjs#10462)
  feat(server-auth): dbAuth 3/3 -  handle login, logout, signup, etc. requests if forwarded from middleware (redwoodjs#10457)
  docs(router): Document new NavLink className replacement behavior (redwoodjs#10401)
  chore(refactor): Split the router out into smaller logical units (redwoodjs#10434)
  feat(server-auth): Part 1/3: dbAuth middleware support (web side changes) (redwoodjs#10444)
  chore(auth): Build: Put ESM at the root, and CJS in /cjs (redwoodjs#10458)
  fix(ssr): Successfully serve static assets like `favicon.png` (redwoodjs#10455)
  chore(deps): update chore (redwoodjs#10367)
  (docs) Fix useCache headers and links (redwoodjs#10451)
  chore: remove aws-lambda (redwoodjs#10450)
  chore(deps): update dependency typescript to v5.4.5 (redwoodjs#10452)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:feature This PR introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants