ð ã¢ã€ãã³ãã£ãã£ãµãŒãã¹
ã¢ã€ãã³ãã£ãã£ãµãŒãã¹ã¯ãã¢ã€ãã³ãã£ãã£ãšã³ãã£ãã£ã®ååŸãæŽæ°ãåé€ãããã¯ãããã¯è§£é€ãããã³ã»ãã¥ãªãã£ç®¡çã®ããã®å®å šãª 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/?authSource=admin', 'dev', 'user', 'password');
express()
.use(
identitiesService(await connectToDatabase('identities'), {
authSecrets: {
authEncSecret: 'your-encryption-secret',
authSignSecret: 'your-signing-secret',
},
authMode: 'bearer', // ãŸã㯠'cookie'
identity: {
typeIds: {
admin: '100',
guest: '000',
regular: '001',
},
},
}),
)
.use(nodeBlocksErrorMiddleware())
.listen(8089, () => console.log('Server running'));
ð ãšã³ããã€ã³ãæŠèŠâ
| ã¡ãœãã | ãã¹ | 説æ | èªå¯ |
|---|---|---|---|
GET | /identities/:identityId | ID ã§ã¢ã€ãã³ãã£ãã£ãååŸ | ã¢ã¯ã»ã¹ããŒã¯ã³å¿
é ïŒæ¢å®ã¯ bearerãauthMode: 'cookie' ã®å Žå㯠cookieïŒã管çè
ã®ã¿ |
GET | /identities | ã¢ã€ãã³ãã£ãã£ã®äžèЧïŒãã£ã«ã¿ | ã¢ã¯ã»ã¹ããŒã¯ã³å¿
é ïŒæ¢å®ã¯ bearerãauthMode: 'cookie' ã®å Žå㯠cookieïŒã管çè
ã®ã¿ |
PATCH | /identities/:identityId | ã¢ã€ãã³ãã£ãã£ãæŽæ° | ã¢ã¯ã»ã¹ããŒã¯ã³å¿
é ïŒæ¢å®ã¯ bearerãauthMode: 'cookie' ã®å Žå㯠cookieïŒã管çè
ã®ã¿ |
POST | /identities/:identityId/lock | ã»ãã¥ãªãã£äžã®çç±ã§ã¢ã€ãã³ãã£ãã£ããã㯠| ã¢ã¯ã»ã¹ããŒã¯ã³å¿
é ïŒæ¢å®ã¯ bearerãauthMode: 'cookie' ã®å Žå㯠cookieïŒã管çè
ã®ã¿ |
POST | /identities/:identityId/unlock | ããã¯ãããã¢ã€ãã³ãã£ãã£ãããã¯è§£é€ | ã¢ã¯ã»ã¹ããŒã¯ã³å¿
é ïŒæ¢å®ã¯ bearerãauthMode: 'cookie' ã®å Žå㯠cookieïŒã管çè
ã®ã¿ |
DELETE | /identities/:identityId | ã¢ã€ãã³ãã£ãã£ãåé€ | ã¢ã¯ã»ã¹ããŒã¯ã³å¿
é ïŒæ¢å®ã¯ bearerãauthMode: 'cookie' ã®å Žå㯠cookieïŒã管çè
ã®ã¿ |
ðïž ãšã³ãã£ãã£ã¹ããŒãâ
ã¢ã€ãã³ãã£ãã£ãšã³ãã£ãã£ã¯ãèªåçæãããããŒã¹ãã£ãŒã«ããšãã¢ã€ãã³ãã£ãã£åºæã®ããŒã¿ã§æ§æãããŸãïŒ
{
"id": "string",
"createdAt": "string (datetime)",
"updatedAt": "string (datetime)",
"email": "string",
"emailVerified": "boolean",
"password": "string (hashed)",
"typeId": "string",
"attempts": "number",
"locked": "boolean",
"deactivatedAt": "string (datetime) | null",
"provider": "string",
"providerId": "string"
}
ãã£ãŒã«ã詳现â
| ãã£ãŒã«ã | å | èªåçæ | å¿ é | 説æ |
|---|---|---|---|---|
id | string | â | â | äžæèå¥åïŒUUIDïŒ |
createdAt | datetime | â | â | äœææ¥æ |
updatedAt | datetime | â | â | æçµæŽæ°æ¥æ |
email | string | â | â | ãŠãŒã¶ãŒã®ã¡ãŒã«ã¢ãã¬ã¹ |
emailVerified | boolean | â | â | ã¡ãŒã«èªèšŒã¹ããŒã¿ã¹ |
password | string | â | â | ããã·ã¥åãã¹ã¯ãŒãïŒbcryptïŒ |
typeId | string | â | â | ãŠãŒã¶ãŒçš®å¥èå¥åïŒäŸ: 管çè 㯠"100"ïŒ |
attempts | number | â | â | ãã°ã€ã³è©Šè¡åæ° |
locked | boolean | â | â | ã¢ã«ãŠã³ãããã¯ç¶æ |
deactivatedAt | datetime ãŸã㯠null | â | â | ã¢ã«ãŠã³ãç¡å¹åæ¥æãã¢ã¯ãã£ãæã¯ null |
provider | string | â | â | OAuth ãããã€ããŒèå¥å |
providerId | string | â | â | ãããã€ããŒåºæã®ã¢ã€ãã³ãã£ãã£èå¥å |
ð æ³šæ: èªåçæãã£ãŒã«ãã¯ãµãŒãã¹åŽã§èšå®ãããäœæ/æŽæ°ãªã¯ãšã¹ãã«å«ããªãã§ãã ããã
ð ã»ãã¥ãªãã£ã«é¢ããæ³šæ: ã»ãã¥ãªãã£äžã®çç±ããã
passwordãã£ãŒã«ã㯠API ã¬ã¹ãã³ã¹ã§è¿ãããŸãããããŒã¿ããŒã¹ã«ã¯ bcrypt ã§å®å šã«ããã·ã¥åããŠä¿åãããã¯ã©ã€ã¢ã³ããžéä¿¡ããåã«é€å€ãããŸãã
ð èªèšŒããããŒâ
ãã¹ãŠã®ãšã³ããã€ã³ãã§ã次ã®ããããŒãå«ããŠãã ããïŒ
Authorization: Bearer <access_token>
x-nb-fingerprint: <device_fingerprint>
â ïž éèŠ: èªå¯æã«ãã£ã³ã¬ãŒããªã³ããæå®ããå ŽåãèªèšŒæžã¿ã®ãã¹ãŠã®ãªã¯ãšã¹ãã§
x-nb-fingerprintããããŒãå¿ é ã§ããæ¬ åŠããŠããå Žå㯠401 Unauthorized ãè¿ããŸãã
ðª Cookie èªèšŒ:
authMode: 'cookie'ã®å Žåãä¿è·ãããã«ãŒã㯠Cookie ããã¢ã¯ã»ã¹ããŒã¯ã³ãèªã¿åããŸãããã¹ãã¢ããªã§cookie-parserãç»é²ããŠãã ããã
ð 管çè ã¢ã¯ã»ã¹å¿ é : ã¢ã€ãã³ãã£ãã£ãµãŒãã¹ã®ãã¹ãŠã®ãšã³ããã€ã³ãã¯ç®¡çè æš©éãå¿ èŠã§ããã¢ã¯ã»ã¹ããŒã¯ã³ã¯ç®¡çè æš©éãæã€ãŠãŒã¶ãŒïŒããã©ã«ãã® typeId 㯠"100"ïŒã®ãã®ã§ããå¿ èŠããããŸããé管çè 㯠403 Forbidden ãè¿ãããŸãã
ð§ APIãšã³ããã€ã³ãâ
1. ã¢ã€ãã³ãã£ãã£ã®ååŸïŒIDæå®ïŒâ
äžæã®IDã§ç¹å®ã®ã¢ã€ãã³ãã£ãã£ãååŸããŸãã
ãªã¯ãšã¹ã:
- Method:
GET - Path:
/identities/:identityId - ããããŒ:
Authorization: Bearer <token>x-nb-fingerprint: <device-fingerprint>
- èªå¯: ã¢ã¯ã»ã¹ããŒã¯ã³å¿
é ïŒæ¢å®ã¯
bearerãauthMode: 'cookie'ã®å Žåã¯cookieïŒã管çè ã®ã¿
URL ãã©ã¡ãŒã¿:
| ãã©ã¡ãŒã¿ | å | å¿ é | 説æ |
|---|---|---|---|
identityId | string | â | ã¢ã€ãã³ãã£ãã£äžæèå¥å |
ã¬ã¹ãã³ã¹ããã£:
| ãã£ãŒã«ã | å | 説æ |
|---|---|---|
id | string | ã¢ã€ãã³ãã£ãã£äžæèå¥å |
email | string | ãŠãŒã¶ãŒã®ã¡ãŒã«ã¢ãã¬ã¹ |
emailVerified | boolean | ã¡ãŒã«èªèšŒã¹ããŒã¿ã¹ |
typeId | string | ãŠãŒã¶ãŒçš®å¥èå¥å |
attempts | number | ãã°ã€ã³è©Šè¡åæ° |
locked | boolean | ã¢ã«ãŠã³ãããã¯ç¶æ |
createdAt | string | äœææ¥æ |
updatedAt | string | æçµæŽæ°æ¥æ |
ããªããŒã·ã§ã³:
- ã¹ããŒãæ€èšŒ: ãªãïŒGET ãªã¯ãšã¹ãïŒ
- ã«ãŒãããªããŒã·ã§ã³:
- èªèšŒæžã¿ãªã¯ãšã¹ãïŒã¢ã¯ã»ã¹ããŒã¯ã³ïŒå¿ é
- 管çè ããŒã«å¿ é
ãªã¯ãšã¹ãäŸ:
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"
}
}
äºæããªããšã©ãŒãçºçããå ŽåïŒDBæ¥ç¶åé¡ãªã©ïŒ:
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
{
"error": {
"message": "Failed to get identity"
}
}
2. ã¢ã€ãã³ãã£ãã£äžèЧâ
ã¢ã€ãã³ãã£ãã£ã®äžèЧãååŸããŸããã¯ãšãªãã©ã¡ãŒã¿ã¯ã¹ããŒãã§æ€èšŒãããŸããããã³ãã©ãŒã¯å®å šãªé åãè¿ãããµãŒããŒåŽã®ããŒãžããŒã·ã§ã³ã¯å®è£ ããŠããŸããã
ãªã¯ãšã¹ã:
- Method:
GET - Path:
/identities - ããããŒ:
Authorization: Bearer <token>x-nb-fingerprint: <device-fingerprint>
- èªå¯: ã¢ã¯ã»ã¹ããŒã¯ã³å¿
é ïŒæ¢å®ã¯
bearerãauthMode: 'cookie'ã®å Žåã¯cookieïŒã管çè ã®ã¿
ã¯ãšãªãã©ã¡ãŒã¿:
| ãã©ã¡ãŒã¿ | å | å¿ é | 説æ |
|---|---|---|---|
name | string | â | ã¹ããŒãã§åãä»ããã Mongo ã® find ã«æž¡ãããïŒæ¢å®ã®ã¢ã€ãã³ãã£ãã£ææžã«ã¯ name ãã£ãŒã«ãããããŸããïŒ |
page | number | â | ã¹ããŒãã§åãä»ããã Mongo ãã£ã«ã¿ãŒã«æž¡ããããããŒãžããŒã·ã§ã³ã«ã¯äœ¿çšãããŸãã |
limit | number | â | ã¹ããŒãã§åãä»ããã Mongo ãã£ã«ã¿ãŒã«æž¡ããããããŒãžããŒã·ã§ã³ã«ã¯äœ¿çšãããŸãã |
ã¬ã¹ãã³ã¹ããã£:
| ãã£ãŒã«ã | å | 説æ |
|---|---|---|
id | string | ã¢ã€ãã³ãã£ãã£äžæèå¥å |
email | string | ãŠãŒã¶ãŒã®ã¡ãŒã«ã¢ãã¬ã¹ |
emailVerified | boolean | ã¡ãŒã«èªèšŒã¹ããŒã¿ã¹ |
typeId | string | ãŠãŒã¶ãŒçš®å¥èå¥å |
attempts | number | ãã°ã€ã³è©Šè¡åæ° |
locked | boolean | ã¢ã«ãŠã³ãããã¯ç¶æ |
createdAt | string | äœææ¥æ |
updatedAt | string | æçµæŽæ°æ¥æ |
ããªããŒã·ã§ã³:
- ã¹ããŒãæ€èšŒ: nameïŒstringïŒãpage/limitïŒæå°/æå€§å¶çŽã®ããæŽæ°ïŒã®ã¯ãšãªæ€èšŒã
page/limitã¯ããŒãžããŒã·ã§ã³ã«ã¯äœ¿ãããããã®ãŸãŸ Mongo ãã£ã«ã¿ãŒã®ã¯ãšãªããŒãšããŠæž¡ãããŸãã - ã«ãŒãããªããŒã·ã§ã³:
- èªèšŒæžã¿ãªã¯ãšã¹ãïŒã¢ã¯ã»ã¹ããŒã¯ã³ïŒå¿ é
- 管çè ããŒã«å¿ é
ãªã¯ãšã¹ãäŸ:
å šä»¶ååŸ:
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": "Identity is not authorized to access this resource"
}
}
äºæããªããšã©ãŒãçºçããå ŽåïŒDBæ¥ç¶åé¡ããã£ã«ã¿æ§æäžæ£ãªã©ïŒ:
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
{
"error": {
"message": "Failed to find identities"
}
}
3. ã¢ã€ãã³ãã£ãã£æŽæ°â
éšåæŽæ°ã§æ¢åã®ã¢ã€ãã³ãã£ãã£ãæŽæ°ããŸãã
ãªã¯ãšã¹ã:
- Method:
PATCH - Path:
/identities/:identityId - ããããŒ:
Content-Type: application/jsonAuthorization: Bearer <token>x-nb-fingerprint: <device-fingerprint>
- èªå¯: ã¢ã¯ã»ã¹ããŒã¯ã³å¿
é ïŒæ¢å®ã¯
bearerãauthMode: 'cookie'ã®å Žåã¯cookieïŒã管çè ã®ã¿
URL ãã©ã¡ãŒã¿:
| ãã©ã¡ãŒã¿ | å | å¿ é | 説æ |
|---|---|---|---|
identityId | string | â | ã¢ã€ãã³ãã£ãã£äžæèå¥å |
ãªã¯ãšã¹ãããã£ïŒãªããžã§ã¯ãå¿ é ãå°ãªããšã1ã€ã®ãã£ãŒã«ããæå®ïŒ:
| ãã£ãŒã«ã | å | å¿ é | 説æ |
|---|---|---|---|
email | string | â | ãŠãŒã¶ãŒã®ã¡ãŒã«ã¢ãã¬ã¹ |
emailVerified | boolean | â | ã¡ãŒã«èªèšŒã¹ããŒã¿ã¹ |
typeId | string | â | ãŠãŒã¶ãŒçš®å¥èå¥å |
ã¬ã¹ãã³ã¹ããã£:
| ãã£ãŒã«ã | å | 説æ |
|---|---|---|
id | string | ã¢ã€ãã³ãã£ãã£äžæèå¥å |
email | string | æŽæ°åŸã®ã¡ãŒã«ã¢ãã¬ã¹ |
emailVerified | boolean | æŽæ°åŸã®ã¡ãŒã«èªèšŒã¹ããŒã¿ã¹ |
typeId | string | æŽæ°åŸã®ãŠãŒã¶ãŒçš®å¥èå¥å |
attempts | number | æŽæ°åŸã®ãã°ã€ã³è©Šè¡åæ° |
locked | boolean | æŽæ°åŸã®ã¢ã«ãŠã³ãããã¯ç¶æ |
createdAt | string | äœææ¥æ |
updatedAt | string | æçµæŽæ°æ¥æ |
ããªããŒã·ã§ã³:
- ã¹ããŒãæ€èšŒ: åºæ¬çãªæ€èšŒïŒå šãã£ãŒã«ãä»»æãåãã§ãã¯ïŒ
- ã«ãŒãããªããŒã·ã§ã³:
- èªèšŒæžã¿ãªã¯ãšã¹ãïŒã¢ã¯ã»ã¹ããŒã¯ã³ïŒå¿ é
- 管çè ããŒã«å¿ é
泚: 空㮠JSON ãªããžã§ã¯ãã¯ãæŽæ°ãã€ããŒãã«å°ãªããšã1ã€ã®ãã£ãŒã«ããå¿ èŠãªããããã³ãã©ãŒã«ãã
400 Identity data is requiredã§æåŠãããŸãã
ãªã¯ãšã¹ãäŸ:
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": "Identity data is required"
}
}
æŽæ°æäœã§ããŒã¿ã倿Žãããªãå ŽåïŒå€æŽãªãïŒ:
HTTP/1.1 400 Bad Request
Content-Type: application/json
{
"error": {
"message": "Failed to update identity"
}
}
äºæããªããšã©ãŒãçºçããå ŽåïŒDBæ¥ç¶åé¡ãªã©ïŒ:
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
{
"error": {
"message": "Failed to update identity"
}
}
4. ã¢ã€ãã³ãã£ãã£åé€â
ã·ã¹ãã ããã¢ã€ãã³ãã£ãã£ãå®å šã«åé€ããŸãã
ãªã¯ãšã¹ã:
- Method:
DELETE - Path:
/identities/:identityId - ããããŒ:
Authorization: Bearer <token>x-nb-fingerprint: <device-fingerprint>
- èªå¯: ã¢ã¯ã»ã¹ããŒã¯ã³å¿
é ïŒæ¢å®ã¯
bearerãauthMode: 'cookie'ã®å Žåã¯cookieïŒã管çè ã®ã¿
URL ãã©ã¡ãŒã¿:
| ãã©ã¡ãŒã¿ | å | å¿ é | 説æ |
|---|---|---|---|
identityId | string | â | ã¢ã€ãã³ãã£ãã£äžæèå¥å |
ã¬ã¹ãã³ã¹ããã£:
| ãã£ãŒã«ã | å | 説æ |
|---|---|---|
| ãªã | - | æåæã¯ã¬ã¹ãã³ã¹ããã£ãªã |
ããªããŒã·ã§ã³:
- ã¹ããŒãæ€èšŒ: ãªãïŒDELETE ãªã¯ãšã¹ãïŒ
- ã«ãŒãããªããŒã·ã§ã³:
- èªèšŒæžã¿ãªã¯ãšã¹ãïŒã¢ã¯ã»ã¹ããŒã¯ã³ïŒå¿ é
- 管çè ããŒã«å¿ é
ãªã¯ãšã¹ãäŸ:
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": "Identity is not authorized to access this resource"
}
}
æå®IDã®ã¢ã€ãã³ãã£ãã£ãååšããªãå Žå:
HTTP/1.1 404 Not Found
Content-Type: application/json
{
"error": {
"message": "Identity not found"
}
}
äºæããªããšã©ãŒãçºçããå ŽåïŒDBæ¥ç¶åé¡ãªã©ïŒ:
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
{
"error": {
"message": "Failed to delete identity"
}
}
5. ã¢ã€ãã³ãã£ãã£ãããã¯â
ã»ãã¥ãªãã£äžã®çç±ãããã¢ã€ãã³ãã£ãã£ã¢ã«ãŠã³ããããã¯ããŠã¢ã¯ã»ã¹ãçŠæ¢ããŸãã
ãªã¯ãšã¹ã:
- ã¡ãœãã:
POST - ãã¹:
/identities/:identityId/lock - ããããŒ:
Authorization: Bearer <token>x-nb-fingerprint: <device-fingerprint>
- èªå¯: ã¢ã¯ã»ã¹ããŒã¯ã³å¿
é ïŒæ¢å®ã¯
bearerãauthMode: 'cookie'ã®å Žåã¯cookieïŒã管çè ã®ã¿
URL ãã©ã¡ãŒã¿:
| ãã©ã¡ãŒã¿ | å | å¿ é | 説æ |
|---|---|---|---|
identityId | string | â | ããã¯ããã¢ã€ãã³ãã£ãã£ã®äžæèå¥å |
ã¬ã¹ãã³ã¹ããã£:
| ãã£ãŒã«ã | å | 説æ |
|---|---|---|
| ãªã | - | ããã¯ãšã³ããã€ã³ãã¯æåæã«ã¬ã¹ãã³ã¹ããã£ãè¿ããŸãã |
ããªããŒã·ã§ã³: ãã¹ãã©ã¡ãŒã¿ãæ€èšŒããèªèšŒæžã¿ã®ç®¡çè ããŒã«ãèŠæ±ããŸãã
ãªã¯ãšã¹ãäŸ:
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": "Identity is not authorized to access this resource"
}
}
ã¢ã€ãã³ãã£ãã£ãååšããªãå Žå:
HTTP/1.1 404 Not Found
Content-Type: application/json
{
"error": {
"message": "Identity not found"
}
}
6. ã¢ã€ãã³ãã£ãã£ãããã¯è§£é€â
以åã«ããã¯ããã¢ã€ãã³ãã£ãã£ã¢ã«ãŠã³ãã®ããã¯ãè§£é€ããã¢ã¯ã»ã¹ã埩å ããŸãã
ãªã¯ãšã¹ã:
- ã¡ãœãã:
POST - ãã¹:
/identities/:identityId/unlock - ããããŒ:
Authorization: Bearer <token>x-nb-fingerprint: <device-fingerprint>
- èªå¯: ã¢ã¯ã»ã¹ããŒã¯ã³å¿
é ïŒæ¢å®ã¯
bearerãauthMode: 'cookie'ã®å Žåã¯cookieïŒã管çè ã®ã¿
URL ãã©ã¡ãŒã¿:
| ãã©ã¡ãŒã¿ | å | å¿ é | 説æ |
|---|---|---|---|
identityId | string | â | ããã¯è§£é€ããã¢ã€ãã³ãã£ãã£ã®äžæèå¥å |
ã¬ã¹ãã³ã¹ããã£:
| ãã£ãŒã«ã | å | 説æ |
|---|---|---|
| ãªã | - | ããã¯è§£é€ãšã³ããã€ã³ãã¯æåæã«ã¬ã¹ãã³ã¹ããã£ãè¿ããŸãã |
ããªããŒã·ã§ã³: ãã¹ãã©ã¡ãŒã¿ãæ€èšŒããèªèšŒæžã¿ã®ç®¡çè ããŒã«ãèŠæ±ããŸãã
ãªã¯ãšã¹ãäŸ:
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": "Identity is not authorized to access this resource"
}
}
ã¢ã€ãã³ãã£ãã£ãååšããªãå Žå:
HTTP/1.1 404 Not Found
Content-Type: application/json
{
"error": {
"message": "Identity not found"
}
}
ðïž ããŒã¿ã¹ãã¢â
| ã³ã¬ã¯ã·ã§ã³ | å¿ é | 説æ |
|---|---|---|
identities | â | ã¢ã€ãã³ãã£ãã£ææž |
âïž èšå®ãªãã·ã§ã³â
ãµãŒãã¹èšå®â
interface IdentitiesServiceConfiguration {
authSecrets: {
authEncSecret: string; // JWT encryption secret
authSignSecret: string; // JWT signing secret
};
authMode?: 'bearer' | 'cookie'; // æªæå®æã¯ bearer åäœãæ¢å®
identity?: {
typeIds?: {
admin: string; // Admin user type identifier
guest: string; // Guest user type identifier
regular: string; // Regular user type identifier
};
};
}
èšå®è©³çްâ
ã¢ã€ãã³ãã£ãã£ãµãŒãã¹ã®èšå®ã¯ãã»ãã¥ãªãã£ãšãŠãŒã¶ãŒçš®å¥ç®¡çã®è«çã°ã«ãŒãã«æŽçãããŠããŸãã
ð ã»ãã¥ãªãã£èšå®â
authSecrets - JWT ããŒã¯ã³ã®ã»ãã¥ãªãã£ã·ãŒã¯ã¬ãã
- å:
{ authEncSecret: string; authSignSecret: string } - 説æ: JWT ã®æå·åããã³çœ²åã«äœ¿çšããç§å¯éµïŒããŒã¯ã³æ€èšŒã«äœ¿çšïŒ
- å¿ é : æ¬çªç°å¢ã§ã¯å¿ é
- åããããã£:
authEncSecret: JWT ãã€ããŒãæå·åã®ç§å¯éµauthSignSecret: JWT çœ²åæ€èšŒã®ç§å¯éµ
ð¥ ãŠãŒã¶ãŒçš®å¥èšå®â
identity.typeIds - ãŠãŒã¶ãŒçš®å¥èå¥åã®èšå®
- å:
{ admin?: string; guest?: string; regular?: string } - 説æ: ããŒã«ããŒã¹ã¢ã¯ã»ã¹å¶åŸ¡ã®ããã®ã«ã¹ã¿ã ãŠãŒã¶ãŒçš®å¥èå¥å
- ããã©ã«ã:
undefinedïŒããã©ã«ãã®çš®å¥æ€èšŒã䜿çšïŒ - åããããã£:
admin: 管çè ãŠãŒã¶ãŒçš®å¥ã®èå¥å- å:
string - 説æ: 管çè ãŠãŒã¶ãŒã®ã«ã¹ã¿ã èå¥å
- å©çšäŸ: 管çæäœã®ããŒã«ããŒã¹ã¢ã¯ã»ã¹å¶åŸ¡
- äŸ:
"admin","administrator","superuser"
- å:
guest: ã²ã¹ããŠãŒã¶ãŒçš®å¥ã®èå¥å- å:
string - 説æ: ã²ã¹ããŠãŒã¶ãŒã®ã«ã¹ã¿ã èå¥å
- å©çšäŸ: æªèªèšŒ/äžæãŠãŒã¶ãŒã®éå®çã¢ã¯ã»ã¹
- äŸ:
"guest","visitor","anonymous"
- å:
regular: äžè¬ãŠãŒã¶ãŒçš®å¥ã®èå¥å- å:
string - 説æ: äžè¬ãŠãŒã¶ãŒã®ã«ã¹ã¿ã èå¥å
- å©çšäŸ: æšæºçãªãŠãŒã¶ãŒæš©é
- äŸ:
"user","member","customer"
- å:
èšå®äŸâ
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圢åŒã§è¿ãããŸãïŒ
代衚çãªãšã©ãŒã³ãŒãâ
| ã¹ããŒã¿ã¹ | ãšã©ãŒã¡ãã»ãŒãž | 説æ |
|---|---|---|
| 400 | Identity data is required | æŽæ°ãªã¯ãšã¹ãã®ããã£ã空 |
| 400 | Failed to update identity | æŽæ°æäœã§ããŒã¿ã倿ŽãããªãïŒå€æŽãªãïŒ |
| 401 | token could not be verified | èªå¯ããŒã¯ã³ããªã/ç¡å¹ |
| 403 | Identity is not authorized to access this resource | èŠæ±æäœã«å¿ èŠãªæš©éãäžè¶³ |
| 404 | Identity not found | GET/PATCH/DELETE/LOCK/UNLOCK ã®å¯Ÿè±¡ã¢ã€ãã³ãã£ãã£ãååšããªã |
| 500 | Failed to get identity | ååŸäžã®DBæ¥ç¶åé¡/äºæãã¬å€±æ |
| 500 | Failed to find identities | äžèЧååŸäžã®DBæ¥ç¶åé¡/ãã£ã«ã¿äžæ£/äºæãã¬å€±æ |
| 500 | Failed to update identity | æŽæ°äžã®DBæ¥ç¶åé¡/äºæãã¬å€±æ |
| 500 | Failed to delete identity | åé€äžã®DBæ¥ç¶åé¡/äºæãã¬å€±æ |
ãšã©ãŒã¬ã¹ãã³ã¹åœ¢åŒâ
{
"error": {
"message": "Error message description",
"data": ["Additional error details"]
}
}
ð é¢é£ããã¥ã¡ã³ãâ
- ãšã©ãŒãã³ããªã³ã° - ãšã©ãŒãã¿ãŒã³ã®çè§£
- ã¹ããŒãã³ã³ããŒãã³ã - ããŒã¿æ€èšŒã®æŠå¿µ
- ã«ã¹ã¿ã ãµãŒãã¹ãã¥ãŒããªã¢ã« - ç¬èªãµãŒãã¹ã®æ§ç¯
- ãããã£ãŒã«ãµãŒãã¹ - ãããã£ãŒã«ç®¡çãµãŒãã¹