Skip to content

Use headers instead of cookies for authorization#771

Merged
abcampo-iry merged 3 commits intomainfrom
issues/1256-use-headers-instead-of-cookies
Apr 9, 2026
Merged

Use headers instead of cookies for authorization#771
abcampo-iry merged 3 commits intomainfrom
issues/1256-use-headers-instead-of-cookies

Conversation

@abcampo-iry
Copy link
Copy Markdown
Contributor

@abcampo-iry abcampo-iry commented Apr 8, 2026

Status

What's changed?

  • Force endpoints to use authentication headers instead of Cookies
  • Removed cookie helpers since not used anymore

Steps to perform after deploying to production

If the production environment requires any extra work after this PR has been deployed detail it here. This could be running a Rake task, a migration, or upgrading a Gem. That kind of thing.

@cla-bot cla-bot bot added the cla-signed label Apr 8, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

Test coverage

90.18% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/24180882147

@abcampo-iry abcampo-iry force-pushed the issues/1256-use-headers-instead-of-cookies branch from 919f9c5 to c7199ae Compare April 8, 2026 15:09
@abcampo-iry abcampo-iry force-pushed the issues/1256-use-headers-instead-of-cookies branch from c7199ae to 019d66d Compare April 8, 2026 16:33
@abcampo-iry abcampo-iry marked this pull request as ready for review April 8, 2026 17:37
Copilot AI review requested due to automatic review settings April 8, 2026 17:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates from cookie-based authentication to header-based authentication for Scratch API endpoints. It removes the IdentifiableByCookie concern that previously read auth tokens from cookies and instead relies on the existing Identifiable concern which reads from the Authorization header. All related test files are updated to use Authorization headers instead of setting cookies.

Changes:

  • Removed IdentifiableByCookie concern (app/controllers/concerns/identifiable_by_cookie.rb)
  • Removed cookie-related code from ProjectsController and ScratchController
  • Updated all Scratch-related test files to use Authorization headers
  • Removed tests that verified cookie-setting behavior

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
app/controllers/concerns/identifiable_by_cookie.rb Deleted - cookie-based auth no longer needed
app/controllers/api/scratch/scratch_controller.rb Removed include IdentifiableByCookie
app/controllers/api/projects_controller.rb Removed cookies include and cookie-setting logic
spec/requests/projects/show_spec.rb Updated tests to verify no cookie is set, simplified test structure
spec/features/scratch/*.rb Updated all test files to use Authorization headers in place of cookie headers

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 60 to 65
it 'does not set a scratch auth cookie' do
get("/api/projects/#{project.identifier}", headers:)

expect(response).to have_http_status(:ok)
expect(response.cookies['scratch_auth']).to be_nil
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this test doesn't have any purpose now - I think it's very unlikely that we would unintentionally set this cookie on this action in the future

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree.
Moreover, my thoughts was to have a negative test and then remove the test completely after the PR is completed.
Happy to remove it in the same PR.

At least with this comment we leave record that it passed and we can remove it.

Copy link
Copy Markdown
Contributor

@zetter-rpf zetter-rpf left a comment

Choose a reason for hiding this comment

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

Great!

One very optional suggestion.

@abcampo-iry abcampo-iry force-pushed the issues/1256-use-headers-instead-of-cookies branch from 019d66d to b2944b2 Compare April 9, 2026 08:38
@abcampo-iry abcampo-iry merged commit 8ed2e84 into main Apr 9, 2026
5 checks passed
@abcampo-iry abcampo-iry deleted the issues/1256-use-headers-instead-of-cookies branch April 9, 2026 08:48
@abcampo-iry abcampo-iry restored the issues/1256-use-headers-instead-of-cookies branch April 9, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants