-
Notifications
You must be signed in to change notification settings - Fork 171
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/remove-pydantic-dependency #195
Conversation
I'll be sure to document this behavior too, I promise 🙏 |
I am still struggling to get this to work with my sample front-end. I don't understand this code in def options_to_json():
generate_registration_options already has done:
So it will always be 'bytes' and then convert it to base64? |
Right, this is current behavior that's confusing and definitely not desirable as per another comment I left over in #180:
I've stashed a couple of approaches I plan on taking after merging this PR to fix this. I'll either A) always treat tl;dr: for this PR the behavior will remain as-is. I'll fix this behavior afterwards as it's very confusing. |
Sorry to be a pain here - this affects the front-end API and changing that needs careful consideration and of course breaks backwards compatibility. So front-ends (mostly JS I presume) must take user.id and b64decode into a Uint8Array to pass into credentials.create - then take the response from authentication (user_handle) and send it back as plain utf-8? Or send it back as b64encoded and have RP code do the decode (which will break if you change it). I suppose I am asking if this could be 'fixed' (either way) PRIOR to releasing. (different PR is fine - just prior to release) and and that you give this a major release change (2.0). As always - thanks for all the effort and consideration you put into the package... we are all very very appreciative. |
To get the most out of If a user of this library does base64url-decode If they do not base64url-decode This...is potentially going to make migrating from v1.x to v2.0 of py_webauthn a little messy. I think the simplest migration path would involve base64url-encoding the string they pass in for To reiterate, a goal of the upcoming v2 is for the UTF-8 bytes that an RP specifies for All of this said, I honestly don't think
I don't think I want to put much effort into trying to solve this with the current |
As always - thank you for your detailed response..Part of the confusion for me is that string (unicode) != UTF-8 in python - and in python, converting a string to UTF-8 ("my string").encode() results in bytes - which isn't JSON encodable (you have to cast it back to string). So your goal of having user.id be a 'string' seems good but does anything care if it encoded as long as what is returned as part of authentication is the same as was passed into registration? All that aside - I have everything working with this PR - with just the one modification to b64decode in my signin code. |
I went digging into Python's Unicode support and it's my understanding "Unicode support" in Python commonly refers to UTF-8, based on https://docs.python.org/3/howto/unicode.html#encodings:
As for the results of your testing...
Thank you for taking the time to test this PR. I'll go ahead with it, but it won't go out immediately as v2.0. I'll be making a couple of other breaking changes (like the user ID stuff we've talked about in here) before rolling all of that into v2.0. |
In python 3 all strings are unicode. It is true that utf-8 is the default encoding (e.g. "hi there".encode()) will convert the unicode string "hi there" to a UTF-8 encoded series of bytes. One thing I noticed was the W3C spec calls user.id "A user handle is an opaque byte sequence with a maximum size of 64 bytes, and is not meant to be displayed to the user." Since unicode may or may not be 1-1 with bytes - I wonder if it would be better for the py_webauthn API to take bytes - not string - in order to avoid an issue with upon encoding it is too long. Then I suppose encoding that using b64 encoding in order to create a JSON serializable value and having the front-end convert to a uint8array (as I know mine does today) . The same in the reverse upon authentication response. Of course - this behavior is pretty much exactly what py_webauthn and pydantic 1.0 did :-) I don't really care either way - my user_handle is a 64 bytes hex string. At a minimum it is probably worth documenting the restrictions on passing in an arbitrary unicode string. |
An experiment in simplifying the list of this package's dependencies. PR is currently a WIP while I continue to explore this.
Fixes #196.