0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-11 02:54:05 +02:00

Add Swagger model annotations and new API routes for OAuth2 authentication management

This commit is contained in:
Tim Riedl 2025-07-29 12:12:58 +02:00
parent b58f94acd6
commit 13b7591717
No known key found for this signature in database
GPG Key ID: 172D6410FC4F844E
5 changed files with 207 additions and 3 deletions

View File

@ -3,6 +3,7 @@
package structs
// swagger:model
type AuthSourceOption struct {
ID int64 `json:"id"`
AuthenticationName string `json:"authentication_name" binding:"Required"`

View File

@ -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"`

View File

@ -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",

View File

@ -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

View File

@ -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": [