-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from fleetyards/auth/openapi
feat(auth): add openapi
- Loading branch information
Showing
16 changed files
with
498 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
apps/ex_fleet_yards/priv/repo/migrations/20230730111440_no_user_for_oauth_client.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule ExFleetYards.Repo.Migrations.NoUserForOauthClient do | ||
use Ecto.Migration | ||
|
||
def up do | ||
execute "ALTER TABLE oauth_user_clients DROP CONSTRAINT oauth_user_clients_user_id_fkey" | ||
|
||
alter table(:oauth_user_clients) do | ||
modify :user_id, references(:users, type: :uuid, on_delete: :delete_all), null: true | ||
end | ||
end | ||
|
||
def down do | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
apps/ex_fleet_yards_auth/lib/ex_fleet_yards_auth/api_spec.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
defmodule ExFleetYardsAuth.ApiSpec do | ||
@moduledoc """ | ||
OpenApi Spec definition root | ||
""" | ||
use ExFleetYardsAuth, :verified_routes | ||
|
||
alias OpenApiSpex.{ | ||
Components, | ||
Info, | ||
OpenApi, | ||
Paths, | ||
Server, | ||
SecurityScheme, | ||
OAuthFlows, | ||
OAuthFlow | ||
} | ||
|
||
alias ExFleetYardsAuth.{Endpoint, Router} | ||
@behaviour OpenApi | ||
|
||
@impl OpenApi | ||
def spec do | ||
%OpenApi{ | ||
servers: [ | ||
Server.from_endpoint(Endpoint) | ||
], | ||
info: %Info{ | ||
title: "Fleetyards", | ||
version: ExFleetYards.Version.version() | ||
}, | ||
paths: Paths.from_router(Router), | ||
components: %Components{ | ||
securitySchemes: %{ | ||
"authorization" => %SecurityScheme{ | ||
type: "oauth2", | ||
scheme: "bearer", | ||
in: "header", | ||
flows: %OAuthFlows{ | ||
authorizationCode: %OAuthFlow{ | ||
authorizationUrl: Endpoint.url() <> ~p"/oauth/authorize", | ||
tokenUrl: Endpoint.url() <> ~p"/oauth/token", | ||
scopes: scope_list() | ||
}, | ||
implicit: %OAuthFlow{ | ||
authorizationUrl: Endpoint.url() <> ~p"/oauth/authorize", | ||
scopes: scope_list() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|> OpenApiSpex.resolve_schema_modules() | ||
end | ||
|
||
defp scope_list do | ||
ExFleetYards.Scopes.scope_list() | ||
|> Enum.map(fn | ||
{scope, description} -> {to_string(scope), description} | ||
{scope, description, _} -> {to_string(scope), description} | ||
end) | ||
|> Enum.into(%{}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
apps/ex_fleet_yards_auth/lib/ex_fleet_yards_auth/controllers/api/client_schema.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule ExFleetYardsAuth.Api.ClientSchema do | ||
@moduledoc """ | ||
Schema definitions for Oauth Clients | ||
""" | ||
use ExFleetYards.Schemas, :schema | ||
|
||
defmodule Client do | ||
require OpenApiSpex | ||
|
||
OpenApiSpex.schema(%{ | ||
description: "Oauth Client", | ||
type: :object, | ||
properties: %{ | ||
access_token_ttl: %Schema{type: :integer, example: 86400}, | ||
authorization_code_ttl: %Schema{type: :integer, example: 60}, | ||
id: %Schema{type: :string, format: :uuid}, | ||
id_token_ttl: %Schema{type: :integer, example: 86400}, | ||
name: %Schema{type: :string}, | ||
pkce: %Schema{type: :boolean}, | ||
redirect_uris: %Schema{type: :array, items: %Schema{type: :string, format: :uri}}, | ||
refresh_token_ttl: %Schema{type: :integer, example: 86400}, | ||
supported_grant_types: %Schema{type: :array, items: %Schema{type: :string}}, | ||
secret: %Schema{type: :string} | ||
}, | ||
required: [:id, :name] | ||
}) | ||
end | ||
|
||
defmodule ClientList do | ||
require OpenApiSpex | ||
|
||
OpenApiSpex.schema(%{ | ||
description: "List of Oauth Clients", | ||
type: :array, | ||
items: Client | ||
}) | ||
end | ||
|
||
result(ClientDelete, "Client Delete", %{client: ExFleetYardsAuth.Api.ClientSchema.Client}, []) | ||
end |
Oops, something went wrong.