oauth2_utils 2.0.0

crate that provides utility functions for working with OAuth2
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use crate::consts::URL_SAFE_CHARS;
use rand::{thread_rng, Rng};

/// Generates a random string of length `n` from URL-safe characters.
pub fn urlsafe_token(n: usize) -> String {
    (0..n)
        .map(|_| {
            URL_SAFE_CHARS
                .chars()
                .nth(thread_rng().gen_range(0..URL_SAFE_CHARS.len()))
                .unwrap()
        })
        .collect()
}