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
9 alias Pleroma.Web.ApiSpec.Schemas.App
11 @spec open_api_operation(atom) :: Operation.t()
12 def open_api_operation(action) do
13 operation = String.to_existing_atom("#{action}_operation")
14 apply(__MODULE__, operation, [])
17 @spec create_operation() :: Operation.t()
18 def create_operation do
20 tags: ["Applications"],
21 summary: "Create an application",
22 description: "Create a new application to obtain OAuth2 credentials",
23 operationId: "AppController.create",
24 requestBody: Helpers.request_body("Parameters", create_request(), required: true),
26 200 => Operation.response("App", "application/json", App),
29 "Unprocessable Entity",
34 "If a required parameter is missing or improperly formatted, the request will fail.",
36 error: %Schema{type: :string}
39 "error" => "Validation failed: Redirect URI must be an absolute URI."
47 def verify_credentials_operation do
49 tags: ["Applications"],
50 summary: "Verify the application works",
51 description: "Confirm that the app's OAuth2 credentials work.",
52 operationId: "AppController.verify_credentials",
53 security: [%{"oAuth" => ["read"]}],
56 Operation.response("App", "application/json", %Schema{
59 "If the Authorization header was provided with a valid token, you should see your app returned as an Application entity.",
61 name: %Schema{type: :string},
62 vapid_key: %Schema{type: :string},
63 website: %Schema{type: :string, nullable: true}
68 "BCk-QqERU0q-CfYZjcuB6lnyyOYfJ2AifKqfeGIm7Z-HiTU5T9eTG5GxVA0_OH5mMlI4UkkDTpaZwozy0TzdZ2M=",
69 "website" => "https://myapp.com/"
79 "If the Authorization header contains an invalid token, is malformed, or is not present, an error will be returned indicating an authorization failure.",
81 error: %Schema{type: :string}
84 "error" => "The access token is invalid."
92 defp create_request do
94 title: "AppCreateRequest",
95 description: "POST body for creating an app",
98 client_name: %Schema{type: :string, description: "A name for your application."},
99 redirect_uris: %Schema{
102 "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."
106 description: "Space separated list of scopes",
112 description: "A URL to the homepage of your app"
115 required: [:client_name, :redirect_uris],
117 "client_name" => "My App",
118 "redirect_uris" => "https://myapp.com/auth/callback",
119 "website" => "https://myapp.com/"