|
| 1 | +// Copyright 2025 The Gitea Authors. All rights reserved. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +package admin |
| 5 | + |
| 6 | +import ( |
| 7 | + "net/http" |
| 8 | + |
| 9 | + auth_model "code.gitea.io/gitea/models/auth" |
| 10 | + "code.gitea.io/gitea/models/db" |
| 11 | + api "code.gitea.io/gitea/modules/structs" |
| 12 | + "code.gitea.io/gitea/routers/api/v1/utils" |
| 13 | + "code.gitea.io/gitea/services/context" |
| 14 | + "code.gitea.io/gitea/services/convert" |
| 15 | +) |
| 16 | + |
| 17 | +// SearchAuth API for getting information of the configured authentication methods according the filter conditions |
| 18 | +func SearchAuth(ctx *context.APIContext) { |
| 19 | + // swagger:operation GET /admin/identity-auth admin adminSearchAuth |
| 20 | + // --- |
| 21 | + // summary: Search authentication sources |
| 22 | + // produces: |
| 23 | + // - application/json |
| 24 | + // parameters: |
| 25 | + // - name: page |
| 26 | + // in: query |
| 27 | + // description: page number of results to return (1-based) |
| 28 | + // type: integer |
| 29 | + // - name: limit |
| 30 | + // in: query |
| 31 | + // description: page size of results |
| 32 | + // type: integer |
| 33 | + // responses: |
| 34 | + // "200": |
| 35 | + // description: "SearchResults of authentication sources" |
| 36 | + // schema: |
| 37 | + // type: array |
| 38 | + // items: |
| 39 | + // "$ref": "#/definitions/AuthOauth2Option" |
| 40 | + // "403": |
| 41 | + // "$ref": "#/responses/forbidden" |
| 42 | + |
| 43 | + listOptions := utils.GetListOptions(ctx) |
| 44 | + |
| 45 | + authSources, maxResults, err := db.FindAndCount[auth_model.Source](ctx, auth_model.FindSourcesOptions{}) |
| 46 | + if err != nil { |
| 47 | + ctx.APIErrorInternal(err) |
| 48 | + return |
| 49 | + } |
| 50 | + |
| 51 | + results := make([]*api.AuthSourceOption, len(authSources)) |
| 52 | + for i := range authSources { |
| 53 | + results[i] = convert.ToOauthProvider(ctx, authSources[i]) |
| 54 | + } |
| 55 | + |
| 56 | + ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) |
| 57 | + ctx.SetTotalCountHeader(maxResults) |
| 58 | + ctx.JSON(http.StatusOK, &results) |
| 59 | +} |
0 commit comments