2023-02-15 18:31:23 +00:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.AuthApplicationType do
|
|
|
|
@moduledoc """
|
|
|
|
Schema representation for an auth application
|
|
|
|
"""
|
|
|
|
use Absinthe.Schema.Notation
|
|
|
|
alias Mobilizon.GraphQL.Resolvers.Application
|
|
|
|
|
|
|
|
@desc "An application"
|
|
|
|
object :auth_application do
|
2023-03-17 17:10:59 +00:00
|
|
|
meta(:authorize, :user)
|
2023-02-21 13:50:09 +00:00
|
|
|
field(:id, :id)
|
2023-02-15 18:31:23 +00:00
|
|
|
field(:name, :string)
|
|
|
|
field(:client_id, :string)
|
2023-03-17 17:10:59 +00:00
|
|
|
field(:scope, :string)
|
2023-02-15 18:31:23 +00:00
|
|
|
field(:website, :string)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "An application"
|
|
|
|
object :auth_application_token do
|
2023-03-17 17:10:59 +00:00
|
|
|
meta(:authorize, :user)
|
2023-02-15 18:31:23 +00:00
|
|
|
field(:id, :id)
|
|
|
|
field(:inserted_at, :string)
|
|
|
|
field(:last_used_at, :string)
|
|
|
|
field(:application, :auth_application)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "The informations returned after authorization"
|
|
|
|
object :application_code_and_state do
|
2023-03-17 17:10:59 +00:00
|
|
|
meta(:authorize, :user)
|
2023-02-15 18:31:23 +00:00
|
|
|
field(:code, :string)
|
|
|
|
field(:state, :string)
|
2023-03-17 17:10:59 +00:00
|
|
|
field(:client_id, :string)
|
|
|
|
field(:scope, :string)
|
2023-02-15 18:31:23 +00:00
|
|
|
end
|
|
|
|
|
2023-02-21 13:50:09 +00:00
|
|
|
object :application_device_activation do
|
2023-03-17 17:10:59 +00:00
|
|
|
meta(:authorize, :user)
|
2023-02-21 13:50:09 +00:00
|
|
|
field(:id, :id)
|
|
|
|
field(:application, :auth_application)
|
|
|
|
field(:scope, :string)
|
|
|
|
end
|
|
|
|
|
2023-02-15 18:31:23 +00:00
|
|
|
object :auth_application_queries do
|
|
|
|
@desc "Get an application"
|
|
|
|
field :auth_application, :auth_application do
|
|
|
|
arg(:client_id, non_null(:string), description: "The application's client_id")
|
2023-03-17 17:10:59 +00:00
|
|
|
|
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Applications.Application,
|
|
|
|
rule: :forbid_app_access,
|
|
|
|
args: %{client_id: :client_id}
|
|
|
|
)
|
|
|
|
|
2023-02-15 18:31:23 +00:00
|
|
|
resolve(&Application.get_application/3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
object :auth_application_mutations do
|
|
|
|
@desc "Authorize an application"
|
|
|
|
field :authorize_application, :application_code_and_state do
|
|
|
|
arg(:client_id, non_null(:string), description: "The application's client_id")
|
|
|
|
|
|
|
|
arg(:redirect_uri, non_null(:string),
|
|
|
|
description: "The URI to redirect to with the code and state"
|
|
|
|
)
|
|
|
|
|
2023-03-17 17:10:59 +00:00
|
|
|
arg(:scope, non_null(:string), description: "The scope for the authorization")
|
2023-02-15 18:31:23 +00:00
|
|
|
|
|
|
|
arg(:state, :string,
|
|
|
|
description: "A state parameter to check that the request wasn't altered"
|
|
|
|
)
|
|
|
|
|
2023-03-17 17:10:59 +00:00
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Applications.Application,
|
|
|
|
rule: :forbid_app_access,
|
|
|
|
args: %{client_id: :client_id}
|
|
|
|
)
|
|
|
|
|
2023-02-15 18:31:23 +00:00
|
|
|
resolve(&Application.authorize/3)
|
|
|
|
end
|
|
|
|
|
2023-02-21 13:50:09 +00:00
|
|
|
@desc "Revoke an authorized application"
|
2023-02-15 18:31:23 +00:00
|
|
|
field :revoke_application_token, :deleted_object do
|
|
|
|
arg(:app_token_id, non_null(:string), description: "The application token's ID")
|
2023-03-17 17:10:59 +00:00
|
|
|
|
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Applications.ApplicationToken,
|
|
|
|
rule: :forbid_app_access,
|
|
|
|
args: %{id: :app_token_id}
|
|
|
|
)
|
|
|
|
|
2023-02-15 18:31:23 +00:00
|
|
|
resolve(&Application.revoke_application_token/3)
|
|
|
|
end
|
2023-02-21 13:50:09 +00:00
|
|
|
|
|
|
|
@desc "Activate an user device"
|
|
|
|
field :device_activation, :application_device_activation do
|
|
|
|
arg(:user_code, non_null(:string),
|
|
|
|
description: "The code provided by the application entered by the user"
|
|
|
|
)
|
|
|
|
|
2023-03-17 17:10:59 +00:00
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Applications.ApplicationDeviceActivation,
|
|
|
|
rule: :forbid_app_access,
|
|
|
|
args: %{id: :user_code}
|
|
|
|
)
|
|
|
|
|
2023-02-21 13:50:09 +00:00
|
|
|
resolve(&Application.activate_device/3)
|
|
|
|
end
|
|
|
|
|
2023-05-30 10:56:36 +00:00
|
|
|
@desc "Authorize an user device"
|
2023-02-21 13:50:09 +00:00
|
|
|
field :authorize_device_application, :auth_application do
|
|
|
|
arg(:client_id, non_null(:string), description: "The application's client_id")
|
2023-03-17 17:10:59 +00:00
|
|
|
|
|
|
|
arg(:user_code, non_null(:string),
|
|
|
|
description: "The code provided by the application entered by the user"
|
|
|
|
)
|
|
|
|
|
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Applications.ApplicationDeviceActivation,
|
|
|
|
rule: :forbid_app_access,
|
|
|
|
args: %{id: :client_id}
|
|
|
|
)
|
2023-02-21 13:50:09 +00:00
|
|
|
|
|
|
|
resolve(&Application.authorize_device_application/3)
|
|
|
|
end
|
2023-02-15 18:31:23 +00:00
|
|
|
end
|
|
|
|
end
|