Skip to content

Add a random token generator fn#27

Open
uniphil wants to merge 2 commits into
graze-social:mainfrom
at-microcosm:simple-website-rand-helper
Open

Add a random token generator fn#27
uniphil wants to merge 2 commits into
graze-social:mainfrom
at-microcosm:simple-website-rand-helper

Conversation

@uniphil
Copy link
Copy Markdown
Contributor

@uniphil uniphil commented Jun 24, 2025

The existing code in the simple-website example manually builds up tokens in a couple places, with a type cast and indexing in the process.

This change extracts token generation to a helper function, updates the types to avoid casting, and refactors it to use choose_multiple from rand0.8's SliceRandom to avoid direct indexing.

Ultimately it's only a bit more than a cosmetic change, so feel free to close/reject if you prefer keeping a flatter style with fewer helper functions.


Note that rand 0.9 has been out since January and it might be worth updating. From uses I've spotted, AIP is only affected by names changing (like rand::thread_rng() becomes just rand::rng()), so it's pretty mechanical to update. I'd be happy to follow up with that if you want!

uniphil added 2 commits June 24, 2025 11:37
The existing code manually builds up tokens in a couple places, with some casts and indexing in the process.

This change extracts token generation from an alphabet to a helper function, updates the types to avoid casting, and refactors it to use `choose_multiple` from rand0.8's `SliceRandom` to avoid direct indexing.

Ultimately it's only a bit more than a cosmetic change, so feel free to close/reject if you prefer keeping a flatter style with fewer helper functions.

---

Note that `rand 0.9` has been out since January and it might be worth updating. From uses I've spotted, AIP is only affected by names changing in 0.9 (like `rand::thread_rng()` becomes just `rand::rng()`), so it's pretty mechanical to update. I'd be happy to follow up with that if you want!
@ngerakines
Copy link
Copy Markdown
Contributor

Thanks for the PR.

I think that function should probably go away in favor of the atproto_oauth::pkce::generate() method.

That said, I'm using "0.8" in atproto-identity-rs. If you're interested, I'd happily accept a PR there to bump to "0.9".

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.

2 participants