From 13b75917176819016f7c468eb068d0a708c81410 Mon Sep 17 00:00:00 2001 From: Tim Riedl Date: Tue, 29 Jul 2025 12:12:58 +0200 Subject: [PATCH] Add Swagger model annotations and new API routes for OAuth2 authentication management --- modules/structs/auth.go | 1 + modules/structs/auth_oauth2.go | 2 + routers/api/v1/admin/auth_oauth.go | 2 +- services/auth/source/oauth2/source.go | 2 +- templates/swagger/v1_json.tmpl | 203 +++++++++++++++++++++++++- 5 files changed, 207 insertions(+), 3 deletions(-) diff --git a/modules/structs/auth.go b/modules/structs/auth.go index 2ee85a7707..fcfe0cfaf9 100644 --- a/modules/structs/auth.go +++ b/modules/structs/auth.go @@ -3,6 +3,7 @@ package structs +// swagger:model type AuthSourceOption struct { ID int64 `json:"id"` AuthenticationName string `json:"authentication_name" binding:"Required"` diff --git a/modules/structs/auth_oauth2.go b/modules/structs/auth_oauth2.go index b23533fade..ee62b38669 100644 --- a/modules/structs/auth_oauth2.go +++ b/modules/structs/auth_oauth2.go @@ -4,6 +4,7 @@ package structs // CreateUserOption create user options +// swagger:model type CreateAuthOauth2Option struct { AuthenticationName string `json:"authentication_name" binding:"Required"` ProviderIconURL string `json:"provider_icon_url"` @@ -27,6 +28,7 @@ type CreateAuthOauth2Option struct { } // EditUserOption edit user options +// swagger:model type EditAuthOauth2Option struct { AuthenticationName string `json:"authentication_name" binding:"Required"` ProviderIconURL string `json:"provider_icon_url"` diff --git a/routers/api/v1/admin/auth_oauth.go b/routers/api/v1/admin/auth_oauth.go index 9bdf4b9556..b3fd3dc861 100644 --- a/routers/api/v1/admin/auth_oauth.go +++ b/routers/api/v1/admin/auth_oauth.go @@ -136,7 +136,7 @@ func EditOauthAuth(ctx *context.APIContext) { return } - form := web.GetForm(ctx).(*api.CreateAuthOauth2Option) + form := web.GetForm(ctx).(*api.EditAuthOauth2Option) config := &oauth2.Source{ Provider: "openidConnect", diff --git a/services/auth/source/oauth2/source.go b/services/auth/source/oauth2/source.go index 3454c9ad55..b446ab09ab 100644 --- a/services/auth/source/oauth2/source.go +++ b/services/auth/source/oauth2/source.go @@ -25,7 +25,7 @@ type Source struct { GroupTeamMap string GroupTeamMapRemoval bool RestrictedGroup string - SkipLocalTwoFA bool `json:",omitempty"` + SkipLocalTwoFA bool // reference to the authSource authSource *auth.Source diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 99d3c994f9..0bc30eec35 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -21,7 +21,7 @@ }, "version": "{{AppVer | JSEscape}}" }, - "basePath": "{{AppSubUrl | JSEscape}}/api/v1", + "basePath": "/{{AppSubUrl | JSEscape}}/api/v1", "paths": { "/activitypub/user-id/{user-id}": { "get": { @@ -472,6 +472,207 @@ } } }, + "/admin/identity-auth": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "Search authentication sources", + "operationId": "adminSearchAuth", + "parameters": [ + { + "type": "integer", + "description": "page number of results to return (1-based)", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "page size of results", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "SearchResults of authentication sources", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/AuthOauth2Option" + } + } + }, + "403": { + "$ref": "#/responses/forbidden" + } + } + } + }, + "/admin/identity-auth/oauth": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "Search OAuth2 authentication sources", + "operationId": "adminSearchOauth2Auth", + "parameters": [ + { + "type": "integer", + "description": "page number of results to return (1-based)", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "page size of results", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "description": "SearchResults of OAuth2 authentication sources", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/AuthOauth2Option" + } + } + }, + "403": { + "$ref": "#/responses/forbidden" + } + } + }, + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "Create an OAuth2 authentication source", + "operationId": "adminCreateOauth2Auth", + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/CreateAuthOauth2Option" + } + } + ], + "responses": { + "201": { + "description": "OAuth2 authentication source created successfully" + }, + "400": { + "$ref": "#/responses/error" + }, + "403": { + "$ref": "#/responses/forbidden" + }, + "422": { + "$ref": "#/responses/validationError" + } + } + } + }, + "/admin/identity-auth/oauth/{id}": { + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "Delete an OAuth2 authentication source", + "operationId": "adminDeleteOauth2Auth", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "authentication source ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OAuth2 authentication source deleted successfully" + }, + "403": { + "$ref": "#/responses/forbidden" + }, + "404": { + "$ref": "#/responses/notFound" + }, + "422": { + "$ref": "#/responses/validationError" + } + } + }, + "patch": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "Update an OAuth2 authentication source", + "operationId": "adminEditOauth2Auth", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "authentication source ID", + "name": "id", + "in": "path", + "required": true + }, + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/CreateAuthOauth2Option" + } + } + ], + "responses": { + "201": { + "description": "OAuth2 authentication source updated successfully" + }, + "400": { + "$ref": "#/responses/error" + }, + "403": { + "$ref": "#/responses/forbidden" + }, + "404": { + "$ref": "#/responses/notFound" + }, + "422": { + "$ref": "#/responses/validationError" + } + } + } + }, "/admin/orgs": { "get": { "produces": [