UNPKG

@wikiccu/nest-auth

Version:

A comprehensive authentication package for NestJS applications with Prisma and PostgreSQL

980 lines 34.5 kB
{ "info": { "name": "WikiCCU Auth API", "description": "Complete authentication API collection for WikiCCU NestJS Auth Service", "version": "2.0.1", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "variable": [ { "key": "baseUrl", "value": "http://localhost:3000", "type": "string" }, { "key": "accessToken", "value": "", "type": "string" }, { "key": "refreshToken", "value": "", "type": "string" } ], "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{accessToken}}", "type": "string" } ] }, "item": [ { "name": "Public Endpoints", "item": [ { "name": "Register User", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"email\": \"user@example.com\",\n \"password\": \"password123\",\n \"username\": \"johndoe\",\n \"firstName\": \"John\",\n \"lastName\": \"Doe\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/register", "host": ["{{baseUrl}}"], "path": ["auth", "register"] }, "description": "Register a new user account. Sends email verification automatically." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"email\": \"user@example.com\",\n \"password\": \"password123\",\n \"username\": \"johndoe\",\n \"firstName\": \"John\",\n \"lastName\": \"Doe\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/register", "host": ["{{baseUrl}}"], "path": ["auth", "register"] } }, "status": "Created", "code": 201, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"user\": {\n \"id\": \"123e4567-e89b-12d3-a456-426614174000\",\n \"email\": \"user@example.com\",\n \"username\": \"johndoe\",\n \"firstName\": \"John\",\n \"lastName\": \"Doe\",\n \"isEmailVerified\": false,\n \"isActive\": true,\n \"roles\": [\"user\"],\n \"permissions\": [\"read:own\"],\n \"createdAt\": \"2024-01-01T00:00:00.000Z\",\n \"updatedAt\": \"2024-01-01T00:00:00.000Z\"\n },\n \"message\": \"User registered successfully. Please check your email for verification.\"\n}" } ] }, { "name": "Login User", "event": [ { "listen": "test", "script": { "exec": [ "if (pm.response.code === 200) {", " const response = pm.response.json();", " pm.collectionVariables.set('accessToken', response.accessToken);", " pm.collectionVariables.set('refreshToken', response.refreshToken);", "}" ], "type": "text/javascript" } } ], "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"email\": \"user@example.com\",\n \"password\": \"password123\",\n \"rememberMe\": true\n}" }, "url": { "raw": "{{baseUrl}}/auth/login", "host": ["{{baseUrl}}"], "path": ["auth", "login"] }, "description": "Authenticate user and receive access and refresh tokens." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"email\": \"user@example.com\",\n \"password\": \"password123\",\n \"rememberMe\": true\n}" }, "url": { "raw": "{{baseUrl}}/auth/login", "host": ["{{baseUrl}}"], "path": ["auth", "login"] } }, "status": "OK", "code": 200, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"user\": {\n \"id\": \"123e4567-e89b-12d3-a456-426614174000\",\n \"email\": \"user@example.com\",\n \"username\": \"johndoe\",\n \"firstName\": \"John\",\n \"lastName\": \"Doe\",\n \"isEmailVerified\": true,\n \"isActive\": true,\n \"roles\": [\"user\"],\n \"permissions\": [\"read:own\"]\n },\n \"accessToken\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\",\n \"refreshToken\": \"refresh_token_here\",\n \"expiresIn\": 3600\n}" } ] }, { "name": "Refresh Token", "event": [ { "listen": "test", "script": { "exec": [ "if (pm.response.code === 200) {", " const response = pm.response.json();", " pm.collectionVariables.set('accessToken', response.accessToken);", " pm.collectionVariables.set('refreshToken', response.refreshToken);", "}" ], "type": "text/javascript" } } ], "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"refreshToken\": \"{{refreshToken}}\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/refresh", "host": ["{{baseUrl}}"], "path": ["auth", "refresh"] }, "description": "Get new access and refresh tokens using the current refresh token." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"refreshToken\": \"refresh_token_here\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/refresh", "host": ["{{baseUrl}}"], "path": ["auth", "refresh"] } }, "status": "OK", "code": 200, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"accessToken\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\",\n \"refreshToken\": \"new_refresh_token_here\",\n \"expiresIn\": 3600\n}" } ] }, { "name": "Forgot Password", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"email\": \"user@example.com\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/forgot-password", "host": ["{{baseUrl}}"], "path": ["auth", "forgot-password"] }, "description": "Request password reset email. Always returns success for security reasons." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"email\": \"user@example.com\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/forgot-password", "host": ["{{baseUrl}}"], "path": ["auth", "forgot-password"] } }, "status": "OK", "code": 200, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"message\": \"If an account with that email exists, a password reset email has been sent.\"\n}" } ] }, { "name": "Reset Password", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"token\": \"reset_token_from_email\",\n \"newPassword\": \"newpassword123\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/reset-password", "host": ["{{baseUrl}}"], "path": ["auth", "reset-password"] }, "description": "Reset password using token received via email." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"token\": \"reset_token_from_email\",\n \"newPassword\": \"newpassword123\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/reset-password", "host": ["{{baseUrl}}"], "path": ["auth", "reset-password"] } }, "status": "OK", "code": 200, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"message\": \"Password reset successfully\"\n}" } ] }, { "name": "Verify Email", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"token\": \"email_verification_token\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/verify-email", "host": ["{{baseUrl}}"], "path": ["auth", "verify-email"] }, "description": "Verify email address using token received via email." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"token\": \"email_verification_token\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/verify-email", "host": ["{{baseUrl}}"], "path": ["auth", "verify-email"] } }, "status": "OK", "code": 200, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"message\": \"Email verified successfully\"\n}" } ] }, { "name": "Resend Email Verification", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"email\": \"user@example.com\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/resend-verification", "host": ["{{baseUrl}}"], "path": ["auth", "resend-verification"] }, "description": "Resend email verification to user." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"email\": \"user@example.com\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/resend-verification", "host": ["{{baseUrl}}"], "path": ["auth", "resend-verification"] } }, "status": "OK", "code": 200, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"message\": \"Verification email sent successfully\"\n}" } ] } ] }, { "name": "Authenticated Endpoints", "item": [ { "name": "Get User Profile", "request": { "method": "GET", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" } ], "url": { "raw": "{{baseUrl}}/auth/profile", "host": ["{{baseUrl}}"], "path": ["auth", "profile"] }, "description": "Get current user profile information. Requires authentication." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "GET", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" } ], "url": { "raw": "{{baseUrl}}/auth/profile", "host": ["{{baseUrl}}"], "path": ["auth", "profile"] } }, "status": "OK", "code": 200, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"id\": \"123e4567-e89b-12d3-a456-426614174000\",\n \"email\": \"user@example.com\",\n \"username\": \"johndoe\",\n \"firstName\": \"John\",\n \"lastName\": \"Doe\",\n \"isEmailVerified\": true,\n \"isActive\": true,\n \"roles\": [\"user\"],\n \"permissions\": [\"read:own\"],\n \"createdAt\": \"2024-01-01T00:00:00.000Z\",\n \"updatedAt\": \"2024-01-01T00:00:00.000Z\"\n}" } ] }, { "name": "Update User Profile", "request": { "method": "PUT", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" }, { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"firstName\": \"Jane\",\n \"lastName\": \"Smith\",\n \"username\": \"janesmith\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/profile", "host": ["{{baseUrl}}"], "path": ["auth", "profile"] }, "description": "Update current user profile information. Requires authentication." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "PUT", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" }, { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"firstName\": \"Jane\",\n \"lastName\": \"Smith\",\n \"username\": \"janesmith\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/profile", "host": ["{{baseUrl}}"], "path": ["auth", "profile"] } }, "status": "OK", "code": 200, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"id\": \"123e4567-e89b-12d3-a456-426614174000\",\n \"email\": \"user@example.com\",\n \"username\": \"janesmith\",\n \"firstName\": \"Jane\",\n \"lastName\": \"Smith\",\n \"isEmailVerified\": true,\n \"isActive\": true,\n \"roles\": [\"user\"],\n \"permissions\": [\"read:own\"],\n \"createdAt\": \"2024-01-01T00:00:00.000Z\",\n \"updatedAt\": \"2024-01-01T00:00:00.000Z\"\n}" } ] }, { "name": "Change Password", "request": { "method": "PUT", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" }, { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"currentPassword\": \"oldpassword123\",\n \"newPassword\": \"newpassword123\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/change-password", "host": ["{{baseUrl}}"], "path": ["auth", "change-password"] }, "description": "Change current user password. Requires authentication and current password verification." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "PUT", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" }, { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"currentPassword\": \"oldpassword123\",\n \"newPassword\": \"newpassword123\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/change-password", "host": ["{{baseUrl}}"], "path": ["auth", "change-password"] } }, "status": "OK", "code": 200, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"message\": \"Password changed successfully\"\n}" } ] }, { "name": "Logout User", "request": { "method": "POST", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" }, { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"refreshToken\": \"{{refreshToken}}\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/logout", "host": ["{{baseUrl}}"], "path": ["auth", "logout"] }, "description": "Logout user by revoking the refresh token. Requires authentication." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "POST", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" }, { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"refreshToken\": \"{{refreshToken}}\"\n}" }, "url": { "raw": "{{baseUrl}}/auth/logout", "host": ["{{baseUrl}}"], "path": ["auth", "logout"] } }, "status": "OK", "code": 200, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"message\": \"Logged out successfully\"\n}" } ] } ] }, { "name": "Admin Endpoints", "item": [ { "name": "Get All Users", "request": { "method": "GET", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" } ], "url": { "raw": "{{baseUrl}}/auth/users?page=1&limit=10", "host": ["{{baseUrl}}"], "path": ["auth", "users"], "query": [ { "key": "page", "value": "1", "description": "Page number" }, { "key": "limit", "value": "10", "description": "Items per page" } ] }, "description": "Get paginated list of all users. Requires admin role." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "GET", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" } ], "url": { "raw": "{{baseUrl}}/auth/users?page=1&limit=10", "host": ["{{baseUrl}}"], "path": ["auth", "users"], "query": [ { "key": "page", "value": "1" }, { "key": "limit", "value": "10" } ] } }, "status": "OK", "code": 200, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"users\": [\n {\n \"id\": \"123e4567-e89b-12d3-a456-426614174000\",\n \"email\": \"user@example.com\",\n \"username\": \"johndoe\",\n \"firstName\": \"John\",\n \"lastName\": \"Doe\",\n \"isEmailVerified\": true,\n \"isActive\": true,\n \"roles\": [\"user\"],\n \"permissions\": [\"read:own\"],\n \"createdAt\": \"2024-01-01T00:00:00.000Z\",\n \"updatedAt\": \"2024-01-01T00:00:00.000Z\"\n }\n ],\n \"total\": 1,\n \"page\": 1,\n \"limit\": 10\n}" } ] }, { "name": "Create User (Admin)", "request": { "method": "POST", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" }, { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"email\": \"admin@example.com\",\n \"password\": \"adminpass123\",\n \"username\": \"adminuser\",\n \"firstName\": \"Admin\",\n \"lastName\": \"User\",\n \"roles\": [\"admin\"]\n}" }, "url": { "raw": "{{baseUrl}}/auth/users", "host": ["{{baseUrl}}"], "path": ["auth", "users"] }, "description": "Create a new user account (pre-verified). Requires admin role." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "POST", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" }, { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"email\": \"admin@example.com\",\n \"password\": \"adminpass123\",\n \"username\": \"adminuser\",\n \"firstName\": \"Admin\",\n \"lastName\": \"User\",\n \"roles\": [\"admin\"]\n}" }, "url": { "raw": "{{baseUrl}}/auth/users", "host": ["{{baseUrl}}"], "path": ["auth", "users"] } }, "status": "Created", "code": 201, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"id\": \"456e7890-e89b-12d3-a456-426614174001\",\n \"email\": \"admin@example.com\",\n \"username\": \"adminuser\",\n \"firstName\": \"Admin\",\n \"lastName\": \"User\",\n \"isEmailVerified\": true,\n \"isActive\": true,\n \"roles\": [\"admin\"],\n \"permissions\": [\"read:all\", \"write:all\"],\n \"createdAt\": \"2024-01-01T00:00:00.000Z\",\n \"updatedAt\": \"2024-01-01T00:00:00.000Z\"\n}" } ] }, { "name": "Update User (Admin)", "request": { "method": "PUT", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" }, { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"firstName\": \"Updated\",\n \"lastName\": \"Name\",\n \"isActive\": true,\n \"roles\": [\"user\", \"moderator\"]\n}" }, "url": { "raw": "{{baseUrl}}/auth/users/123e4567-e89b-12d3-a456-426614174000", "host": ["{{baseUrl}}"], "path": ["auth", "users", "123e4567-e89b-12d3-a456-426614174000"] }, "description": "Update user information including roles and active status. Requires admin role." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "PUT", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" }, { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"firstName\": \"Updated\",\n \"lastName\": \"Name\",\n \"isActive\": true,\n \"roles\": [\"user\", \"moderator\"]\n}" }, "url": { "raw": "{{baseUrl}}/auth/users/123e4567-e89b-12d3-a456-426614174000", "host": ["{{baseUrl}}"], "path": ["auth", "users", "123e4567-e89b-12d3-a456-426614174000"] } }, "status": "OK", "code": 200, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"id\": \"123e4567-e89b-12d3-a456-426614174000\",\n \"email\": \"user@example.com\",\n \"username\": \"johndoe\",\n \"firstName\": \"Updated\",\n \"lastName\": \"Name\",\n \"isEmailVerified\": true,\n \"isActive\": true,\n \"roles\": [\"user\", \"moderator\"],\n \"permissions\": [\"read:own\", \"moderate:content\"],\n \"createdAt\": \"2024-01-01T00:00:00.000Z\",\n \"updatedAt\": \"2024-01-01T00:00:00.000Z\"\n}" } ] }, { "name": "Delete User (Admin)", "request": { "method": "DELETE", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" } ], "url": { "raw": "{{baseUrl}}/auth/users/123e4567-e89b-12d3-a456-426614174000", "host": ["{{baseUrl}}"], "path": ["auth", "users", "123e4567-e89b-12d3-a456-426614174000"] }, "description": "Permanently delete a user account. Requires admin role." }, "response": [ { "name": "Success Response", "originalRequest": { "method": "DELETE", "header": [ { "key": "Authorization", "value": "Bearer {{accessToken}}" } ], "url": { "raw": "{{baseUrl}}/auth/users/123e4567-e89b-12d3-a456-426614174000", "host": ["{{baseUrl}}"], "path": ["auth", "users", "123e4567-e89b-12d3-a456-426614174000"] } }, "status": "OK", "code": 200, "_postman_previewlanguage": "json", "header": [ { "key": "Content-Type", "value": "application/json" } ], "cookie": [], "body": "{\n \"message\": \"User deleted successfully\"\n}" } ] } ] } ], "event": [ { "listen": "prerequest", "script": { "type": "text/javascript", "exec": [ "// Auto-set Authorization header for authenticated requests", "if (pm.request.headers.has('Authorization')) {", " const authHeader = pm.request.headers.get('Authorization');", " if (authHeader.value.includes('{{accessToken}}')) {", " const token = pm.collectionVariables.get('accessToken');", " if (token) {", " pm.request.headers.get('Authorization').value = `Bearer ${token}`;", " }", " }", "}" ] } } ] }