From 855620cb676409a23b2a49ec6b3631f0a1f3865c Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Sun, 9 Mar 2025 14:26:04 +0100 Subject: [PATCH] feat: Configureer auth Swagger --- backend/src/routes/auth.ts | 3 ++ docs/api/generate.ts | 32 +++++++++++++- docs/api/swagger.json | 91 +++++++++++++++++++++++++++++++++++++- idp/student-realm.json | 2 +- idp/teacher-realm.json | 2 +- 5 files changed, 125 insertions(+), 5 deletions(-) diff --git a/backend/src/routes/auth.ts b/backend/src/routes/auth.ts index 57af3a7d..0ab5b210 100644 --- a/backend/src/routes/auth.ts +++ b/backend/src/routes/auth.ts @@ -9,14 +9,17 @@ router.get('/config', (req, res) => { }); router.get('/testAuthenticatedOnly', authenticatedOnly, (req, res) => { + /* #swagger.security = [{ "student": [ ] }, { "teacher": [ ] }] */ res.json({message: "If you see this, you should be authenticated!"}); }); router.get('/testStudentsOnly', studentsOnly, (req, res) => { + /* #swagger.security = [{ "student": [ ] }] */ res.json({message: "If you see this, you should be a student!"}); }); router.get('/testTeachersOnly', teachersOnly, (req, res) => { + /* #swagger.security = [{ "teacher": [ ] }] */ res.json({message: "If you see this, you should be a teacher!"}); }); diff --git a/docs/api/generate.ts b/docs/api/generate.ts index 737619bb..695f30e1 100644 --- a/docs/api/generate.ts +++ b/docs/api/generate.ts @@ -17,7 +17,37 @@ const doc = { { url: 'https://sel2-1.ugent.be/api' } - ] + ], + components: { + securitySchemes: { + student: { + type: 'oauth2', + flows: { + implicit: { + authorizationUrl: 'http://localhost:7080/realms/student/protocol/openid-connect/auth', + scopes: { + openid: 'openid', + profile: 'profile', + email: 'email' + } + } + } + }, + teacher: { + type: 'oauth2', + flows: { + implicit: { + authorizationUrl: 'http://localhost:7080/realms/teacher/protocol/openid-connect/auth', + scopes: { + openid: 'openid', + profile: 'profile', + email: 'email' + } + } + } + } + } + } }; const outputFile = './swagger.json'; diff --git a/docs/api/swagger.json b/docs/api/swagger.json index 4f231cbd..85039f09 100644 --- a/docs/api/swagger.json +++ b/docs/api/swagger.json @@ -520,10 +520,10 @@ } } }, - "/login/": { + "/auth/config": { "get": { "tags": [ - "Login" + "Auth" ], "description": "", "responses": { @@ -533,6 +533,63 @@ } } }, + "/auth/testAuthenticatedOnly": { + "get": { + "tags": [ + "Auth" + ], + "description": "", + "responses": { + "200": { + "description": "OK" + } + }, + "security": [ + { + "student": [] + }, + { + "teacher": [] + } + ] + } + }, + "/auth/testStudentsOnly": { + "get": { + "tags": [ + "Auth" + ], + "description": "", + "responses": { + "200": { + "description": "OK" + } + }, + "security": [ + { + "student": [] + } + ] + } + }, + "/auth/testTeachersOnly": { + "get": { + "tags": [ + "Auth" + ], + "description": "", + "responses": { + "200": { + "description": "OK" + } + }, + "security": [ + { + "teacher": [] + } + ] + } + }, "/theme/": { "get": { "tags": [ @@ -708,5 +765,35 @@ } } } + }, + "components": { + "securitySchemes": { + "student": { + "type": "oauth2", + "flows": { + "implicit": { + "authorizationUrl": "http://localhost:7080/realms/student/protocol/openid-connect/auth", + "scopes": { + "openid": "openid", + "profile": "profile", + "email": "email" + } + } + } + }, + "teacher": { + "type": "oauth2", + "flows": { + "implicit": { + "authorizationUrl": "http://localhost:7080/realms/teacher/protocol/openid-connect/auth", + "scopes": { + "openid": "openid", + "profile": "profile", + "email": "email" + } + } + } + } + } } } \ No newline at end of file diff --git a/idp/student-realm.json b/idp/student-realm.json index 7b6bc94b..15cbc666 100644 --- a/idp/student-realm.json +++ b/idp/student-realm.json @@ -551,7 +551,7 @@ "enabled" : true, "alwaysDisplayInConsole" : false, "clientAuthenticatorType" : "client-jwt", - "redirectUris" : [ "urn:ietf:wg:oauth:2.0:oob", "http://localhost:5173/*", "http://localhost:5173" ], + "redirectUris" : [ "urn:ietf:wg:oauth:2.0:oob", "http://localhost:5173/*", "http://localhost:5173", "http://localhost:3000/api-docs/oauth2-redirect.html" ], "webOrigins" : [ "+" ], "notBefore" : 0, "bearerOnly" : false, diff --git a/idp/teacher-realm.json b/idp/teacher-realm.json index f1bc513a..b5e88c22 100644 --- a/idp/teacher-realm.json +++ b/idp/teacher-realm.json @@ -551,7 +551,7 @@ "enabled" : true, "alwaysDisplayInConsole" : false, "clientAuthenticatorType" : "client-secret", - "redirectUris" : [ "urn:ietf:wg:oauth:2.0:oob", "http://localhost:5173/*", "http://localhost:5173" ], + "redirectUris" : [ "urn:ietf:wg:oauth:2.0:oob", "http://localhost:5173/*", "http://localhost:5173", "http://localhost:3000/api-docs/oauth2-redirect.html" ], "webOrigins" : [ "+" ], "notBefore" : 0, "bearerOnly" : false,