Skip to content
Open
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
12 changes: 12 additions & 0 deletions .changeset/angry-crews-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@growi/sdk-typescript": patch
---

Add authorization header override functionality

- Add `authorizationHeader` option to `AxiosInstanceManager.addAxiosInstance()`
- Allow custom authorization headers instead of default Bearer token authentication
- When `authorizationHeader` is specified, GROWI access token is sent via `X-GROWI-ACCESS-TOKEN` header
- Support for Digest authentication, Basic authentication, and custom proxy authentication
- Add detailed usage examples and documentation to README
- Add comprehensive test cases covering error handling and edge cases
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ axiosInstanceManager.addAxiosInstance({
baseURL: 'https://your-growi-instance-2.com',
token: 'your-api-token-2',
})

// Example with Digest authentication when GROWI is behind Digest auth protection
axiosInstanceManager.addAxiosInstance({
name: 'app-3',
baseURL: 'https://your-growi-instance-3.com',
token: 'your-growi-access-token',
authorizationHeader: 'Digest username="user", realm="Protected Area", nonce="abc123", uri="/", response="xyz789"', // Digest auth header
})
```

### API v3 Usage Example
Expand Down Expand Up @@ -127,6 +135,49 @@ src/
- **API v3**: Contains new features and improved API endpoints. We recommend using v3 whenever possible.
- **API v1**: Use when you need features not available in v3 or for legacy compatibility.

### Authentication Header Override

The SDK now supports overriding the default Bearer token authorization method. When the `authorizationHeader` option is provided:

- The `Authorization` header will be set to the provided custom value
- The GROWI access token will be sent via the `X-GROWI-ACCESS-TOKEN` header

This feature is particularly useful when GROWI is behind authentication systems such as Digest authentication, Basic authentication, or custom proxy authentication that require specific authorization header formats.

**Default behavior (Bearer token):**
```typescript
axiosInstanceManager.addAxiosInstance({
name: 'default-auth',
baseURL: 'https://growi.example.com',
token: 'your-growi-api-token',
// Authorization header will be: "Bearer your-growi-api-token"
});
```

**Digest authentication example:**
```typescript
axiosInstanceManager.addAxiosInstance({
name: 'digest-auth',
baseURL: 'https://growi.example.com',
token: 'growi-api-token',
authorizationHeader: 'Digest username="admin", realm="GROWI Protected", nonce="abc123def456", uri="/", response="calculated-response-hash"',
// Authorization header will be set to the Digest auth string
// X-GROWI-ACCESS-TOKEN header will be: "growi-api-token"
});
```

**Basic authentication example:**
```typescript
axiosInstanceManager.addAxiosInstance({
name: 'basic-auth',
baseURL: 'https://growi.example.com',
token: 'growi-api-token',
authorizationHeader: 'Basic ' + btoa('username:password'),
// Authorization header will be: "Basic base64-encoded-credentials"
// X-GROWI-ACCESS-TOKEN header will be: "growi-api-token"
});
```

## Type Definition

All API requests and responses are type-safe:
Expand Down
51 changes: 51 additions & 0 deletions README_JP.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ axiosInstanceManager.addAxiosInstance({
baseURL: 'https://your-growi-instance-2.com',
token: 'your-api-token-2',
})

// GROWIがDigest認証で保護されている場合の例
axiosInstanceManager.addAxiosInstance({
name: 'app-3',
baseURL: 'https://your-growi-instance-3.com',
token: 'your-growi-access-token',
authorizationHeader: 'Digest username="user", realm="Protected Area", nonce="abc123", uri="/", response="xyz789"', // Digest認証ヘッダー
})
```

### API v3 の使用例
Expand Down Expand Up @@ -127,6 +135,49 @@ src/
- **API v3**: 新機能や改良された API エンドポイントが含まれています。可能な限り v3 の使用を推奨します。
- **API v1**: v3 で提供されていない機能や、レガシー対応が必要な場合に使用してください。

### 認証ヘッダーの上書き

SDK は、デフォルトの Bearer トークン認証方法を上書きする機能をサポートしています。`authorizationHeader` オプションが提供された場合:

- `Authorization` ヘッダーは提供されたカスタム値に設定されます
- GROWI アクセストークンは `X-GROWI-ACCESS-TOKEN` ヘッダー経由で送信されます

この機能は、特に GROWI が Digest認証、Basic認証、またはカスタムプロキシ認証などの認証システムの背後にある場合に、特定の認証ヘッダー形式が必要な時に便利です。

**デフォルトの動作(Bearer トークン):**
```typescript
axiosInstanceManager.addAxiosInstance({
name: 'default-auth',
baseURL: 'https://growi.example.com',
token: 'your-growi-api-token',
// Authorization ヘッダーは: "Bearer your-growi-api-token" に設定されます
});
```

**Digest認証の例:**
```typescript
axiosInstanceManager.addAxiosInstance({
name: 'digest-auth',
baseURL: 'https://growi.example.com',
token: 'growi-api-token',
authorizationHeader: 'Digest username="admin", realm="GROWI Protected", nonce="abc123def456", uri="/", response="calculated-response-hash"',
// Authorization ヘッダーは Digest認証文字列に設定されます
// X-GROWI-ACCESS-TOKEN ヘッダーは: "growi-api-token" に設定されます
});
```

**Basic認証の例:**
```typescript
axiosInstanceManager.addAxiosInstance({
name: 'basic-auth',
baseURL: 'https://growi.example.com',
token: 'growi-api-token',
authorizationHeader: 'Basic ' + btoa('username:password'),
// Authorization ヘッダーは: "Basic base64エンコードされた認証情報" に設定されます
// X-GROWI-ACCESS-TOKEN ヘッダーは: "growi-api-token" に設定されます
});
```

## 型定義

すべての API リクエスト・レスポンスは型安全です:
Expand Down
Loading