1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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: "List OAuth apps",
20 tags: ["Admin", "oAuth Apps"],
21 operationId: "AdminAPI.OAuthAppController.index",
22 security: [%{"oAuth" => ["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"
42 Operation.response("List of apps", "application/json", %Schema{
45 apps: %Schema{type: :array, items: oauth_app()},
46 count: %Schema{type: :integer},
47 page_size: %Schema{type: :integer}
54 "client_id" => "yHoDSiWYp5mPV6AfsaVOWjdOyt5PhWRiafi6MRd1lSk",
55 "client_secret" => "nLmis486Vqrv2o65eM9mLQx_m_4gH-Q6PcDpGIMl6FY",
56 "redirect_uri" => "https://example.com/oauth-callback",
57 "website" => "https://example.com",
69 def create_operation do
71 tags: ["Admin", "oAuth Apps"],
72 summary: "Create OAuth App",
73 operationId: "AdminAPI.OAuthAppController.create",
74 requestBody: request_body("Parameters", create_request()),
75 security: [%{"oAuth" => ["write"]}],
77 200 => Operation.response("App", "application/json", oauth_app()),
78 400 => Operation.response("Bad Request", "application/json", ApiError)
83 def update_operation do
85 tags: ["Admin", "oAuth Apps"],
86 summary: "Update OAuth App",
87 operationId: "AdminAPI.OAuthAppController.update",
88 parameters: [id_param()],
89 security: [%{"oAuth" => ["write"]}],
90 requestBody: request_body("Parameters", update_request()),
92 200 => Operation.response("App", "application/json", oauth_app()),
94 Operation.response("Bad Request", "application/json", %Schema{
95 oneOf: [ApiError, %Schema{type: :string}]
101 def delete_operation do
103 tags: ["Admin", "oAuth Apps"],
104 summary: "Delete OAuth App",
105 operationId: "AdminAPI.OAuthAppController.delete",
106 parameters: [id_param()],
107 security: [%{"oAuth" => ["write"]}],
109 204 => no_content_response(),
110 400 => no_content_response()
115 defp create_request do
117 title: "oAuthAppCreateRequest",
119 required: [:name, :redirect_uris],
121 name: %Schema{type: :string, description: "Application Name"},
122 scopes: %Schema{type: :array, items: %Schema{type: :string}, description: "oAuth scopes"},
123 redirect_uris: %Schema{
126 "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."
131 description: "A URL to the homepage of the app"
137 description: "Is the app trusted?"
142 "redirect_uris" => "https://myapp.com/auth/callback",
143 "website" => "https://myapp.com/",
144 "scopes" => ["read", "write"],
150 defp update_request do
152 title: "oAuthAppUpdateRequest",
155 name: %Schema{type: :string, description: "Application Name"},
156 scopes: %Schema{type: :array, items: %Schema{type: :string}, description: "oAuth scopes"},
157 redirect_uris: %Schema{
160 "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."
165 description: "A URL to the homepage of the app"
171 description: "Is the app trusted?"
176 "redirect_uris" => "https://myapp.com/auth/callback",
177 "website" => "https://myapp.com/",
178 "scopes" => ["read", "write"],
189 id: %Schema{type: :integer},
190 name: %Schema{type: :string},
191 client_id: %Schema{type: :string},
192 client_secret: %Schema{type: :string},
193 redirect_uri: %Schema{type: :string},
194 website: %Schema{type: :string, nullable: true},
195 trusted: %Schema{type: :boolean}
200 "client_id" => "TWhM-tNSuncnqN7DBJmoyeLnk6K3iJJ71KKXxgL1hPM",
201 "client_secret" => "ZEaFUFmF0umgBX1qKJDjaU99Q31lDkOU8NutzTOoliw",
202 "redirect_uri" => "https://myapp.com/oauth-callback",
203 "website" => "https://myapp.com/",
210 Operation.parameter(:id, :path, :integer, "App ID",