-
Notifications
You must be signed in to change notification settings - Fork 31
More detailed README and small bugfix #58
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
Conversation
Co-authored-by: benitav <benitav@users.noreply.github.com>
| // dart:convert doesn't like missing padding | ||
| if (part.length % 4 > 0) { | ||
| part += '=' * (4 - part.length % 4); | ||
| } | ||
| final rawData = base64Decode(part); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that JWTs use base64-url encoding instead of standard base64. Apart from the padding, there are also other minor encoding differences. Could you check if this works?
| // dart:convert doesn't like missing padding | |
| if (part.length % 4 > 0) { | |
| part += '=' * (4 - part.length % 4); | |
| } | |
| final rawData = base64Decode(part); | |
| final rawData = base64Url.decode(part); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll test, but their docs suggest otherwise: https://api.flutter.dev/flutter/dart-convert/base64Url-constant.html
requires padding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested with your suggested change and still get the same FormatException about invalid length.
dart-lang/sdk#39510 seems to suggest this is deliberate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, there does seem to be a better way to do this, brb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using https://api.flutter.dev/flutter/dart-convert/Base64Codec/normalize.html seems like a better approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Turns out my initial suggested change doesn't even make a difference - base64url.decode and base64.decode does the same thing.
This adds quite a lot of detail to the README, I think it's basically everything that I would have needed to get Hello World up and running.
I'm not sure how you feel about about having a longer readme versus moving more detail to examples/. Personally I find it quite useful to have the main gist of things in a Readme that I can read from top to bottom.
I also fixed a small bug in
getExpiryDatethat I ran into. JWTs don't use padding but it seems that dart:convert requires padding even for base64Url encoding.