Skip to content

Commit 408c2e3

Browse files
feat: login endpoint
1 parent f26e7c1 commit 408c2e3

25 files changed

+940
-61
lines changed

.vscode/launch.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch Package",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "auto",
12+
"program": "${workspaceFolder}"
13+
}
14+
]
15+
}

docs/docs.go

+166-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,66 @@ const docTemplate = `{
99
"info": {
1010
"description": "{{escape .Description}}",
1111
"title": "{{.Title}}",
12+
"termsOfService": "https://github.com/DoWithLogic/go-rbac",
1213
"contact": {},
1314
"version": "{{.Version}}"
1415
},
1516
"host": "{{.Host}}",
1617
"basePath": "{{.BasePath}}",
1718
"paths": {
19+
"/login": {
20+
"post": {
21+
"description": "Login",
22+
"consumes": [
23+
"application/json"
24+
],
25+
"produces": [
26+
"application/json"
27+
],
28+
"tags": [
29+
"Users"
30+
],
31+
"summary": "Login",
32+
"operationId": "login",
33+
"parameters": [
34+
{
35+
"description": "Login Object",
36+
"name": "body",
37+
"in": "body",
38+
"required": true,
39+
"schema": {
40+
"$ref": "#/definitions/dtos.LoginRequest"
41+
}
42+
}
43+
],
44+
"responses": {
45+
"200": {
46+
"description": "SUCCESS",
47+
"schema": {
48+
"allOf": [
49+
{
50+
"$ref": "#/definitions/response.Success"
51+
},
52+
{
53+
"type": "object",
54+
"properties": {
55+
"data": {
56+
"$ref": "#/definitions/dtos.LoginResponse"
57+
}
58+
}
59+
}
60+
]
61+
}
62+
},
63+
"500": {
64+
"description": "INTERNAL_SERVER__ERROR",
65+
"schema": {
66+
"$ref": "#/definitions/response.FailedResponse"
67+
}
68+
}
69+
}
70+
}
71+
},
1872
"/users": {
1973
"post": {
2074
"security": [
@@ -63,6 +117,21 @@ const docTemplate = `{
63117
}
64118
},
65119
"definitions": {
120+
"constants.Permission": {
121+
"type": "string",
122+
"enum": [
123+
"users:read",
124+
"users:update",
125+
"users:create",
126+
"users:delete"
127+
],
128+
"x-enum-varnames": [
129+
"UsersReadPermission",
130+
"UsersUpdatePermission",
131+
"UsersCreatePermission",
132+
"UsersDeletePermission"
133+
]
134+
},
66135
"constants.ResponseMessage": {
67136
"type": "string",
68137
"enum": [
@@ -122,6 +191,72 @@ const docTemplate = `{
122191
}
123192
}
124193
},
194+
"dtos.LoginData": {
195+
"type": "object",
196+
"properties": {
197+
"created_at": {
198+
"type": "string"
199+
},
200+
"email": {
201+
"type": "string"
202+
},
203+
"id": {
204+
"type": "string"
205+
},
206+
"permissions": {
207+
"type": "array",
208+
"items": {
209+
"$ref": "#/definitions/dtos.UserPermission"
210+
}
211+
},
212+
"role": {
213+
"$ref": "#/definitions/constants.UserRole"
214+
},
215+
"role_id": {
216+
"type": "string"
217+
},
218+
"updated_at": {
219+
"type": "string"
220+
}
221+
}
222+
},
223+
"dtos.LoginRequest": {
224+
"type": "object",
225+
"required": [
226+
"email",
227+
"password"
228+
],
229+
"properties": {
230+
"email": {
231+
"type": "string"
232+
},
233+
"password": {
234+
"type": "string"
235+
}
236+
}
237+
},
238+
"dtos.LoginResponse": {
239+
"type": "object",
240+
"properties": {
241+
"access_token": {
242+
"type": "string"
243+
},
244+
"user": {
245+
"$ref": "#/definitions/dtos.LoginData"
246+
}
247+
}
248+
},
249+
"dtos.UserPermission": {
250+
"type": "object",
251+
"properties": {
252+
"permission": {
253+
"$ref": "#/definitions/constants.Permission"
254+
},
255+
"permission_id": {
256+
"type": "string"
257+
}
258+
}
259+
},
125260
"response.FailedResponse": {
126261
"type": "object",
127262
"properties": {
@@ -163,6 +298,34 @@ const docTemplate = `{
163298
"example": "success"
164299
}
165300
}
301+
},
302+
"response.Success": {
303+
"type": "object",
304+
"properties": {
305+
"code": {
306+
"description": "HTTP status code.",
307+
"type": "integer",
308+
"example": 200
309+
},
310+
"data": {
311+
"description": "data payload."
312+
},
313+
"message": {
314+
"allOf": [
315+
{
316+
"$ref": "#/definitions/constants.ResponseMessage"
317+
}
318+
],
319+
"example": "success"
320+
}
321+
}
322+
}
323+
},
324+
"securityDefinitions": {
325+
"BearerToken": {
326+
"type": "apiKey",
327+
"name": "Authorization",
328+
"in": "header"
166329
}
167330
}
168331
}`
@@ -171,10 +334,10 @@ const docTemplate = `{
171334
var SwaggerInfo = &swag.Spec{
172335
Version: "",
173336
Host: "",
174-
BasePath: "",
337+
BasePath: "/api/v1/rbac",
175338
Schemes: []string{},
176-
Title: "",
177-
Description: "",
339+
Title: "Go Role and Scope Based Access Control (RBAC)",
340+
Description: "## About\n\nThe **go-rbac** repository is a robust, Golang-based system for implementing and managing role and scope based access control (RBAC) within your organization. It provides a framework to define user roles, permissions, and associated access controls to protect resources and ensure that only authorized users can access specific features or perform certain actions.\n\n## Overview\n\n- **Purpose:** The go-rbac system is designed to simplify the management of user roles, permissions, and access controls within your application, making it easier to implement security policies.\n- **Technology Stack:** Developed in Golang, leveraging lightweight libraries to ensure high performance and scalability.\n- **Data Management:** Implements user roles, permissions, and role-permission mappings in a structured way to easily enforce security policies.\n- **Scalability:** Supports multiple roles and permissions, designed to scale with growing organizational needs.\n- **Security:** Ensures fine-grained access control with role-based permissions and JWT authentication, safeguarding critical resources.\n- **Integration:** Easily integrates with existing authentication systems, APIs, and services within your organization.\n\n## Key Components\n\n- **User Role Model:** Defines the structure and attributes of user roles, including standard roles like Admin, Employee, and Customer.\n- **Permissions Model:** Defines the various permissions (scopes) users can have based on their roles.\n- **Role-Permission Mapping:** Links specific roles to allowed permissions, ensuring users with the appropriate roles can perform specific actions.\n- **JWT Authentication:** Secure access to the API using JWT tokens, with support for role and permission validation.\n- **API Endpoints:** Exposes various endpoints to manage users, roles, and permissions, ensuring access control via role validation.\n\n## API Documentation\n\n### Overview\nThis repository provides a set of API endpoints for managing roles, permissions, and user access. The API allows you to create, update, retrieve, and delete roles, permissions, and role-permission mappings. It also supports secure JWT-based authentication to enforce role-based access control.\n\n### Explore Swagger Documentation\nFor a detailed description of all the available API endpoints, request/response formats, and examples, explore our Swagger documentation at the following link:\n\n- [Swagger Documentation](http://localhost:3002/swagger/index.html)\n\nThe Swagger documentation will provide detailed information on:\n- **Available Endpoints**: All API routes for managing users, roles, permissions, and access control.\n- **Request/Response Formats**: Detailed format for the expected input and output of each API endpoint.\n- **Authentication**: How to authenticate requests using JWT tokens.\n- **Role and Permission Validation**: How roles and permissions are validated for each endpoint.\n\n### Contact\n\nFor any questions or support related to go-rbac, please create issue contact at `[email protected]`.\n\n### Swagger Documentation\n\nExplore our Swagger documentation for a comprehensive overview of the available endpoints, request/response formats, and examples. Access the documentation at `https://{{base-url}}/swagger/index.html`.\n\n",
178341
InfoInstanceName: "swagger",
179342
SwaggerTemplate: docTemplate,
180343
LeftDelim: "{{",

0 commit comments

Comments
 (0)