Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
feat: allow user to automatically roll tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Jan 21, 2024
1 parent a1a3a53 commit 03e4cd6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ A self-hosted anisette server for SideStore.

## Usage

Populate your `.env` file.

```bash
echo "CLOUDFLARE_API_TOKEN=$CLOUDFLARE_API_TOKEN" > .env
```

The token you may use to authenticate the API can be generated with the following command.

```bash
Expand Down
Binary file modified bun.lockb
Binary file not shown.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
"dev": "wrangler dev",
"deploy": "wrangler deploy",
"test": "bun test --watch",
"generate": "bun scripts/get_token.ts"
"generate": "bun scripts/generate_token.ts"
},
"dependencies": {
"tslib": "^2.6.2",
"zod": "^3.22.4"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230807.0",
"@typescript-eslint/eslint-plugin": "^6.3.0",
"@typescript-eslint/parser": "^6.3.0",
"bun-types": "^1.0.1",
"eslint": "^8.47.0",
"eslint-config-prettier": "^9.0.0",
"prettier": "^3.0.1",
"typescript": "^5.1.6",
"wrangler": "^3.5.0"
"@cloudflare/workers-types": "^4.20240117.0",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"bun-types": "^1.0.24",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"prettier": "^3.2.4",
"typescript": "^5.3.3",
"wrangler": "^3.23.0"
}
}
19 changes: 16 additions & 3 deletions scripts/generate_token.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { randomBytes } from 'crypto'

function main() {
console.log(randomBytes(48).toString('base64url'))
async function main() {
const generated_token = randomBytes(48).toString('base64url')
console.log(`[+] Your generated token is ${generated_token}`)
const save = prompt('[?] Would you like to use this token? (y/N)\n')?.toLowerCase()

if (save !== 'y') {
return
}

const process = Bun.spawn(['npx', 'wrangler', 'secret', 'put', 'TOKEN'], {
stdin: new TextEncoder().encode(generated_token)
})

const response = await new Response(process.stdout).text()
console.log(response)
}

main()
void main()

0 comments on commit 03e4cd6

Please sign in to comment.