Auth Grants and API Tokens
Overview
AuthGrants are a secure permission system that allows third-party applications to access the LearnCard Network API with specific, limited permissions. This documentation explains how to create and manage AuthGrants, generate API tokens, and use them to make authenticated API requests.
Understanding AuthGrants
What is an AuthGrant?
An AuthGrant is a permission object that:
Defines specific access rights (scopes) granted to a client application
Has a defined lifecycle (creation, active period, expiration, revocation)
Includes metadata such as name, description, and status
Serves as the basis for generating API tokens for authentication
Scope System
AuthGrants use a scope-based permission model following the pattern: {resource}:{action}
Resources:
boosts
claimHook
profile
profileManager
credential
presentation
storage
utilities
contracts
didMetadata
authGrants
Actions:
read
: Permission to view resourceswrite
: Permission to create or update resourcesdelete
: Permission to remove resources
Special Patterns:
All access:
*:*
Read all:
*:read
Resource-wide:
authGrants:*
Multiple scopes: Space-separated list (e.g.,
"authGrants:read contracts:write"
)
Common Scope Bundles:
Creating an AuthGrant
Use the LearnCard SDK's addAuthGrant
method to create a new AuthGrant:
AuthGrant Properties
id
: Unique identifier (auto-generated if not provided)name
: Name of the AuthGrantdescription
: (Optional) Description of the purpose or use casechallenge
: Security challenge string (must start with AuthGrant prefix)status
: Either 'active' or 'revoked'scope
: Permission scope stringcreatedAt
: ISO 8601 datetime string of creation (auto-generated if not provided)expiresAt
: (Optional) ISO 8601 datetime string for expiration
Generating an API Token
Once you have an AuthGrant, you can generate an API token using the getAPITokenForAuthGrant
method:
This token encapsulates the permissions defined in the AuthGrant and should be used for authentication in API requests.
Using the API Token for HTTP Requests
Use the generated API token in the Authorization header with the Bearer scheme:
Complete End-to-End Example
Here's a complete example showing how to:
Create an AuthGrant
Generate an API token
Use the token to send a boost via the HTTP API
Managing AuthGrants
Retrieving AuthGrants
Updating AuthGrants
Revoking AuthGrants
Security Considerations
Store API tokens securely; they grant access according to the AuthGrant's scope
Use the principle of least privilege: request only the scopes needed for your application
Set appropriate expiration times for AuthGrants when creating them
Revoke AuthGrants when they are no longer needed
Last updated
Was this helpful?