https://github.com/alexanderschau/access_token
Access Tokens 🔑 for Deno 🦕
https://github.com/alexanderschau/access_token
deno javascript typescript
Last synced: about 2 months ago
JSON representation
Access Tokens 🔑 for Deno 🦕
- Host: GitHub
- URL: https://github.com/alexanderschau/access_token
- Owner: alexanderschau
- Created: 2021-08-27T11:54:46.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-05-01T09:18:50.000Z (about 4 years ago)
- Last Synced: 2025-11-09T22:47:32.962Z (8 months ago)
- Topics: deno, javascript, typescript
- Language: TypeScript
- Homepage: https://deno.land/x/access_token
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# access_token
Random Token Generator for Deno 🦕 and the Browser.
## Example
```ts
import { accessToken } from "https://deno.land/x/access_token@VERSION/mod.ts";
// Create a new token
// accessToken.generate(prefix, secret?)
const token = accessToken.generate("mtt", "my_optional_secret");
// Validate a token
if (accessToken.validate(token, "my_optional_secret")) {
console.log("Token is valid: ", token);
}
// Remove token from string (e.g. on Code Scanning)
const stringToCheck =
"This is my token: xxx_1BpDK7DKPGCgc4EOmsq0mGIfw45XmS1ge36n.";
const stringWithoutToken = stringToCheck.replaceAll(
accessToken.regExp,
"SECRET_TOKEN",
);
console.log("After scanning:", stringWithoutToken);
```
## Format
This token generator is inspired by [GitHub new authentication token format](https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/). It is easy to recognize (by humans and machines) and allows us to validate it, without the need to hit a database.