Generates a non-guessable OAuth token OAuth (1 and 2) does not specify the format of tokens except that they should be strings of random characters. Tokens should not be guessable and entropy when generating the random characters is important. Which is why SystemRandom is used inste
(length=30, chars=UNICODE_ASCII_CHARACTER_SET)
| 186 | |
| 187 | |
| 188 | def generate_token(length=30, chars=UNICODE_ASCII_CHARACTER_SET): |
| 189 | """Generates a non-guessable OAuth token |
| 190 | |
| 191 | OAuth (1 and 2) does not specify the format of tokens except that they |
| 192 | should be strings of random characters. Tokens should not be guessable |
| 193 | and entropy when generating the random characters is important. Which is |
| 194 | why SystemRandom is used instead of the default random.choice method. |
| 195 | """ |
| 196 | rand = SystemRandom() |
| 197 | return ''.join(rand.choice(chars) for x in range(length)) |
| 198 | |
| 199 | |
| 200 | def generate_signed_token(private_pem, request): |
no outgoing calls
searching dependent graphs…