Skip to content

Commit 40d627e

Browse files
committed
feat: add admin HTTP Basic Auth for course operations
- Add Basic Auth to Create Course endpoint - Add Basic Auth to Update Course endpoint - Add Basic Auth to Delete Course endpoint - Document auth requirements in API specs
1 parent 24cb312 commit 40d627e

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

openapi.json

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@
6363
"500": {
6464
"description": "Failed to create course"
6565
}
66-
}
66+
},
67+
"security": [
68+
{
69+
"AdminBasicAuth": []
70+
}
71+
]
6772
}
6873
},
6974
"/v1/courses/{slug}": {
@@ -130,7 +135,12 @@
130135
"500": {
131136
"description": "Failed to delete course"
132137
}
133-
}
138+
},
139+
"security": [
140+
{
141+
"AdminBasicAuth": []
142+
}
143+
]
134144
},
135145
"patch": {
136146
"tags": [
@@ -159,7 +169,12 @@
159169
"500": {
160170
"description": "Failed to update course"
161171
}
162-
}
172+
},
173+
"security": [
174+
{
175+
"AdminBasicAuth": []
176+
}
177+
]
163178
}
164179
},
165180
"/v1/courses/{slug}/attempts": {
@@ -1290,6 +1305,10 @@
12901305
}
12911306
},
12921307
"securitySchemes": {
1308+
"AdminBasicAuth": {
1309+
"type": "http",
1310+
"scheme": "basic"
1311+
},
12931312
"JWTBearerAuth": {
12941313
"type": "http",
12951314
"scheme": "bearer",

src/handler/course.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use tracing::{error, info};
3030
use crate::{
3131
context::Context,
3232
errors::Result,
33-
extractor::Claims,
33+
extractor::{AdminBasic, Claims},
3434
request::{CreateCourseRequest, CreateUserCourseRequest, UpdateUserCourseRequest},
3535
response::{AttemptResponse, CourseDetailResponse, CourseResponse, UserCourseResponse},
3636
service::CourseService,
@@ -64,9 +64,11 @@ pub async fn find(State(ctx): State<Arc<Context>>) -> Result<impl IntoResponse>
6464
(status = 201, description = "Course created successfully", body = CourseResponse),
6565
(status = 500, description = "Failed to create course")
6666
),
67+
security(("AdminBasicAuth" = [])),
6768
tag = "Course"
6869
)]
6970
pub async fn create(
71+
_: AdminBasic,
7072
State(ctx): State<Arc<Context>>,
7173
Json(req): Json<CreateCourseRequest>,
7274
) -> Result<impl IntoResponse> {
@@ -106,9 +108,11 @@ pub async fn get(
106108
(status = 404, description = "Course not found"),
107109
(status = 500, description = "Failed to delete course")
108110
),
111+
security(("AdminBasicAuth" = [])),
109112
tag = "Course"
110113
)]
111114
pub async fn delete(
115+
_: AdminBasic,
112116
State(ctx): State<Arc<Context>>,
113117
Path(slug): Path<String>,
114118
) -> Result<impl IntoResponse> {
@@ -128,9 +132,11 @@ pub async fn delete(
128132
(status = 404, description = "Course not found"),
129133
(status = 500, description = "Failed to update course")
130134
),
135+
security(("AdminBasicAuth" = [])),
131136
tag = "Course"
132137
)]
133138
pub async fn update(
139+
_: AdminBasic,
134140
State(ctx): State<Arc<Context>>,
135141
Path(slug): Path<String>,
136142
) -> Result<impl IntoResponse> {

src/swagger.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ impl Modify for SecurityAddon {
9090
SecurityScheme::Http(
9191
HttpBuilder::new().scheme(HttpAuthScheme::Bearer).bearer_format("JWT").build(),
9292
),
93+
);
94+
95+
components.add_security_scheme(
96+
"AdminBasicAuth",
97+
SecurityScheme::Http(HttpBuilder::new().scheme(HttpAuthScheme::Basic).build()),
9398
)
9499
}
95100
}

0 commit comments

Comments
 (0)