From 451e8912161721f911446e96ca5c434b9085a330 Mon Sep 17 00:00:00 2001 From: Simon Uhegbu Date: Tue, 20 Jan 2026 13:42:29 +0000 Subject: [PATCH] Update api-key.mdx --- src/content/accounts-and-teams/api-key.mdx | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/content/accounts-and-teams/api-key.mdx b/src/content/accounts-and-teams/api-key.mdx index 508d9660..b208a653 100644 --- a/src/content/accounts-and-teams/api-key.mdx +++ b/src/content/accounts-and-teams/api-key.mdx @@ -50,7 +50,7 @@ If you wish to restrict the use of your API-Key to a specific IP address or rang One you have added your CIDR address/mask, just click the "+ Add" button to apply your restriction. -## Refreshing a Personal/User API Key +## Refreshing a Personal/User API Key from the webapp If you lose the API key associated with your account, or suspect it has been compromised, you'll need to refresh the key, generating a new one. @@ -58,4 +58,29 @@ To do this, under your profile menu, select Personal API Keys. Click the "Refresh API Key" button to generate a new API key. - \ No newline at end of file + + +## Refreshing a Personal/User API Key from the Cloudsmith CLI ## + +This script uses SSO to login, grab the API key and workspace id. Just change the ORG_NAME to the your workspace id and you should be all set. + +``` +#!/bin/bash + +ORG_NAME="cloudsmith" + +# Step 1: Authenticate +cloudsmith auth -o $ORG_NAME + +# List tokens for user and extract the slug_perm (grabbing the first for simplicity) +SLUG_PERM=$(cloudsmith tokens ls -F json | jq -r '.data[0].slug_perm') + +# Now refresh the token to get a key valid for 2 hours, then export it for use +NEW_KEY=$(cloudsmith tokens refresh $SLUG_PERM -F json | grep '^{' | jq '.data.key') + +echo "New API Key: $NEW_KEY" +export CLOUDSMITH_API_KEY=$NEW_KEY + +# Step 4: Verify we're logged in +cloudsmith whoami +```