mix ash_authentication_oauth2_server. install
(ash_authentication_oauth2_server v0.1.0)
Copy Markdown
View Source
Scaffolds an OAuth 2.1 authorization server
Scaffolds:
- Four resources in the configured Ash domain —
OauthClient,OauthAuthorizationCode,OauthRefreshToken,OauthConsent. - An
Oauth2Serverconfig module that pulls them together. - Three
secret_for/4clauses on the user's Secrets module (:issuer_url,:resource_url,:signing_secret) that read from application env, so prod overrides go inconfig/runtime.exs. - Localhost defaults in
config/dev.exsfor development.
After install, run mix ash.codegen --name add_oauth2_server to
generate migrations for the new resources, then mix ecto.migrate.
The router macros are NOT auto-mounted. use the router module in
your Phoenix router and add the scopes by hand — different apps
want different paths/pipelines:
use AshAuthentication.Phoenix.Oauth2Server.Router
scope "/" do
pipe_through :browser
oauth2_server_consent_routes oauth2_server: MyApp.Oauth2Server
end
scope "/" do
pipe_through :api
oauth2_server_protocol_routes oauth2_server: MyApp.Oauth2Server
endThen mount AshAuthentication.Phoenix.Oauth2Server.BearerPlug on
whatever resource you want OAuth-protected.
Production config
The dev URLs written to config/dev.exs are placeholders. For prod,
set the real values in config/runtime.exs:
config :my_app,
oauth2_issuer_url: System.get_env("OAUTH2_ISSUER_URL"),
oauth2_resource_url: System.get_env("OAUTH2_RESOURCE_URL"),
oauth2_signing_secret: System.get_env("OAUTH2_SIGNING_SECRET")oauth2_resource_url is the URL clients will reach your protected
resource at. It's bound to the access token's aud claim.
Example
mix ash_authentication_oauth2_server.install
Options
--accounts,-a— Domain. Default:MyApp.Accounts.--user,-u— User resource. Default:<Accounts>.User.--server-module,-s— Where to put theOauth2Servermodule. Default:MyApp.Oauth2Server.--secrets-module— Module implementingAshAuthentication.Secret. Default:MyApp.Secrets.--issuer-url— Issuer URL written toconfig/dev.exs. Default:http://localhost:4000.--resource-url— Resource URL written toconfig/dev.exs. Default: same as--issuer-url.--scope— Scope advertised in metadata. Default:example.scope(a placeholder to replace with whatever your protected resource actually uses).
Summary
Functions
Callback implementation for Igniter.Mix.Task.igniter/1.
Functions
Callback implementation for Igniter.Mix.Task.igniter/1.