{
  "info": {
    "name": "Mock Nafath Authentication API",
    "description": "Postman collection for testing mock Nafath authentication endpoints",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "_postman_id": "mock-nafath-auth-collection",
    "_exporter_id": "mock-nafath-exporter"
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "http://localhost:8000",
      "type": "string"
    },
    {
      "key": "attempt_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "attempt_token",
      "value": "",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "OIDC Flow",
      "item": [
        {
          "name": "1. Start Authentication",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"locale\": \"ar\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/start",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "auth", "nafath", "mock", "start"]
            },
            "description": "Start OIDC authentication flow"
          },
          "response": [],
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "var jsonData = pm.response.json();",
                  "if (jsonData.data && jsonData.data.attempt_id) {",
                  "    pm.environment.set(\"attempt_id\", jsonData.data.attempt_id);",
                  "}",
                  "if (jsonData.data && jsonData.data.attempt_token) {",
                  "    pm.environment.set(\"attempt_token\", jsonData.data.attempt_token);",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ]
        },
        {
          "name": "2. Complete Callback",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"state\": \"{{attempt_id}}\",\n  \"auto_complete\": true\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/callback",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "auth", "nafath", "mock", "callback"]
            },
            "description": "Simulate Nafath callback completion"
          },
          "response": []
        },
        {
          "name": "3. Check Status",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-Nafath-Attempt-Token",
                "value": "{{attempt_token}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/status/{{attempt_id}}",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "auth", "nafath", "mock", "status", "{{attempt_id}}"]
            },
            "description": "Check authentication status"
          },
          "response": []
        },
        {
          "name": "4. Get API Token",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"attempt_token\": \"{{attempt_token}}\",\n  \"device_name\": \"Postman Test Device\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/token/{{attempt_id}}",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "auth", "nafath", "mock", "token", "{{attempt_id}}"]
            },
            "description": "Exchange authenticated attempt for API token"
          },
          "response": [],
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "var jsonData = pm.response.json();",
                  "if (jsonData.data && jsonData.data.token) {",
                  "    pm.environment.set(\"api_token\", jsonData.data.token);",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ]
        }
      ]
    },
    {
      "name": "MFA Flow",
      "item": [
        {
          "name": "1. Start MFA Authentication",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"national_id\": \"1234567890\",\n  \"locale\": \"ar\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/start",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "auth", "nafath", "mock", "start"]
            },
            "description": "Start MFA authentication flow with national ID"
          },
          "response": [],
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "var jsonData = pm.response.json();",
                  "if (jsonData.data && jsonData.data.attempt_id) {",
                  "    pm.environment.set(\"attempt_id\", jsonData.data.attempt_id);",
                  "}",
                  "if (jsonData.data && jsonData.data.attempt_token) {",
                  "    pm.environment.set(\"attempt_token\", jsonData.data.attempt_token);",
                  "}",
                  "if (jsonData.data && jsonData.data.random) {",
                  "    pm.environment.set(\"mfa_random\", jsonData.data.random);",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ]
        },
        {
          "name": "2. Complete MFA",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"attempt_id\": \"{{attempt_id}}\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/complete-mfa",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "auth", "nafath", "mock", "complete-mfa"]
            },
            "description": "Simulate MFA completion after mobile approval"
          },
          "response": []
        },
        {
          "name": "3. Check Status",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-Nafath-Attempt-Token",
                "value": "{{attempt_token}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/status/{{attempt_id}}",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "auth", "nafath", "mock", "status", "{{attempt_id}}"]
            },
            "description": "Check MFA authentication status"
          },
          "response": []
        },
        {
          "name": "4. Get API Token",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"attempt_token\": \"{{attempt_token}}\",\n  \"device_name\": \"Postman MFA Device\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/token/{{attempt_id}}",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "auth", "nafath", "mock", "token", "{{attempt_id}}"]
            },
            "description": "Exchange authenticated MFA attempt for API token"
          },
          "response": [],
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "var jsonData = pm.response.json();",
                  "if (jsonData.data && jsonData.data.token) {",
                  "    pm.environment.set(\"api_token\", jsonData.data.token);",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ]
        }
      ]
    },
    {
      "name": "Individual Endpoints",
      "item": [
        {
          "name": "Start Authentication",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"locale\": \"ar\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/start",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "auth", "nafath", "mock", "start"]
            },
            "description": "Start Nafath authentication (OIDC or MFA based on national_id presence)"
          },
          "response": [
            {
              "name": "OIDC Flow Success",
              "originalRequest": {
                "method": "POST",
                "header": [],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"locale\": \"ar\"\n}"
                },
                "url": {
                  "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/start",
                  "host": ["{{baseUrl}}"],
                  "path": ["api", "v1", "auth", "nafath", "mock", "start"]
                }
              },
              "status": "Created",
              "code": 201,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"data\": {\n    \"attempt_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n    \"attempt_token\": \"abc123xyz456def789ghi012jkl345mno678pqr901stu234vwx567yz\",\n    \"authorization_url\": \"http://localhost:8000/api/v1/auth/nafath/mock/callback?state=550e8400-e29b-41d4-a716-446655440000\",\n    \"expires_at\": \"2025-01-01T12:00:00+00:00\"\n  }\n}"
            },
            {
              "name": "MFA Flow Success",
              "originalRequest": {
                "method": "POST",
                "header": [],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"national_id\": \"1234567890\",\n  \"locale\": \"ar\"\n}"
                },
                "url": {
                  "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/start",
                  "host": ["{{baseUrl}}"],
                  "path": ["api", "v1", "auth", "nafath", "mock", "start"]
                }
              },
              "status": "Created",
              "code": 201,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"data\": {\n    \"attempt_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n    \"attempt_token\": \"abc123xyz456def789ghi012jkl345mno678pqr901stu234vwx567yz\",\n    \"random\": \"123456\",\n    \"expires_at\": \"2025-01-01T12:00:00+00:00\"\n  }\n}"
            }
          ]
        },
        {
          "name": "Check Status",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-Nafath-Attempt-Token",
                "value": "{{attempt_token}}",
                "description": "Attempt token from start endpoint"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/status/:attempt_id",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "auth", "nafath", "mock", "status", ":attempt_id"],
              "variable": [
                {
                  "key": "attempt_id",
                  "value": "{{attempt_id}}",
                  "description": "Authentication attempt ID"
                }
              ]
            },
            "description": "Check the current status of authentication attempt"
          },
          "response": [
            {
              "name": "Pending Status",
              "originalRequest": {
                "method": "GET",
                "header": [],
                "url": {
                  "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/status/550e8400-e29b-41d4-a716-446655440000",
                  "host": ["{{baseUrl}}"],
                  "path": ["api", "v1", "auth", "nafath", "mock", "status", "550e8400-e29b-41d4-a716-446655440000"]
                }
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"data\": {\n    \"attempt_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n    \"status\": \"pending\",\n    \"provider_status\": \"PENDING\",\n    \"message\": null,\n    \"token_ready\": false,\n    \"user\": null\n  }\n}"
            },
            {
              "name": "Authenticated Status",
              "originalRequest": {
                "method": "GET",
                "header": [],
                "url": {
                  "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/status/550e8400-e29b-41d4-a716-446655440000",
                  "host": ["{{baseUrl}}"],
                  "path": ["api", "v1", "auth", "nafath", "mock", "status", "550e8400-e29b-41d4-a716-446655440000"]
                }
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"data\": {\n    \"attempt_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n    \"status\": \"authenticated\",\n    \"provider_status\": \"COMPLETED\",\n    \"message\": null,\n    \"token_ready\": true,\n    \"user\": {\n      \"id\": 1,\n      \"national_id\": \"1234567890\",\n      \"name\": \"Mock User\",\n      \"arabic_name\": \"مستخدم تجريبي\",\n      \"english_name\": \"Mock User\",\n      \"preferred_locale\": \"ar\",\n      \"nationality\": \"SA\",\n      \"gender\": \"M\",\n      \"assurance_level\": 3,\n      \"last_auth_method\": \"nafath\"\n    }\n  }\n}"
            }
          ]
        },
        {
          "name": "Complete Callback",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"state\": \"{{attempt_id}}\",\n  \"auto_complete\": true\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/callback",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "auth", "nafath", "mock", "callback"]
            },
            "description": "Simulate Nafath callback for OIDC flow"
          },
          "response": [
            {
              "name": "Callback Success",
              "originalRequest": {
                "method": "POST",
                "header": [],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"state\": \"550e8400-e29b-41d4-a716-446655440000\",\n  \"auto_complete\": true\n}"
                },
                "url": {
                  "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/callback",
                  "host": ["{{baseUrl}}"],
                  "path": ["api", "v1", "auth", "nafath", "mock", "callback"]
                }
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"success\": true,\n  \"message\": \"Mock authentication completed successfully\",\n  \"attempt_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n  \"redirect_to\": \"http://localhost:8000/dashboard\"\n}"
            }
          ]
        },
        {
          "name": "Complete MFA",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"attempt_id\": \"{{attempt_id}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/complete-mfa",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "auth", "nafath", "mock", "complete-mfa"]
            },
            "description": "Simulate MFA completion for mobile flow"
          },
          "response": [
            {
              "name": "MFA Success",
              "originalRequest": {
                "method": "POST",
                "header": [],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"attempt_id\": \"550e8400-e29b-41d4-a716-446655440000\"\n}"
                },
                "url": {
                  "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/complete-mfa",
                  "host": ["{{baseUrl}}"],
                  "path": ["api", "v1", "auth", "nafath", "mock", "complete-mfa"]
                }
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"success\": true,\n  \"message\": \"Mock MFA completed successfully\",\n  \"attempt_id\": \"550e8400-e29b-41d4-a716-446655440000\"\n}"
            }
          ]
        },
        {
          "name": "Get API Token",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"attempt_token\": \"{{attempt_token}}\",\n  \"device_name\": \"Test Device\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/token/:attempt_id",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "auth", "nafath", "mock", "token", ":attempt_id"],
              "variable": [
                {
                  "key": "attempt_id",
                  "value": "{{attempt_id}}",
                  "description": "Authenticated attempt ID"
                }
              ]
            },
            "description": "Exchange authenticated attempt for API token"
          },
          "response": [
            {
              "name": "Token Success",
              "originalRequest": {
                "method": "POST",
                "header": [],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"attempt_token\": \"abc123xyz456def789ghi012jkl345mno678pqr901stu234vwx567yz\",\n  \"device_name\": \"Test Device\"\n}"
                },
                "url": {
                  "raw": "{{baseUrl}}/api/v1/auth/nafath/mock/token/550e8400-e29b-41d4-a716-446655440000",
                  "host": ["{{baseUrl}}"],
                  "path": ["api", "v1", "auth", "nafath", "mock", "token", "550e8400-e29b-41d4-a716-446655440000"]
                }
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"data\": {\n    \"token\": \"plain-api-token-string\",\n    \"token_type\": \"Bearer\",\n    \"expires_at\": \"2025-01-01T13:00:00+00:00\",\n    \"user\": {\n      \"id\": 1,\n      \"national_id\": \"1234567890\",\n      \"name\": \"Mock User\",\n      \"arabic_name\": \"مستخدم تجريبي\",\n      \"english_name\": \"Mock User\",\n      \"preferred_locale\": \"ar\",\n      \"nationality\": \"SA\",\n      \"gender\": \"M\",\n      \"assurance_level\": 3,\n      \"last_auth_method\": \"nafath\"\n    }\n  }\n}"
            }
          ]
        }
      ]
    }
  ]
}
