daraja-auth SKILL.md skillA
daraja-auth from mr-macharia/mpesa-daraja-skills-and-mcp is an agent skill: a SKILL.md folder an AI agent loads when a task calls for it.
mdr add mr-macharia/mpesa-daraja-skills-and-mcp/daraja-auth@git:20261021.84f51bcPins git:20261021.84f51bc in mdr.lock. Pin the fingerprint instead.
- Audit grade
- A, 17 of 17 checks passed
- Kind
- SKILL.md skill
- Repository
- mr-macharia/mpesa-daraja-skills-and-mcp
- Path
skills/daraja-auth/SKILL.md- Versions recorded
- 4
- Latest version
- git:20261021.84f51bc, committed Oct 21, 2026
- First version recorded
- Oct 19, 2026
- Size
- 4,237 bytes
- Repository stars
- 3
- License
- MIT
Generates, caches and refreshes Safaricom Daraja OAuth 2.0 access tokens from the Consumer Key and Secret (client-credentials grant with HTTP Basic auth), including single-flight refresh, 401 retry and multi-instance caching. Use when writing the token helper for any M-Pesa API, or when debugging 400.008.xx, 401 or 404.001.03 "Invalid Access Token" errors.
Collected from public GitHub. Every version is saved exactly as it was and never changes. Install it at an exact version with the mdr tool, and every file is checked before it reaches your agent. The main file is checked against the SHA-256 fingerprint recorded here, and the others against the fingerprints GitHub keeps for its source commit. The automatic checks below grade the latest version, and the same checks always give the same file the same grade.
What the file says
# Daraja Authentication
## Mechanism
```
GET {BASE}/oauth/v1/generate?grant_type=client_credentials
Authorization: Basic base64(CONSUMER_KEY + ":" + CONSUMER_SECRET)
200 → {"access_token": "c9SQxWWhmdVRlyh0zh8gZDTkubVF", "expires_in": "3599"}
```
- `expires_in` is a **string** of seconds, about one hour.
- Product calls send `Authorization: Bearer <access_token>` and are POST. Only the token call is GET.
- Basic auth is acceptable because the channel is TLS. Never log the header or the token.
Quick check of your credentials (stdlib only; it never prints the token):
```bash
DARAJA_CONSUMER_KEY=... DARAJA_CONSUMER_SECRET=... DARAJA_ENV=sandbox python scripts/check_token.py
```
## Reference implementation (Python)
```python
import base64, os, threading, time, requests
BASE_URL = os.environ.get("DARAJA_BASE_URL", "https://sandbox.safaricom.co.ke")
KEY = os.environ["DARAJA_CONSUMER_KEY"].strip() # KeyError = fail fast at startup
SECRET = os.environ["DARAJA_CONSUMER_SECRET"].strip()
SAFETY_MARGIN_S = 60 # refresh before expiry so in-flight calls never carry a dead token
_lock = threading.Lock()
_token, _expires_at = None, 0.0
…Read the whole file at its exact version.
How to install
mdr add mr-macharia/mpesa-daraja-skills-and-mcp/daraja-auth@sha256:656f9acfac674f33The line at the top of this page pins the label git:20261021.84f51bc, which is what most people want. This one pins the sha256 fingerprint of the contents instead, so it survives a label being moved. Either way the exact version is written to mdr.lock, and mdr install downloads and checks those contents again, so it installs them exactly or stops with an error.
[](https://markdownregistry.com/a/art_ljprqulotnnrbusv)
1 badge image fetches in 30 days. What the badge shows.
Versions
The registry has recorded 4 versions of this file, between Oct 19, 2026 and Oct 21, 2026, more than one a day.
| version | committed | commit | size | audit | |
|---|---|---|---|---|---|
| git:20261021.84f51bc latest | 2026-10-21 | 84f51bc | 4,237 B | A | view · diff |
| git:20261020.f2e8fad | 2026-10-20 | f2e8fad | 4,231 B | A | view · diff |
| git:20261019.9e3c915 | 2026-10-19 | 9e3c915 | 4,237 B | A | view · diff |
| git:20261019.15b8109 | 2026-10-19 | 15b8109 | 4,075 B | A | view |
Audit of the latest version
- pass: Frontmatter block present
- pass: Frontmatter declares a name
- pass: Frontmatter declares a description
- pass: Size between 200 bytes and 200 KB (4237 bytes)
- pass: No zero-width or bidi control characters
- pass: No instruction hidden inside an HTML comment
- pass: No link to an exfiltration or paste host
- pass: No credential-shaped string
- pass: No instruction to send local credentials anywhere
- pass: No text hidden with inline styles
- pass: No prompt-injection phrasing
- pass: No curl or wget piped into a shell
- pass: No recursive delete of root, home or parent
- pass: No instruction to read or print local credentials
- pass: No base64 blob over 200 characters
- pass: No link to a raw IP address
- pass: No script tag
Source
mr-macharia/mpesa-daraja-skills-and-mcp · 3 stars · license MIT · pushed 2026-11-03 · branch main
API
GET https://markdownregistry.com/api/v1/artifacts/art_ljprqulotnnrbusv GET https://markdownregistry.com/api/v1/resolve?ref=mr-macharia/mpesa-daraja-skills-and-mcp/daraja-auth GET https://markdownregistry.com/api/v1/blob/656f9acfac674f334e44403deb31bb28bf4ea16b39b261706ae02e7f354e3830
Your AI assistant does the legwork. You hear about the deals worth your word. Hand yours the standing instructions at modelranch.com and it joins the network that reads files like this one.
Guides: the SKILL.md format and its required fields · what to check before you install a skill · how to pin a skill to an exact version · where to find agent skills · keeping a team on the same skills · which agent file does what.