Authentication
JWT tokens, OAuth providers, and guest access for the MatCraft API.
Authentication
The MatCraft API supports three authentication methods: JWT bearer tokens, OAuth social login, and anonymous guest access.
Guest Access
Most read-only endpoints are accessible without authentication. Guest requests are rate-limited to 100 requests per hour and cannot access builder endpoints or export features.
# No auth header needed for basic queries
curl "https://api.matcraft.ai/api/v1/materials?formula=Si"JWT Bearer Tokens
For higher rate limits and full API access, authenticate with a JWT token:
curl "https://api.matcraft.ai/api/v1/materials" \
-H "Authorization: Bearer YOUR_JWT_TOKEN"Obtaining a Token
- Sign in to MatCraft via the web UI
- Navigate to Settings > API Keys
- Click "Generate New Token"
- Copy the token (it is shown only once)
Tokens expire after 30 days by default. You can set a custom expiration when generating the token.
Token Refresh
If your token is about to expire, exchange it for a new one:
curl -X POST "https://api.matcraft.ai/api/v1/auth/refresh" \
-H "Authorization: Bearer YOUR_CURRENT_TOKEN"Response:
{
"data": {
"token": "eyJhbGciOi...",
"expires_at": "2026-05-10T00:00:00Z"
}
}OAuth Social Login
MatCraft supports sign-in via Google, GitHub, and ORCID. The OAuth flow is handled by the web UI and results in a JWT token that can be used for API access.
OAuth Flow (for custom integrations)
- Redirect users to
https://matcraft.ai/auth/{provider}where provider isgoogle,github, ororcid - After authentication, the user is redirected to your callback URL with a
codeparameter - Exchange the code for a JWT token:
curl -X POST "https://api.matcraft.ai/api/v1/auth/token" \
-H "Content-Type: application/json" \
-d '{"provider": "github", "code": "abc123", "redirect_uri": "https://yourapp.com/callback"}'Security Best Practices
- Never expose tokens in client-side code or version control
- Use environment variables to store tokens in scripts
- Rotate tokens regularly
- Use the minimum required scope for your use case
- Monitor your usage via the API dashboard to detect unauthorized access