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

docs: add auth and context #112

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sandros94
Copy link
Contributor

Resolves #88

Should I also add an auth example via cookie?

I might need some help on the ok: false backward compatible thing

Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@a1cab88). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #112   +/-   ##
=======================================
  Coverage        ?   76.55%           
=======================================
  Files           ?        9           
  Lines           ?      708           
  Branches        ?      146           
=======================================
  Hits            ?      542           
  Misses          ?      164           
  Partials        ?        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


const hooks = defineHooks({
upgrade(request) {
const userAuth = request.headers.get("Authorization");
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use basic auth for better understanding?

One benefit of basic auth is that we can also make a proper response that asks for it.

Copy link
Contributor Author

@sandros94 sandros94 Jan 24, 2025

Choose a reason for hiding this comment

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

Like the full process of checking if userAuth is Basic, then use undio to parse the base64 and then check the user and pass? If auth is missing/incorrect respond with WWW-Authenticate header?

Copy link
Member

Choose a reason for hiding this comment

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

We can use simple atob/btoa but yes a very simple user:pass auth if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this PR I'm learning a few things about responses and WWW-Authenticate, so feel free to roast me 😅

@travis-r6s
Copy link

Thanks @sandros94, this gave me some much needed guidance! However, I found that setting the context to an object doesn't work, you have to set specific properties. For example (using [email protected]):

Trying to set request.context to a new object:

upgrade(request) {
  request.context = { data: 'test'}
},
open(peer) {
  console.log(peer.context) // logs {}
}

Setting a specific property in request.context:

upgrade(request) {
  request.context.data = 'test'
},
open(peer) {
  console.log(peer.context) // logs { data: 'test' }
}

Co-authored-by: Travis Reynolds <[email protected]>
@sandros94
Copy link
Contributor Author

@travis-r6s thanks for reporting it!

Indeed context is already initialized 😅

@pi0
Copy link
Member

pi0 commented Jan 29, 2025

Good point @travis-r6s ~> #115

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

Successfully merging this pull request may close these issues.

Describe how authentication should be handled
3 participants