ð ã¢ã€ãã³ãã£ãã£ãµãŒãã¹
Identity Serviceã¯ãCRUDãããã¯/ã¢ã³ããã¯ãã»ãã¥ãªãã£ç®¡çãå«ãå®å šãªã©ã€ããµã€ã¯ã«æäœã§ã¢ã€ãã³ãã£ãã£ãšã³ãã£ãã£ã管çããããã®å®å šãªREST APIãæäŸããŸããNodeblocksã®é¢æ°åã³ã³ããžã·ã§ã³ã¢ãããŒããšMongoDBçµ±åã䜿çšããŠæ§ç¯ãããŠããŸãã
ð ã¯ã€ãã¯ã¹ã¿ãŒãâ
import express from 'express';
import { middlewares, services, drivers } from '@nodeblocks/backend-sdk';
const { nodeBlocksErrorMiddleware } = middlewares;
const { identitiesService } = services;
const { withMongo } = drivers;
const connectToDatabase = withMongo('mongodb://localhost:27017', 'dev', 'user', 'password');
express()
.use(
identitiesService(
await connectToDatabase('identities'),
{
authSecrets: {
authEncSecret: 'your-encryption-secret',
authSignSecret: 'your-signing-secret',
},
identity: {
typeIds: {
admin: '100',
guest: '000',
regular: '001',
},
},
}
)
)
.use(nodeBlocksErrorMiddleware())
.listen(8089, () => console.log('Server running'));
ð ãšã³ããã€ã³ãæŠèŠâ
| Method | Path | 説æ | èªèšŒãå¿ èŠ |
|---|---|---|---|
GET | /identities/:identityId | IDã§ã¢ã€ãã³ãã£ãã£ãååŸ | â 管çè |
GET | /identities | ã¢ã€ãã³ãã£ãã£ããªã¹ã/ãã£ã«ã¿ | â 管çè |
PATCH | /identities/:identityId | ã¢ã€ãã³ãã£ãã£ãæŽæ° | â 管çè |
POST | /identities/:identityId/lock | ã»ãã¥ãªãã£ã®ããã«ã¢ã€ãã³ãã£ãã£ããã㯠| â 管çè |
POST | /identities/:identityId/unlock | ããã¯ãããã¢ã€ãã³ãã£ãã£ãã¢ã³ãã㯠| â 管çè |
DELETE | /identities/:identityId | ã¢ã€ãã³ãã£ãã£ãåé€ | â 管çè |
ðïž ãšã³ãã£ãã£ã¹ããŒãâ
ã¢ã€ãã³ãã£ãã£ãšã³ãã£ãã£ã¯ãåºæ¬ãã£ãŒã«ãïŒèªåçæïŒãšã¢ã€ãã³ãã£ãã£åºæã®ããŒã¿ãçµã¿åãããŸãïŒ
{
"id": "string",
"createdAt": "string (datetime)",
"updatedAt": "string (datetime)",
"email": "string",
"emailVerified": "boolean",
"password": "string (hashed)",
"typeId": "string",
"attempts": "number",
"locked": "boolean"
}
ãã£ãŒã«ã詳现â
| Field | Type | èªåçæ | å¿ é | 説æ |
|---|---|---|---|---|
id | string | â | â | äžæã®èå¥åïŒUUIDïŒ |
createdAt | datetime | â | â | äœæã¿ã€ã ã¹ã¿ã³ã |
updatedAt | datetime | â | â | æçµæŽæ°ã¿ã€ã ã¹ã¿ã³ã |
email | string | â | â | ãŠãŒã¶ãŒã®ã¡ãŒã«ã¢ãã¬ã¹ |
emailVerified | boolean | â | â | ã¡ãŒã«ç¢ºèªã¹ããŒã¿ã¹ |
password | string | â | â | ããã·ã¥åããããã¹ã¯ãŒãïŒbcryptïŒ |
typeId | string | â | â | ãŠãŒã¶ãŒã¿ã€ãèå¥åïŒäŸïŒç®¡çè ã®å Žåã¯"100"ïŒ |
attempts | number | â | â | ãã°ã€ã³è©Šè¡åæ° |
locked | boolean | â | â | ã¢ã«ãŠã³ãããã¯ã¹ããŒã¿ã¹ |
ð æ³šèš: èªåçæãã£ãŒã«ãã¯ãµãŒãã¹ã«ãã£ãŠèšå®ãããäœæ/æŽæ°ãªã¯ãšã¹ãã«å«ããã¹ãã§ã¯ãããŸããã
ð ã»ãã¥ãªãã£æ³šèš: ã»ãã¥ãªãã£äžã®çç±ã«ããã
passwordãã£ãŒã«ãã¯APIã¬ã¹ãã³ã¹ã§è¿ãããããšã¯ãããŸãããbcryptããã·ã¥ã䜿çšããŠããŒã¿ããŒã¹ã«å®å šã«ä¿åãããŸãããã¯ã©ã€ã¢ã³ãã«ã¬ã¹ãã³ã¹ãéä¿¡ããåã«ãã£ã«ã¿ãªã³ã°ãããŸãã
ð èªèšŒããããŒâ
ãã¹ãŠã®ãšã³ããã€ã³ãã§ã次ã®ããããŒãå«ããŠãã ããïŒ
Authorization: Bearer <access_token>
x-nb-fingerprint: <device_fingerprint>
â ïž éèŠ:
x-nb-fingerprintããããŒã¯ãèªèšŒæã«ãã£ã³ã¬ãŒããªã³ããæå®ãããå Žåããã¹ãŠã®èªèšŒæžã¿ãªã¯ãšã¹ãã§å¿ é ã§ããããããªãå Žåããªã¯ãšã¹ãã¯401 Unauthorizedãè¿ããŸãã
ð 管çè ã¢ã¯ã»ã¹ãå¿ èŠ: ãã¹ãŠã®Identity Serviceãšã³ããã€ã³ãã«ã¯ç®¡çè æš©éãå¿ èŠã§ããbearerããŒã¯ã³ã¯ç®¡çè æš©éãæã€ãŠãŒã¶ãŒã«å±ããŠããå¿ èŠããããŸãïŒããã©ã«ãã§ã¯typeId: "100"ïŒã管çè 以å€ã®ãŠãŒã¶ãŒã¯403 Forbiddenã¬ã¹ãã³ã¹ãåãåããŸãã
ð§ APIãšã³ããã€ã³ãâ
1. IDã§ã¢ã€ãã³ãã£ãã£ãååŸâ
äžæã®IDã§ç¹å®ã®ã¢ã€ãã³ãã£ãã£ãååŸããŸãã
ãªã¯ãšã¹ã:
- Method:
GET - Path:
/identities/:identityId - Headers:
Authorization: Bearer <token>x-nb-fingerprint: <device-fingerprint>
- Authorization: BearerããŒã¯ã³ãå¿ èŠïŒç®¡çè ïŒ
URLãã©ã¡ãŒã¿:
| Parameter | Type | å¿ é | 説æ |
|---|---|---|---|
identityId | string | â | äžæã®ã¢ã€ãã³ãã£ãã£èå¥å |
ã¬ã¹ãã³ã¹ããã£:
| Field | Type | 説æ |
|---|---|---|
id | string | äžæã®ã¢ã€ãã³ãã£ãã£èå¥å |
email | string | ãŠãŒã¶ãŒã®ã¡ãŒã«ã¢ãã¬ã¹ |
emailVerified | boolean | ã¡ãŒã«ç¢ºèªã¹ããŒã¿ã¹ |
typeId | string | ãŠãŒã¶ãŒã¿ã€ãèå¥å |
attempts | number | ãã°ã€ã³è©Šè¡åæ° |
locked | boolean | ã¢ã«ãŠã³ãããã¯ã¹ããŒã¿ã¹ |
createdAt | string | äœæã¿ã€ã ã¹ã¿ã³ã |
updatedAt | string | æçµæŽæ°ã¿ã€ã ã¹ã¿ã³ã |
ããªããŒã·ã§ã³:
- ã¹ããŒãããªããŒã·ã§ã³: ãªãïŒGETãªã¯ãšã¹ãïŒ
- ã«ãŒãããªããŒã¿ãŒ:
- èªèšŒæžã¿ãªã¯ãšã¹ããå¿ èŠïŒbearerããŒã¯ã³ïŒ
- 管çè ããŒã«ãå¿ èŠ
ãªã¯ãšã¹ãäŸ:
curl {{host}}/identities/811ff0a3-a26f-447b-b68a-dd83ea4000b9 \
-H "Authorization: Bearer your-access-token-here"
æåã¬ã¹ãã³ã¹:
HTTP/1.1 200 OK
Content-Type: application/json
{
"attempts": 0,
"email": "admin@example.com",
"emailVerified": true,
"locked": false,
"createdAt": "2025-07-29T07:37:01.735Z",
"id": "811ff0a3-a26f-447b-b68a-dd83ea4000b9",
"updatedAt": "2025-07-29T07:39:36.564Z",
"typeId": "100"
}
ãšã©ãŒã¬ã¹ãã³ã¹:
èªèšŒããŒã¯ã³ãæäŸãããŠããªãå Žå:
HTTP/1.1 401 Unauthorized
Content-Type: application/json
{
"error": {
"message": "token could not be verified"
}
}
æå®ãããIDã®ã¢ã€ãã³ãã£ãã£ãååšããªãå Žå:
HTTP/1.1 404 Not Found
Content-Type: application/json
{
"error": {
"message": "Identity not found"
}
}
äºæããªããšã©ãŒãçºçããå ŽåïŒããŒã¿ããŒã¹æ¥ç¶ã®åé¡ãªã©ïŒ:
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
{
"error": {
"message": "Failed to get identity"
}
}
2. ã¢ã€ãã³ãã£ãã£ã®ãªã¹ãååŸâ
ãªãã·ã§ã³ã®ãã£ã«ã¿ãªã³ã°ãšããŒãžããŒã·ã§ã³ã䜿çšããŠã¢ã€ãã³ãã£ãã£ã®ãªã¹ããååŸããŸãã
ãªã¯ãšã¹ã:
- Method:
GET - Path:
/identities - Headers:
Authorization: Bearer <token>x-nb-fingerprint: <device-fingerprint>
- Authorization: BearerããŒã¯ã³ãå¿ èŠïŒç®¡çè ïŒ
ã¯ãšãªãã©ã¡ãŒã¿:
| Parameter | Type | å¿ é | 説æ |
|---|---|---|---|
name | string | â | ååã§ã¢ã€ãã³ãã£ãã£ããã£ã«ã¿ |
page | number | â | ããŒãžçªå·ïŒ1-1000ïŒ |
limit | number | â | ããŒãžãããã®é ç®æ°ïŒ1-50ïŒ |
ã¬ã¹ãã³ã¹ããã£:
| Field | Type | 説æ |
|---|---|---|
id | string | äžæã®ã¢ã€ãã³ãã£ãã£èå¥å |
email | string | ãŠãŒã¶ãŒã®ã¡ãŒã«ã¢ãã¬ã¹ |
emailVerified | boolean | ã¡ãŒã«ç¢ºèªã¹ããŒã¿ã¹ |
typeId | string | ãŠãŒã¶ãŒã¿ã€ãèå¥å |
attempts | number | ãã°ã€ã³è©Šè¡åæ° |
locked | boolean | ã¢ã«ãŠã³ãããã¯ã¹ããŒã¿ã¹ |
createdAt | string | äœæã¿ã€ã ã¹ã¿ã³ã |
updatedAt | string | æçµæŽæ°ã¿ã€ã ã¹ã¿ã³ã |
ããªããŒã·ã§ã³:
- ã¹ããŒãããªããŒã·ã§ã³: nameïŒæååïŒãpageãlimitïŒæå°/æå€§å¶çŽä»ãæŽæ°ïŒã®ã¯ãšãªãã©ã¡ãŒã¿ããªããŒã·ã§ã³
- ã«ãŒãããªããŒã¿ãŒ:
- èªèšŒæžã¿ãªã¯ãšã¹ããå¿ èŠïŒbearerããŒã¯ã³ïŒ
- 管çè ããŒã«ãå¿ èŠ
ãªã¯ãšã¹ãäŸ:
ãã¹ãŠã®ã¢ã€ãã³ãã£ãã£ããªã¹ã:
curl {{host}}/identities \
-H "Authorization: Bearer <access-token>"
ååã§ãã£ã«ã¿:
curl "{{host}}/identities?name=admin" \
-H "Authorization: Bearer <access-token>"
ãã£ã«ã¿ãšããŒãžããŒã·ã§ã³ãçµã¿åããã:
curl "{{host}}/identities?name=admin&page=1&limit=20" \
-H "Authorization: Bearer <access-token>"
æåã¬ã¹ãã³ã¹:
HTTP/1.1 200 OK
Content-Type: application/json
[
{
"attempts": 0,
"email": "admin@example.com",
"emailVerified": true,
"locked": false,
"createdAt": "2025-07-29T07:37:01.735Z",
"id": "811ff0a3-a26f-447b-b68a-dd83ea4000b9",
"updatedAt": "2025-07-29T07:39:36.564Z",
"typeId": "100"
},
{
"attempts": 0,
"email": "user@example.com",
"emailVerified": false,
"locked": false,
"createdAt": "2025-07-29T07:38:15.123Z",
"id": "922ff1b4-b37g-558c-c79b-ee94fb5001c0",
"updatedAt": "2025-07-29T07:38:15.123Z",
"typeId": "001"
}
]
ãšã©ãŒã¬ã¹ãã³ã¹:
ãŠãŒã¶ãŒããªãœãŒã¹ã«ã¢ã¯ã»ã¹ããæš©éããªãå Žå:
HTTP/1.1 403 Forbidden
Content-Type: application/json
{
"error": {
"message": "User is not authorized to access this resource"
}
}
äºæããªããšã©ãŒãçºçããå ŽåïŒããŒã¿ããŒã¹æ¥ç¶ã®åé¡ãç¡å¹ãªãã£ã«ã¿æ§æãªã©ïŒ:
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
{
"error": {
"message": "Failed to find identities"
}
}
3. ã¢ã€ãã³ãã£ãã£ã®æŽæ°â
éšåçãªããŒã¿ã§æ¢åã®ã¢ã€ãã³ãã£ãã£ãæŽæ°ããŸãã
ãªã¯ãšã¹ã:
- Method:
PATCH - Path:
/identities/:identityId - Headers:
Content-Type: application/jsonAuthorization: Bearer <token>x-nb-fingerprint: <device-fingerprint>
- Authorization: BearerããŒã¯ã³ãå¿ èŠïŒç®¡çè ïŒ
URLãã©ã¡ãŒã¿:
| Parameter | Type | å¿ é | 説æ |
|---|---|---|---|
identityId | string | â | äžæã®ã¢ã€ãã³ãã£ãã£èå¥å |
ãªã¯ãšã¹ãããã£ïŒãã¹ãŠã®ãã£ãŒã«ãã¯ãªãã·ã§ã³ïŒ:
| Field | Type | å¿ é | 説æ |
|---|---|---|---|
email | string | â | ãŠãŒã¶ãŒã®ã¡ãŒã«ã¢ãã¬ã¹ |
emailVerified | boolean | â | ã¡ãŒã«ç¢ºèªã¹ããŒã¿ã¹ |
typeId | string | â | ãŠãŒã¶ãŒã¿ã€ãèå¥å |
ã¬ã¹ãã³ã¹ããã£:
| Field | Type | 説æ |
|---|---|---|
id | string | äžæã®ã¢ã€ãã³ãã£ãã£èå¥å |
email | string | æŽæ°ãããã¡ãŒã«ã¢ãã¬ã¹ |
emailVerified | boolean | æŽæ°ãããã¡ãŒã«ç¢ºèªã¹ããŒã¿ã¹ |
typeId | string | æŽæ°ããããŠãŒã¶ãŒã¿ã€ãèå¥å |
attempts | number | æŽæ°ããããã°ã€ã³è©Šè¡åæ° |
locked | boolean | æŽæ°ãããã¢ã«ãŠã³ãããã¯ã¹ããŒã¿ã¹ |
createdAt | string | äœæã¿ã€ã ã¹ã¿ã³ã |
updatedAt | string | æçµæŽæ°ã¿ã€ã ã¹ã¿ã³ã |
ããªããŒã·ã§ã³:
- ã¹ããŒãããªããŒã·ã§ã³: åºæ¬ããªããŒã·ã§ã³ïŒãã¹ãŠã®ãã£ãŒã«ãã¯ãªãã·ã§ã³ãåãã§ãã¯ïŒ
- ã«ãŒãããªããŒã¿ãŒ:
- èªèšŒæžã¿ãªã¯ãšã¹ããå¿ èŠïŒbearerããŒã¯ã³ïŒ
- 管çè ããŒã«ãå¿ èŠ
ãªã¯ãšã¹ãäŸ:
curl -X PATCH {{host}}/identities/811ff0a3-a26f-447b-b68a-dd83ea4000b9 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access-token>" \
-d '{
"email": "admin@example.com",
"emailVerified": true,
"typeId": "200"
}'
æåã¬ã¹ãã³ã¹:
HTTP/1.1 200 OK
Content-Type: application/json
{
"attempts": 0,
"email": "admin@example.com",
"locked": false,
"createdAt": "2025-07-29T07:37:01.735Z",
"id": "811ff0a3-a26f-447b-b68a-dd83ea4000b9",
"updatedAt": "2025-07-29T07:42:07.611Z",
"typeId": "200"
}
ãšã©ãŒã¬ã¹ãã³ã¹:
æå®ãããIDã®ã¢ã€ãã³ãã£ãã£ãååšããªãå Žå:
HTTP/1.1 404 Not Found
Content-Type: application/json
{
"error": {
"message": "Identity not found"
}
}
æŽæ°æäœãããŒã¿ã倿Žããªãã£ãå ŽåïŒå€æŽãæ€åºãããªãã£ãïŒ:
HTTP/1.1 400 Bad Request
Content-Type: application/json
{
"error": {
"message": "Failed to update identity"
}
}
äºæããªããšã©ãŒãçºçããå ŽåïŒããŒã¿ããŒã¹æ¥ç¶ã®åé¡ãªã©ïŒ:
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
{
"error": {
"message": "Failed to update identity"
}
}
4. ã¢ã€ãã³ãã£ãã£ã®åé€â
ã·ã¹ãã ããã¢ã€ãã³ãã£ãã£ãæ°žç¶çã«åé€ããŸãã
ãªã¯ãšã¹ã:
- Method:
DELETE - Path:
/identities/:identityId - Headers:
Authorization: Bearer <token>x-nb-fingerprint: <device-fingerprint>
- Authorization: BearerããŒã¯ã³ãå¿ èŠïŒç®¡çè ïŒ
URLãã©ã¡ãŒã¿:
| Parameter | Type | å¿ é | 説æ |
|---|---|---|---|
identityId | string | â | äžæã®ã¢ã€ãã³ãã£ãã£èå¥å |
ã¬ã¹ãã³ã¹ããã£:
| Field | Type | 説æ |
|---|---|---|
| ã¬ã¹ãã³ã¹ããã£ãªã | - | åé€ãšã³ããã€ã³ãã¯æåæã«ã¬ã¹ãã³ã¹ããã£ãè¿ããŸãã |
ããªããŒã·ã§ã³:
- ã¹ããŒãããªããŒã·ã§ã³: ãªãïŒDELETEãªã¯ãšã¹ãïŒ
- ã«ãŒãããªããŒã¿ãŒ:
- èªèšŒæžã¿ãªã¯ãšã¹ããå¿ èŠïŒbearerããŒã¯ã³ïŒ
- 管çè ããŒã«ãå¿ èŠ
ãªã¯ãšã¹ãäŸ:
curl -X DELETE {{host}}/identities/be265523-7fea-44a1-a0a2-dc5dabdb9f0c \
-H "Authorization: Bearer <access-token>"
æåã¬ã¹ãã³ã¹:
HTTP/1.1 204 No Content
ãšã©ãŒã¬ã¹ãã³ã¹:
ãŠãŒã¶ãŒããªãœãŒã¹ã«ã¢ã¯ã»ã¹ããæš©éããªãå Žå:
HTTP/1.1 403 Forbidden
Content-Type: application/json
{
"error": {
"message": "User is not authorized to access this resource"
}
}
æå®ãããIDã®ã¢ã€ãã³ãã£ãã£ãååšããªãå Žå:
HTTP/1.1 404 Not Found
Content-Type: application/json
{
"error": {
"message": "Identity not found"
}
}
äºæããªããšã©ãŒãçºçããå ŽåïŒããŒã¿ããŒã¹æ¥ç¶ã®åé¡ãªã©ïŒ:
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
{
"error": {
"message": "Failed to delete identity"
}
}
5. ã¢ã€ãã³ãã£ãã£ã®ããã¯â
ã»ãã¥ãªãã£äžã®çç±ã«ãããã¢ã€ãã³ãã£ãã£ã¢ã«ãŠã³ããããã¯ããŠã¢ã¯ã»ã¹ã鲿¢ããŸãã
ãªã¯ãšã¹ã:
- Method:
POST - Path:
/identities/:identityId/lock - Headers:
Authorization: Bearer <token>x-nb-fingerprint: <device-fingerprint>
- Authorization: BearerããŒã¯ã³ãå¿ èŠïŒç®¡çè ïŒ
URLãã©ã¡ãŒã¿:
| Parameter | Type | å¿ é | 説æ |
|---|---|---|---|
identityId | string | â | ããã¯ããäžæã®ã¢ã€ãã³ãã£ãã£èå¥å |
ã¬ã¹ãã³ã¹ããã£:
| Field | Type | 説æ |
|---|---|---|
| ã¬ã¹ãã³ã¹ããã£ãªã | - | ããã¯ãšã³ããã€ã³ãã¯æåæã«ã¬ã¹ãã³ã¹ããã£ãè¿ããŸãã |
ããªããŒã·ã§ã³:
- ã¹ããŒãããªããŒã·ã§ã³: ãã¹ãã©ã¡ãŒã¿ããªããŒã·ã§ã³
- ã«ãŒãããªããŒã¿ãŒ:
- èªèšŒæžã¿ãªã¯ãšã¹ããå¿ èŠïŒbearerããŒã¯ã³ïŒ
- 管çè ããŒã«ãå¿ èŠ
ãªã¯ãšã¹ãäŸ:
curl -X POST {{host}}/identities/be265523-7fea-44a1-a0a2-dc5dabdb9f0c/lock \
-H "Authorization: Bearer <access-token>" \
-H "x-nb-fingerprint: <device-fingerprint>"
æåã¬ã¹ãã³ã¹:
HTTP/1.1 204 No Content
ãšã©ãŒã¬ã¹ãã³ã¹:
ãŠãŒã¶ãŒããªãœãŒã¹ã«ã¢ã¯ã»ã¹ããæš©éããªãå Žå:
HTTP/1.1 403 Forbidden
Content-Type: application/json
{
"error": {
"message": "User is not authorized to access this resource"
}
}
ã¢ã€ãã³ãã£ãã£ãååšããªãå Žå:
HTTP/1.1 404 Not Found
Content-Type: application/json
{
"error": {
"message": "Identity not found"
}
}
6. ã¢ã€ãã³ãã£ãã£ã®ã¢ã³ããã¯â
以åã«ããã¯ãããã¢ã€ãã³ãã£ãã£ã¢ã«ãŠã³ããã¢ã³ããã¯ããŠã¢ã¯ã»ã¹ã埩å ããŸãã
ãªã¯ãšã¹ã:
- Method:
POST - Path:
/identities/:identityId/unlock - Headers:
Authorization: Bearer <token>x-nb-fingerprint: <device-fingerprint>
- Authorization: BearerããŒã¯ã³ãå¿ èŠïŒç®¡çè ïŒ
URLãã©ã¡ãŒã¿:
| Parameter | Type | å¿ é | 説æ |
|---|---|---|---|
identityId | string | â | ã¢ã³ããã¯ããäžæã®ã¢ã€ãã³ãã£ãã£èå¥å |
ã¬ã¹ãã³ã¹ããã£:
| Field | Type | 説æ |
|---|---|---|
| ã¬ã¹ãã³ã¹ããã£ãªã | - | ã¢ã³ããã¯ãšã³ããã€ã³ãã¯æåæã«ã¬ã¹ãã³ã¹ããã£ãè¿ããŸãã |
ããªããŒã·ã§ã³:
- ã¹ããŒãããªããŒã·ã§ã³: ãã¹ãã©ã¡ãŒã¿ããªããŒã·ã§ã³
- ã«ãŒãããªããŒã¿ãŒ:
- èªèšŒæžã¿ãªã¯ãšã¹ããå¿ èŠïŒbearerããŒã¯ã³ïŒ
- 管çè ããŒã«ãå¿ èŠ
ãªã¯ãšã¹ãäŸ:
curl -X POST {{host}}/identities/be265523-7fea-44a1-a0a2-dc5dabdb9f0c/unlock \
-H "Authorization: Bearer <access-token>" \
-H "x-nb-fingerprint: <device-fingerprint>"
æåã¬ã¹ãã³ã¹:
HTTP/1.1 204 No Content
ãšã©ãŒã¬ã¹ãã³ã¹:
ãŠãŒã¶ãŒããªãœãŒã¹ã«ã¢ã¯ã»ã¹ããæš©éããªãå Žå:
HTTP/1.1 403 Forbidden
Content-Type: application/json
{
"error": {
"message": "User is not authorized to access this resource"
}
}
ã¢ã€ãã³ãã£ãã£ãååšããªãå Žå:
HTTP/1.1 404 Not Found
Content-Type: application/json
{
"error": {
"message": "Identity not found"
}
}
âïž èšå®ãªãã·ã§ã³â
ãµãŒãã¹èšå®â
interface IdentitiesServiceConfiguration {
authSecrets: {
authEncSecret: string; // JWT encryption secret
authSignSecret: string; // JWT signing secret
};
identity?: {
typeIds?: {
admin: string; // Admin user type identifier
guest: string; // Guest user type identifier
regular: string; // Regular user type identifier
};
};
}
èšå®è©³çްâ
ã¢ã€ãã³ãã£ãã£ãµãŒãã¹ã®èšå®ã¯ãã»ãã¥ãªãã£ãšãŠãŒã¶ãŒã¿ã€ã管çã®ããã®è«ççãªã°ã«ãŒãã«æŽçãããŠããŸãã
ð ã»ãã¥ãªãã£èšå®â
authSecrets - JWTããŒã¯ã³ã»ãã¥ãªãã£ã·ãŒã¯ã¬ãã
- Type:
{ authEncSecret: string; authSignSecret: string } - 説æ: JWTæå·åãšçœ²åã®ããã®ã·ãŒã¯ã¬ããããŒïŒããŒã¯ã³æ€èšŒã«äœ¿çšïŒ
- å¿ é : ã¯ãïŒæ¬çªç°å¢ã®å ŽåïŒ
- åããããã£:
authEncSecret: JWTãã€ããŒãæå·åã®ããã®ã·ãŒã¯ã¬ããããŒauthSignSecret: JWTçœ²åæ€èšŒã®ããã®ã·ãŒã¯ã¬ããããŒ
ð¥ ãŠãŒã¶ãŒã¿ã€ãèšå®â
identity.typeIds - ãŠãŒã¶ãŒã¿ã€ãèå¥åèšå®
- Type:
{ admin?: string; guest?: string; regular?: string } - 説æ: ããŒã«ããŒã¹ã¢ã¯ã»ã¹å¶åŸ¡ã®ããã®ã«ã¹ã¿ã ãŠãŒã¶ãŒã¿ã€ãèå¥å
- ããã©ã«ã:
undefinedïŒããã©ã«ãã®åæ€èšŒã䜿çšïŒ - åããããã£:
admin: 管çè ãŠãŒã¶ãŒã¿ã€ãèå¥å- Type:
string - 説æ: 管çè ãŠãŒã¶ãŒçšã®ã«ã¹ã¿ã èå¥å
- 䜿çšäŸ: 管çæäœã®ããã®ããŒã«ããŒã¹ã¢ã¯ã»ã¹å¶åŸ¡
- äŸ:
"admin","administrator","superuser"
- Type:
guest: ã²ã¹ããŠãŒã¶ãŒã¿ã€ãèå¥å- Type:
string - 説æ: ã²ã¹ããŠãŒã¶ãŒçšã®ã«ã¹ã¿ã èå¥å
- 䜿çšäŸ: èªèšŒãããŠããªããŸãã¯äžæçãªãŠãŒã¶ãŒåãã®éå®ã¢ã¯ã»ã¹
- äŸ:
"guest","visitor","anonymous"
- Type:
regular: éåžžãŠãŒã¶ãŒã¿ã€ãèå¥å- Type:
string - 説æ: éåžžãŠãŒã¶ãŒçšã®ã«ã¹ã¿ã èå¥å
- 䜿çšäŸ: æšæºçãªãŠãŒã¶ãŒã¢ã¯ã»ã¹æš©é
- äŸ:
"user","member","customer"
- Type:
èšå®äŸâ
const identityConfig = {
authSecrets: {
authEncSecret: process.env.AUTH_ENC_SECRET || 'your-enc-secret',
authSignSecret: process.env.AUTH_SIGN_SECRET || 'your-sign-secret'
},
identity: {
typeIds: {
admin: '100',
guest: '000',
regular: '001'
}
}
};
ðš ãšã©ãŒãã³ããªã³ã°â
ãã¹ãŠã®ã¢ã€ãã³ãã£ãã£ãµãŒãã¹ãšã©ãŒã¯ãé©åãªHTTPã¹ããŒã¿ã¹ã³ãŒããšå ±ã«JSON圢åŒã§è¿ãããŸãïŒ
äžè¬çãªãšã©ãŒã³ãŒãâ
| Status | Error Message | 説æ |
|---|---|---|
| 400 | Failed to update identity | æŽæ°æäœãããŒã¿ã倿Žããªãã£ãïŒå€æŽãæ€åºãããªãã£ãïŒ |
| 401 | token could not be verified | èªèšŒããŒã¯ã³ãæ¬ èœããŠãããç¡å¹ |
| 403 | User is not authorized to access this resource | ãªã¯ãšã¹ããããæäœã«å¯Ÿããæš©éãäžè¶³ããŠãã |
| 404 | Identity not found | GET/PATCH/DELETEæäœã«å¯ŸããŠã¢ã€ãã³ãã£ãã£ãååšããªã |
| 500 | Failed to get identity | ååŸäžã®ããŒã¿ããŒã¹æ¥ç¶ã®åé¡ãŸãã¯äºæããªã倱æ |
| 500 | Failed to find identities | ãªã¹ãååŸäžã®ããŒã¿ããŒã¹æ¥ç¶ã®åé¡ãç¡å¹ãªãã£ã«ã¿æ§æããŸãã¯äºæããªã倱æ |
| 500 | Failed to update identity | æŽæ°äžã®ããŒã¿ããŒã¹æ¥ç¶ã®åé¡ãŸãã¯äºæããªã倱æ |
| 500 | Failed to delete identity | åé€äžã®ããŒã¿ããŒã¹æ¥ç¶ã®åé¡ãŸãã¯äºæããªã倱æ |
ãšã©ãŒã¬ã¹ãã³ã¹åœ¢åŒâ
{
"error": {
"message": "ãšã©ãŒã¡ãã»ãŒãžã®èª¬æ",
"data": ["远å ã®ãšã©ãŒè©³çް"]
}
}
ð é¢é£ããã¥ã¡ã³ãâ
- Error Handling - ãšã©ãŒãã¿ãŒã³ã®çè§£
- Schema Component - ããŒã¿ããªããŒã·ã§ã³ã®æŠå¿µ
- Custom Service Tutorial - ç¬èªã®ãµãŒãã¹ãæ§ç¯
- User Service - ãŠãŒã¶ãŒç®¡çæäœ