OAuth 2.0 is the appropriate authentication method when third-party applications need delegated access on behalf of a resource owner, or when client credentials-based machine-to-machine access is required.
Supported Grant Types #
| Grant Type | Use Case |
|---|---|
| Authorization Code (with PKCE) | Web applications and mobile apps acting on behalf of a user |
| Client Credentials | Machine-to-machine access without a user context |
| Refresh Token | Renewing an expired access token |
Note: PKCE (Proof Key for Code Exchange) is required for the Authorization Code flow. Only code_challenge_method: S256 is supported.
Registering an OAuth Client #
Before using OAuth, register your application:
- Navigate to DDLS > Developer > OAuth Clients.
- Click Add New Client.
- Provide the application name and redirect URI(s).
- Save. You will receive a
client_idandclient_secret.
Token Lifetimes #
| Token | TTL |
|---|---|
| Access token | 3600 seconds (1 hour) |
| Refresh token | 30 days |
OAuth Endpoints #
| Endpoint | Method | Description |
|---|---|---|
/wp-json/dmsi-api/v1/oauth/authorize | GET, POST | Authorization endpoint — user consent screen |
/wp-json/dmsi-api/v1/oauth/token | POST | Token endpoint (code exchange, client credentials, refresh) |
/wp-json/dmsi-api/v1/oauth/revoke | POST | Revoke an access or refresh token |
Authorization Code Flow (with PKCE) #
- Generate a
code_verifier(random string, 43-128 chars) and derivecode_challenge = BASE64URL(SHA256(code_verifier)). - Redirect the user to the authorization endpoint:
GET /wp-json/dmsi-api/v1/oauth/authorize
?response_type=code
&client_id=<your-client-id>
&redirect_uri=<your-redirect-uri>
&scope=licenses:read
&state=<random-state>
&code_challenge=<code-challenge>
&code_challenge_method=S256
- After user consent, the authorization server redirects to your
redirect_uriwith acodeparameter. - Exchange the code for tokens:
curl -X POST https://yoursite.com/wp-json/dmsi-api/v1/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "code=<authorization-code>" \
-d "redirect_uri=<your-redirect-uri>" \
-d "client_id=<your-client-id>" \
-d "code_verifier=<code-verifier>"
Client Credentials Flow #
curl -X POST https://yoursite.com/wp-json/dmsi-api/v1/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-u "<client-id>:<client-secret>" \
-d "grant_type=client_credentials" \
-d "scope=licenses:read products:read"
