agentleFS
jocarrdjocarrd/crux-agents/skills/oauth-reauthorize/SKILL.md

oauth-reauthorize

Skill4 starsChanged 19 days agoMITView on GitHub

Regenerate the refresh_token of an OAuth integration when the flow has been invalidated, bringing up an ephemeral local server that captures the callback code and saving the tokens with restrictive permissions. Use when an integration starts failing with invalid_grant on refresh, after manually revoking permissions, or when setting up a new machine where the token is missing.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After revoking access manually.

    line 16
  2. Very specific:

    Don't accept the flow just because the script says OK: make a real query against the API with the freshly obtained access_token.

    line 43
  3. Distinctive:

    If the project needs to renew them periodically, that lives in a separate script, not here.

    line 68

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

oauth-reauthorize

Redoes from scratch the OAuth flow of a desktop integration.

When to use

  • An integration returns invalid_grant on refresh. The usual symptom is that the provider expired the grant from lack of use, or someone revoked the permissions by hand.
  • A new machine where the client file is already there but the token is missing.
  • After revoking access manually.

Preconditions

  • A client.json of desktop type in the integration's configuration directory. The type matters, see the gotchas.
  • The account you are going to authorize with actually has access to the resource.
  • The loopback port you are going to use, free.

Usage

python3 <this-skill-directory>/scripts/oauth-authorize.py \
  --dir ~/.config/<service> \
  --scope "<scope>"

Optionally --port, and --auth-url/--token-url if the provider is not Google.

The script prints the consent URL and opens the browser. After accepting, the provider redirects to 127.0.0.1, the ephemeral server captures the code, exchanges it for tokens and writes them with 600 permissions.

Verify

Don't accept the flow just because the script says OK: make a real query against the API with the freshly obtained access_token. A token that is written but authorizes nothing is the easiest failure to overlook, and it appears when the requested scope is not the one the API needs.

Gotchas

  • The response doesn't include refresh_token. It happens when the provider reuses a previous grant. The script already requests explicit consent and offline access to force a new one, but the safety net is to revoke access by hand on the account's permissions page and repeat.
  • redirect_uri_mismatch. The OAuth client has to be of desktop type: those accept any port under loopback by default. Web-type ones require registering the exact URI.
  • The out-of-band flow is dead. The urn:ietf:wg:oauth:2.0:oob that appears in old tutorials has been deprecated for years. Always loopback.
  • Don't use privileged ports for the callback: they require root with no advantage.
  • A service account doesn't replace this unless it has explicit permission on the resource. A service-account credentials file existing in the directory doesn't mean it works; many integrations only support user OAuth.

Afterwards

The tokens are secrets: they stay with 600 permissions and are not committed. If the project needs to renew them periodically, that lives in a separate script, not here.

Related

  • The project's operational documentation, for the concrete scopes and resource of each integration

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.