AshAuthentication. Phoenix. Oauth2Server. Router
(ash_authentication_oauth2_server v0.1.0)
Copy Markdown
View Source
Phoenix router macros for mounting the OAuth 2.1 authorization server.
use this module inside your router to gain access to
oauth2_server_consent_routes/1 (browser-facing, user consent) and
oauth2_server_protocol_routes/1 (client-facing protocol endpoints).
Example
defmodule MyAppWeb.Router do
use Phoenix.Router
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
end
endThe two macros forward to:
AshAuthentication.Phoenix.Oauth2Server.ConsentRouter— handles/oauth/authorize(the user-driven consent step).AshAuthentication.Phoenix.Oauth2Server.ProtocolRouter— handles/oauth/register,/oauth/token,/oauth/revoke, and the three metadata documents under/.well-known.
Summary
Functions
Generate the routes for the user-driven consent step of an OAuth 2.1 authorization-server flow.
Generate the routes for the client-facing OAuth 2.1 protocol endpoints — discovery, dynamic client registration, token, and revocation.
Functions
Generate the routes for the user-driven consent step of an OAuth 2.1 authorization-server flow.
Mount this inside a scope that pipes through your browser pipeline
(with :protect_from_forgery and session loading) — both the consent
GET and POST need a logged-in user and CSRF protection.
Example
scope "/" do
pipe_through :browser
oauth2_server_consent_routes oauth2_server: MyApp.Oauth2Server
endOptions
:oauth2_server(required) — yourOauth2Serverconfig module.:path— base path. Defaults to/oauth/authorize.:consent_view— module exposingrender(:consent, assigns). Defaults toAshAuthentication.Phoenix.Oauth2Server.ConsentView.
Generate the routes for the client-facing OAuth 2.1 protocol endpoints — discovery, dynamic client registration, token, and revocation.
Mount this inside a scope that pipes through your API pipeline. These endpoints are called by external OAuth clients without a browser session, so CSRF must NOT apply.
Example
scope "/" do
pipe_through :api
oauth2_server_protocol_routes oauth2_server: MyApp.Oauth2Server
endOptions
:oauth2_server(required) — yourOauth2Serverconfig module.:oauth_path— prefix for/token,/register, etc. Defaults to/oauth.:well_known_path— prefix for/oauth-authorization-server,/oauth-protected-resource,/openid-configuration. Defaults to/.well-known.