Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions openespi-authserver/DEPLOYMENT_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,7 @@ espi:

These admin REST APIs accept a client_credentials bearer token:

- `/admin/**`
- `/api/v1/oauth2/clients/**`
- `/admin/**` (including the client API, `/admin/oauth2/clients`, #344)
- `/api/v1/certificates/**`
- `/api/v1/datacustodian/**`

Expand Down Expand Up @@ -740,7 +739,7 @@ A browser session reaches the admin paths only if it has **all** of the followin
- the password factor (form login at `/login`)
- the passkey factor (WebAuthn)

The admin paths are `/admin/**`, `/api/v1/admin/**`, `/api/v1/oauth2/clients/**`, `/api/v1/certificates/**`, `/api/v1/datacustodian/**` and `/connect/**`.
The admin paths are `/admin/**` (the client API is `/admin/oauth2/clients`, #344), `/api/v1/admin/**`, `/api/v1/certificates/**`, `/api/v1/datacustodian/**` and `/connect/**`.

The MFA requirement applies to these paths only. The OAuth2 protocol endpoints, the delegated customer flow, introspection and the `espi_admin` bearer chain are unaffected.

Expand Down
2 changes: 1 addition & 1 deletion openespi-authserver/QUICK_START.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ curl -X POST http://localhost:8080/oauth2/token \
```bash
# Get client list
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8080/api/v1/oauth2/clients
http://localhost:8080/admin/oauth2/clients

# Check user info
curl -H "Authorization: Bearer YOUR_TOKEN" \
Expand Down
13 changes: 8 additions & 5 deletions openespi-authserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ This module provides OAuth2 Authorization Server capabilities as part of the Ope
│ • /oauth2/register (RFC 7591 client registration)│
│ │
│ Admin Endpoints: │
│ • /admin/oauth2/tokens (Token management) │
│ • /admin/oauth2/tokens (Token revocation) │
│ • /admin/oauth2/clients (Client management) │
│ • /admin/oauth2/authorizations (Authorization management) │
├─────────────────────────────────────────────────────────────┤
│ ESPI Components: │
│ • EspiTokenCustomizer (JWT token enhancement) │
Expand Down Expand Up @@ -312,13 +311,17 @@ scope=DataCustodian_Admin_Access

### Administrative APIs

- `GET /admin/oauth2/tokens` - List active tokens
- `DELETE /admin/oauth2/tokens/{tokenId}` - Revoke token
- `GET /admin/oauth2/clients` - List registered clients
- `GET /admin/oauth2/clients` - List registered clients (paged, filtered)
- `POST /admin/oauth2/clients` - Create a client
- `GET /admin/oauth2/clients/{clientId}` - Get specific client
- `PUT /admin/oauth2/clients/{clientId}` - Update a client
- `PUT /admin/oauth2/clients/{clientId}/status` - Suspend, revoke or reactivate a client
- `DELETE /admin/oauth2/clients/{clientId}` - Delete client
- `DELETE /admin/oauth2/clients/{clientId}/tokens` - Revoke all client tokens
- `GET /admin/oauth2/authorizations` - List authorizations

The client API is one controller since #344 (it was `/api/v1/oauth2/clients`); see
[docs/OAUTH2_CLIENT_MANAGEMENT_API.md](docs/OAUTH2_CLIENT_MANAGEMENT_API.md).

## Dynamic Client Registration

Expand Down
2 changes: 0 additions & 2 deletions openespi-authserver/docker/config/application-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ espi:
client-management:
default-rate-limit-per-minute: 100
default-max-concurrent-sessions: 5
max-failures-before-lock: 10
default-lock-duration-minutes: 60
enable-automatic-cleanup: true
enable-security-monitoring: true

Expand Down
23 changes: 12 additions & 11 deletions openespi-authserver/docs/API_DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ User-Agent: YourApp/1.0

## OAuth2 Client Management API

### Base Path: `/api/v1/oauth2/clients`
### Base Path: `/admin/oauth2/clients`

#### 1. List OAuth2 Clients

**Endpoint**: `GET /api/v1/oauth2/clients`
**Endpoint**: `GET /admin/oauth2/clients`

**Description**: Retrieve a paginated list of registered OAuth2 clients

Expand All @@ -58,7 +58,7 @@ User-Agent: YourApp/1.0

**Request Example**:
```http
GET /api/v1/oauth2/clients?page=0&size=10&sort=clientName&direction=ASC&espiCompliant=true
GET /admin/oauth2/clients?page=0&size=10&sort=clientName&direction=ASC&espiCompliant=true
Authorization: Bearer eyJhbGciOiJSUzI1NiIs...
Accept: application/json
```
Expand Down Expand Up @@ -111,7 +111,7 @@ Accept: application/json

#### 2. Get Client by ID

**Endpoint**: `GET /api/v1/oauth2/clients/{clientId}`
**Endpoint**: `GET /admin/oauth2/clients/{clientId}`

**Description**: Retrieve a specific OAuth2 client by ID

Expand All @@ -120,7 +120,7 @@ Accept: application/json

**Request Example**:
```http
GET /api/v1/oauth2/clients/espi-third-party-001
GET /admin/oauth2/clients/espi-third-party-001
Authorization: Bearer eyJhbGciOiJSUzI1NiIs...
Accept: application/json
```
Expand Down Expand Up @@ -158,7 +158,7 @@ Accept: application/json

#### 3. Create New Client

**Endpoint**: `POST /api/v1/oauth2/clients`
**Endpoint**: `POST /admin/oauth2/clients`

**Description**: Register a new OAuth2 client

Expand Down Expand Up @@ -203,7 +203,7 @@ only method is `none` is public: it gets no `client_secret`, always requires PKC

#### 4. Update Client

**Endpoint**: `PUT /api/v1/oauth2/clients/{clientId}`
**Endpoint**: `PUT /admin/oauth2/clients/{clientId}`

**Description**: Update an existing OAuth2 client

Expand All @@ -226,7 +226,7 @@ methods and grant types cannot be changed here: a request naming them, or any ot

#### 5. Delete Client

**Endpoint**: `DELETE /admin/oauth2/clients/{clientId}` (the client management API has no delete of its own)
**Endpoint**: `DELETE /admin/oauth2/clients/{clientId}`

**Description**: Permanently deletes an OAuth2 client, with its consents, its authorizations (so every token
issued to it stops working at once), its ESPI application information, consent details and metrics. It cannot be
Expand All @@ -245,7 +245,8 @@ authorizations deleted. A client that does not exist, or was deleted meanwhile,
}
```

The earlier `POST /api/v1/oauth2/clients/bulk` was removed (#344).
The earlier `POST /api/v1/oauth2/clients/bulk` was removed (#344). The client API itself moved from
`/api/v1/oauth2/clients` to `/admin/oauth2/clients` (#344).

## DataCustodian Integration API

Expand Down Expand Up @@ -625,7 +626,7 @@ token=eyJhbGciOiJSUzI1NiIs...&token_type_hint=access_token
"error_description": "Human-readable error description",
"error_uri": "https://docs.greenbuttonalliance.org/errors/error_code",
"timestamp": "2024-01-16T15:30:00Z",
"path": "/api/v1/oauth2/clients",
"path": "/admin/oauth2/clients",
"correlationId": "abc-123-def-456"
}
```
Expand Down Expand Up @@ -675,7 +676,7 @@ token=eyJhbGciOiJSUzI1NiIs...&token_type_hint=access_token
"error": "validation_error",
"error_description": "Request validation failed",
"timestamp": "2024-01-16T15:30:00Z",
"path": "/api/v1/oauth2/clients",
"path": "/admin/oauth2/clients",
"correlationId": "abc-123-def-456",
"details": [
{
Expand Down
2 changes: 1 addition & 1 deletion openespi-authserver/docs/ESPI_COMPLIANCE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ server:

#### Client Registration for Certificate Auth

Not yet available. The Client Management API (`POST /api/v1/oauth2/clients`) accepts only `client_secret_basic`,
Not yet available. The Client Management API (`POST /admin/oauth2/clients`) accepts only `client_secret_basic`,
`client_secret_post` and `none` as `authentication_methods`: `tls_client_auth` needs the client's certificate
subject DN in its settings, which the API does not take, so a request for it is refused with 400
`invalid_request` (#332).
Expand Down
2 changes: 1 addition & 1 deletion openespi-authserver/docs/INTEGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ with 400 `invalid_request`.
Use the Client Management API for programmatic registration:

```http
POST /api/v1/oauth2/clients
POST /admin/oauth2/clients
Authorization: Bearer your-admin-token
Content-Type: application/json

Expand Down
74 changes: 57 additions & 17 deletions openespi-authserver/docs/OAUTH2_CLIENT_MANAGEMENT_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

The OAuth2 Client Management API provides comprehensive CRUD operations for managing OAuth2 clients in the ESPI 4.0 Authorization Server. This API is designed for enterprise-grade deployments with support for bulk operations and NAESB ESPI 4.0 compliance.
The OAuth2 Client Management API provides comprehensive CRUD operations for managing OAuth2 clients in the ESPI 4.0 Authorization Server. It also records the NAESB ESPI 4.0 data the Authorization Server keeps about each client.

## Authentication

Expand All @@ -11,30 +11,32 @@ All endpoints require `ROLE_ADMIN` or `ROLE_DC_ADMIN` authority.
## Base URL

```
/api/v1/oauth2/clients
/admin/oauth2/clients
```

This is the Authorization Server's one admin client API (#344). It was `/api/v1/oauth2/clients` until #344 part 3, and the client delete was `OAuthAdminController`'s; both are here now. Review date: if no operator tool or admin portal uses this API by 2027-06-30, it is deprecated and retired.

## Endpoints

### 1. List Clients

Retrieve a paginated list of OAuth2 clients with filtering and sorting capabilities.

**Endpoint:** `GET /api/v1/oauth2/clients`
**Endpoint:** `GET /admin/oauth2/clients`

**Parameters:**
- `page` (optional): Page number (default: 0)
- `size` (optional): Page size (default: 20, max: 100)
- `sortBy` (optional): Sort field - client_id, client_name, client_id_issued_at or last_used_at (default: client_id); any other value is 400
- `sortDirection` (optional): Sort direction - asc/desc (default: asc); any other value is 400
- `status` (optional): Filter by the status in force - active/suspended/revoked (see Update Client Status); any other value is 400
- `securityLevel` (optional): Filter by security level - standard/high/maximum
- `securityLevel` (optional): Filter by security level - standard/high/maximum; any other value is 400
- `espiVersion` (optional): Filter by ESPI version
- `search` (optional): Text the client name or client ID contains; `%` and `_` match only themselves

**Example Request:**
```http
GET /api/v1/oauth2/clients?page=0&size=10&status=active&search=utility
GET /admin/oauth2/clients?page=0&size=10&status=active&search=utility
Authorization: Bearer <access_token>
```

Expand All @@ -57,7 +59,6 @@ Authorization: Bearer <access_token>
"max_concurrent_sessions": 50,
"created_by": "migration_v3_0_0",
"last_used_at": "2024-01-15T10:30:00Z",
"failure_count": 0,
"business_category": "Electric Utility",
"certification_status": "self_certified",
"service_territory": "State of California"
Expand All @@ -74,7 +75,7 @@ Authorization: Bearer <access_token>

Create a new OAuth2 client with ESPI 4.0 compliance features.

**Endpoint:** `POST /api/v1/oauth2/clients`
**Endpoint:** `POST /admin/oauth2/clients`

**Request Body:**
```json
Expand Down Expand Up @@ -136,7 +137,7 @@ milliseconds (13 digits), `_` and 8 hex digits. ESPI's `client_id` has at most 6

Retrieve detailed information about a specific client.

**Endpoint:** `GET /api/v1/oauth2/clients/{clientId}`
**Endpoint:** `GET /admin/oauth2/clients/{clientId}`

**Example Response:**
```json
Expand All @@ -162,7 +163,6 @@ Retrieve detailed information about a specific client.
"max_concurrent_sessions": 10,
"created_by": "admin_user",
"last_used_at": "2024-01-15T11:45:00Z",
"failure_count": 0,
"business_category": "Energy Data Platform",
"certification_status": "gba_certified",
"service_territory": "North America"
Expand All @@ -173,7 +173,7 @@ Retrieve detailed information about a specific client.

Update an existing client's configuration.

**Endpoint:** `PUT /api/v1/oauth2/clients/{clientId}`
**Endpoint:** `PUT /admin/oauth2/clients/{clientId}`

**Request Body:**
```json
Expand Down Expand Up @@ -210,7 +210,7 @@ refused with 400 `invalid_request` (#332).

Update a client's status (activate, suspend, revoke).

**Endpoint:** `PUT /api/v1/oauth2/clients/{clientId}/status`
**Endpoint:** `PUT /admin/oauth2/clients/{clientId}/status`

**Request Body:**
```json
Expand Down Expand Up @@ -239,8 +239,8 @@ holds the status asked for, `lock_duration_minutes` and the resulting `locked_un
**A lock only ever restricts.** In the database, `client_status` is what only a status change ends, and
`locked_until` is a lock that ends on its own: it suspends an `active` client while it runs and never ends a stored
`suspended` or `revoked`. So a suspension with `lock_duration_minutes` is stored as `client_status = 'active'` with
`locked_until` set, and a suspension without it as `suspended` with no lock. Anything else that sets a lock, such as
a failure lockout (#353), may only extend one, never shorten it. A status change is the administrator's act and
`locked_until` set, and a suspension without it as `suspended` with no lock. There is no failure lockout (#353);
anything added later that sets a lock may only extend one, never shorten it. A status change is the administrator's act and
replaces the client's earlier state, whatever it was: a timed suspension of a `revoked` client ends when its lock
does, as setting the client `active` would end the revocation at once.

Expand All @@ -267,8 +267,9 @@ means no filter; any other value, including a blank one, is 400 `invalid_request
- **`active`** again, or the end of a timed suspension: the client works again at once, and its unexpired tokens
introspect as active again.

While they last, `revoked` and `suspended` act the same. To end a client's tokens for good, delete the client
(`DELETE /admin/oauth2/clients/{clientId}`, which deletes its authorizations).
While they last, `revoked` and `suspended` act the same. To end a client's tokens for good, revoke them
(`DELETE /admin/oauth2/clients/{clientId}/tokens`) or delete the client (`DELETE /admin/oauth2/clients/{clientId}`);
both delete its authorizations.

An unknown client
is 404 whatever the body holds, as long as it is JSON of the right shape; the body's values are checked after the
Expand All @@ -277,6 +278,47 @@ the client and kept in the audit record's data, and without it the client record

The earlier `POST /api/v1/oauth2/clients/bulk` was removed (#344): change clients one at a time.

### 6. Revoke a Client's Tokens

Delete all of the client's authorizations, so that none of its access or refresh tokens works any longer and the
Data Custodian's introspection reports them inactive (#349). The client stays registered and can be authorized again.

**Endpoint:** `DELETE /admin/oauth2/clients/{clientId}/tokens`

**Response:**
```json
{
"status": "revoked",
"client_id": "utility_admin_portal",
"authorizations_deleted": 3
}
```

An unknown client, or one deleted meanwhile, is 404. The revocation is audited (`client_tokens_revoked`) under the
signed-in administrator, with the number of authorizations deleted.

### 7. Delete Client

Delete the client with its authorizations, consents and ESPI application info.

**Endpoint:** `DELETE /admin/oauth2/clients/{clientId}`

**Response:**
```json
{
"status": "deleted",
"client_id": "utility_admin_portal",
"authorizations_deleted": 3
}
```

An unknown client, or one deleted meanwhile, is 404. The delete is audited (`client_deleted`) under the signed-in
administrator, with the number of authorizations deleted.

An update, a status change, a token revocation and a delete of the same client never interleave: each locks the
client's row, so one that finds the client deleted meanwhile is 404, and an update never brings a deleted client
back (#348).

## ESPI 4.0 Compliance Features

### Security Levels
Expand Down Expand Up @@ -372,8 +414,6 @@ espi:
client-management:
default-rate-limit-per-minute: 100
default-max-concurrent-sessions: 5
max-failures-before-lock: 10
default-lock-duration-minutes: 60
enable-automatic-cleanup: true
enable-security-monitoring: true
```
Expand Down
2 changes: 1 addition & 1 deletion openespi-authserver/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ graph TB
| Endpoint Category | Base Path | Purpose |
|------------------|-----------|---------|
| **OAuth2 Standard** | `/oauth2/*` | Standard OAuth2 endpoints |
| **Client Management** | `/api/v1/oauth2/clients` | OAuth2 client registration and management |
| **Client Management** | `/admin/oauth2/clients` | OAuth2 client registration and management |
| **DataCustodian Integration** | `/api/v1/datacustodian` | Integration with OpenESPI DataCustodian |
| **OIDC UserInfo** | `/userinfo` | OpenID Connect user information with ESPI claims |

Expand Down
Loading