Skip to content

Commit 65f565c

Browse files
SimplyLizclaude
andcommitted
fix: Use /v1/tokens endpoint for npm token validation
Granular npm tokens return 403 on /v1/user. Use /v1/tokens to check validity, expiry date, and scopes instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5b22e63 commit 65f565c

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

.github/workflows/release.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,25 @@ jobs:
4141
run: |
4242
FAILED=false
4343
44-
# Check npm token
44+
# Check npm token (granular tokens return 403 on /v1/user, use /v1/tokens instead)
4545
echo "Checking npm token..."
46-
NPM_RESULT=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer $NPM_AUTH_TOKEN" https://registry.npmjs.org/-/npm/v1/user)
47-
if [ "$NPM_RESULT" = "200" ]; then
48-
echo "✓ npm token is valid"
49-
else
50-
echo "::error::npm token is invalid or expired (HTTP $NPM_RESULT). Update NPM_AUTH_TOKEN in repo secrets."
51-
FAILED=true
52-
fi
46+
NPM_RESPONSE=$(curl -s -H "Authorization: Bearer $NPM_AUTH_TOKEN" https://registry.npmjs.org/-/npm/v1/tokens)
47+
NPM_RESULT=$(echo "$NPM_RESPONSE" | node -e "try{const d=JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));const t=d.objects?.find(o=>o.token&&o.token.startsWith(process.env.NPM_AUTH_TOKEN.slice(0,8)));if(!t){console.log('NOT_FOUND')}else if(new Date(t.expiry)<new Date()){console.log('EXPIRED:'+t.expiry)}else{console.log('OK:'+t.expiry+':'+t.scopes?.map(s=>s.name).join(','))}}catch{console.log('ERROR')}" 2>/dev/null)
48+
case "$NPM_RESULT" in
49+
OK:*)
50+
EXPIRY=$(echo "$NPM_RESULT" | cut -d: -f2-3)
51+
SCOPES=$(echo "$NPM_RESULT" | cut -d: -f4)
52+
echo "✓ npm token is valid (expires: $EXPIRY, scopes: $SCOPES)"
53+
;;
54+
EXPIRED:*)
55+
echo "::error::npm token expired on ${NPM_RESULT#EXPIRED:}. Update NPM_AUTH_TOKEN in repo secrets."
56+
FAILED=true
57+
;;
58+
*)
59+
echo "::error::npm token is invalid or could not be verified. Update NPM_AUTH_TOKEN in repo secrets."
60+
FAILED=true
61+
;;
62+
esac
5363
5464
# Check Homebrew tap token
5565
echo "Checking Homebrew tap token..."

0 commit comments

Comments
 (0)