-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(auth): add openapi #89
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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 |
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}, | ||
Check failure Code scanning / Credo Numbers larger than 9999 should be written with underscores: 86_400 Error
Numbers larger than 9999 should be written with underscores: 86_400
|
||
authorization_code_ttl: %Schema{type: :integer, example: 60}, | ||
id: %Schema{type: :string, format: :uuid}, | ||
id_token_ttl: %Schema{type: :integer, example: 86400}, | ||
Check failure Code scanning / Credo Numbers larger than 9999 should be written with underscores: 86_400 Error
Numbers larger than 9999 should be written with underscores: 86_400
|
||
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}, | ||
Check failure Code scanning / Credo Numbers larger than 9999 should be written with underscores: 86_400 Error
Numbers larger than 9999 should be written with underscores: 86_400
|
||
supported_grant_types: %Schema{type: :array, items: %Schema{type: :string}}, | ||
secret: %Schema{type: :string} | ||
}, | ||
required: [:id, :name] | ||
}) | ||
end | ||
|
||
defmodule ClientList do | ||
Check warning Code scanning / Credo Modules should have a @moduledoc tag. Warning
Modules should have a @moduledoc tag.
|
||
require OpenApiSpex | ||
|
||
OpenApiSpex.schema(%{ | ||
description: "List of Oauth Clients", | ||
type: :array, | ||
items: Client | ||
}) | ||
end | ||
|
||
result(ClientDelete, "Client Delete", %{client: ExFleetYardsAuth.Api.ClientSchema.Client}, []) | ||
end |
Check warning
Code scanning / Credo
Modules should have a @moduledoc tag. Warning