1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.Admin.OAuthAppOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10 import Pleroma.Web.ApiSpec.Helpers
12 def open_api_operation(action) do
13 operation = String.to_existing_atom("#{action}_operation")
14 apply(__MODULE__, operation, [])
17 def index_operation do
19 summary: "Retrieve a list of OAuth applications",
20 tags: ["OAuth application managment"],
21 operationId: "AdminAPI.OAuthAppController.index",
22 security: [%{"oAuth" => ["admin:write"]}],
24 Operation.parameter(:name, :query, %Schema{type: :string}, "App name"),
25 Operation.parameter(:client_id, :query, %Schema{type: :string}, "Client ID"),
26 Operation.parameter(:page, :query, %Schema{type: :integer, default: 1}, "Page"),
30 %Schema{type: :boolean, default: false},
36 %Schema{type: :integer, default: 50},
37 "Number of apps to return"
43 Operation.response("List of apps", "application/json", %Schema{
46 apps: %Schema{type: :array, items: oauth_app()},
47 count: %Schema{type: :integer},
48 page_size: %Schema{type: :integer}
55 "client_id" => "yHoDSiWYp5mPV6AfsaVOWjdOyt5PhWRiafi6MRd1lSk",
56 "client_secret" => "nLmis486Vqrv2o65eM9mLQx_m_4gH-Q6PcDpGIMl6FY",
57 "redirect_uri" => "https://example.com/oauth-callback",
58 "website" => "https://example.com",
70 def create_operation do
72 tags: ["OAuth application managment"],
73 summary: "Create an OAuth application",
74 operationId: "AdminAPI.OAuthAppController.create",
75 requestBody: request_body("Parameters", create_request()),
76 parameters: admin_api_params(),
77 security: [%{"oAuth" => ["admin:write"]}],
79 200 => Operation.response("App", "application/json", oauth_app()),
80 400 => Operation.response("Bad Request", "application/json", ApiError)
85 def update_operation do
87 tags: ["OAuth application managment"],
88 summary: "Update OAuth application",
89 operationId: "AdminAPI.OAuthAppController.update",
90 parameters: [id_param() | admin_api_params()],
91 security: [%{"oAuth" => ["admin:write"]}],
92 requestBody: request_body("Parameters", update_request()),
94 200 => Operation.response("App", "application/json", oauth_app()),
96 Operation.response("Bad Request", "application/json", %Schema{
97 oneOf: [ApiError, %Schema{type: :string}]
103 def delete_operation do
105 tags: ["OAuth application managment"],
106 summary: "Delete OAuth application",
107 operationId: "AdminAPI.OAuthAppController.delete",
108 parameters: [id_param() | admin_api_params()],
109 security: [%{"oAuth" => ["admin:write"]}],
111 204 => no_content_response(),
112 400 => no_content_response()
117 defp create_request do
119 title: "oAuthAppCreateRequest",
121 required: [:name, :redirect_uris],
123 name: %Schema{type: :string, description: "Application Name"},
124 scopes: %Schema{type: :array, items: %Schema{type: :string}, description: "oAuth scopes"},
125 redirect_uris: %Schema{
128 "Where the user should be redirected after authorization. To display the authorization code to the user instead of redirecting to a web page, use `urn:ietf:wg:oauth:2.0:oob` in this parameter."
133 description: "A URL to the homepage of the app"
139 description: "Is the app trusted?"
144 "redirect_uris" => "https://myapp.com/auth/callback",
145 "website" => "https://myapp.com/",
146 "scopes" => ["read", "write"],
152 defp update_request do
154 title: "oAuthAppUpdateRequest",
157 name: %Schema{type: :string, description: "Application Name"},
158 scopes: %Schema{type: :array, items: %Schema{type: :string}, description: "oAuth scopes"},
159 redirect_uris: %Schema{
162 "Where the user should be redirected after authorization. To display the authorization code to the user instead of redirecting to a web page, use `urn:ietf:wg:oauth:2.0:oob` in this parameter."
167 description: "A URL to the homepage of the app"
173 description: "Is the app trusted?"
178 "redirect_uris" => "https://myapp.com/auth/callback",
179 "website" => "https://myapp.com/",
180 "scopes" => ["read", "write"],
191 id: %Schema{type: :integer},
192 name: %Schema{type: :string},
193 client_id: %Schema{type: :string},
194 client_secret: %Schema{type: :string},
195 redirect_uri: %Schema{type: :string},
196 website: %Schema{type: :string, nullable: true},
197 trusted: %Schema{type: :boolean}
202 "client_id" => "TWhM-tNSuncnqN7DBJmoyeLnk6K3iJJ71KKXxgL1hPM",
203 "client_secret" => "ZEaFUFmF0umgBX1qKJDjaU99Q31lDkOU8NutzTOoliw",
204 "redirect_uri" => "https://myapp.com/oauth-callback",
205 "website" => "https://myapp.com/",
212 Operation.parameter(:id, :path, :integer, "App ID",