-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Update token gen #4832
Update token gen #4832
Conversation
hmm seems the hex token is a bit too long for the column as is Also, here's the relevant line: https://github.com/PostHog/posthog-js/blob/cbb31c2e64d7f8f47921b801ec1a5b62b1052ff4/src/posthog-persistence.js#L51 And issue: PostHog/posthog-js#249 |
It could be a bit shorter if instead of |
A few approaches here: Could diverge Personal API Key (needs to be more secure) and Project API key so that personal keys can be base 64. I'm against this though because we might want to put personal api keys on a cookie some day (if even test keys for Docs autofill, like Stripe). Another approach is to keep as is and update personal api keys to 64 char column. And yet another (just saw @Twixes' comment as I started to write) is indeed base36. That's probably a good idea. |
Base 36 indeed would allow us to keep the 50 char limit as well |
b6d1888
to
a81e8ed
Compare
I guess we could have |
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.
V nice. I modified the number_to_b36
function a bit to actually convert to base62 – even shorter keys. And added token prefixes: phc_
for project tokens used by client libraries, 'phx_` for personal API keys offering full account access – inspired by GitHub's latest changes (though definitely not as rigorous, checksum and all, as they did). All completely under the 50 characters limit still.
Nice! Base62 works and is shorter. Neat solution. |
Also, thanks for adding the prefix. I spent a bit of time last night wondering about some changes to be made to API authentication, and having this prefix helps as we introduce new keys with different prefixes (I'm about to spec this out in an issue). |
40d30bb
to
5411894
Compare
unrelated cypress component test - merging |
Changes
On a call right now so might still need to look into tradeoffs. A hex token should not contain invalid chars for cookies though, at the expense of being longer.
Checklist