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.AppOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Helpers
10 @spec open_api_operation(atom) :: Operation.t()
11 def open_api_operation(action) do
12 operation = String.to_existing_atom("#{action}_operation")
13 apply(__MODULE__, operation, [])
16 @spec index_operation() :: Operation.t()
17 def index_operation do
19 tags: ["Applications"],
20 summary: "List applications",
21 description: "List the OAuth applications for the current user",
22 operationId: "AppController.index",
24 200 => Operation.response("App", "application/json", index_response()),
29 @spec create_operation() :: Operation.t()
30 def create_operation do
32 tags: ["Applications"],
33 summary: "Create an application",
34 description: "Create a new application to obtain OAuth2 credentials",
35 operationId: "AppController.create",
36 requestBody: Helpers.request_body("Parameters", create_request(), required: true),
38 200 => Operation.response("App", "application/json", create_response()),
41 "Unprocessable Entity",
46 "If a required parameter is missing or improperly formatted, the request will fail.",
48 error: %Schema{type: :string}
51 "error" => "Validation failed: Redirect URI must be an absolute URI."
59 def verify_credentials_operation do
61 tags: ["Applications"],
62 summary: "Verify the application works",
63 description: "Confirm that the app's OAuth2 credentials work.",
64 operationId: "AppController.verify_credentials",
65 security: [%{"oAuth" => ["read"]}],
68 Operation.response("App", "application/json", %Schema{
71 "If the Authorization header was provided with a valid token, you should see your app returned as an Application entity.",
73 name: %Schema{type: :string},
74 vapid_key: %Schema{type: :string},
75 website: %Schema{type: :string, nullable: true}
80 "BCk-QqERU0q-CfYZjcuB6lnyyOYfJ2AifKqfeGIm7Z-HiTU5T9eTG5GxVA0_OH5mMlI4UkkDTpaZwozy0TzdZ2M=",
81 "website" => "https://myapp.com/"
91 "If the Authorization header contains an invalid token, is malformed, or is not present, an error will be returned indicating an authorization failure.",
93 error: %Schema{type: :string}
96 "error" => "The access token is invalid."
104 defp create_request do
106 title: "AppCreateRequest",
107 description: "POST body for creating an app",
110 client_name: %Schema{type: :string, description: "A name for your application."},
111 redirect_uris: %Schema{
114 "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."
118 description: "Space separated list of scopes",
124 description: "A URL to the homepage of your app"
127 required: [:client_name, :redirect_uris],
129 "client_name" => "My App",
130 "redirect_uris" => "https://myapp.com/auth/callback",
131 "website" => "https://myapp.com/"
136 defp create_response do
138 title: "AppCreateResponse",
139 description: "Response schema for an app",
142 id: %Schema{type: :string},
143 name: %Schema{type: :string},
144 client_id: %Schema{type: :string},
145 client_secret: %Schema{type: :string},
146 redirect_uri: %Schema{type: :string},
147 vapid_key: %Schema{type: :string},
148 website: %Schema{type: :string, nullable: true}
153 "client_id" => "TWhM-tNSuncnqN7DBJmoyeLnk6K3iJJ71KKXxgL1hPM",
154 "client_secret" => "ZEaFUFmF0umgBX1qKJDjaU99Q31lDkOU8NutzTOoliw",
156 "BCk-QqERU0q-CfYZjcuB6lnyyOYfJ2AifKqfeGIm7Z-HiTU5T9eTG5GxVA0_OH5mMlI4UkkDTpaZwozy0TzdZ2M=",
157 "website" => "https://myapp.com/"
162 defp index_response do
164 title: "AppIndexResponse",
165 description: "Response schema for GET /api/v1/apps",
168 id: %Schema{type: :string},
169 name: %Schema{type: :string},
170 client_id: %Schema{type: :string},
171 client_secret: %Schema{type: :string},
172 redirect_uri: %Schema{type: :string},
173 vapid_key: %Schema{type: :string},
174 website: %Schema{type: :string, nullable: true}
179 "client_id" => "TWhM-tNSuncnqN7DBJmoyeLnk6K3iJJ71KKXxgL1hPM",
180 "client_secret" => "ZEaFUFmF0umgBX1qKJDjaU99Q31lDkOU8NutzTOoliw",
182 "BCk-QqERU0q-CfYZjcuB6lnyyOYfJ2AifKqfeGIm7Z-HiTU5T9eTG5GxVA0_OH5mMlI4UkkDTpaZwozy0TzdZ2M=",
183 "website" => "https://myapp.com/"