-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
162 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[ | ||
import_deps: [:phoenix], | ||
inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"] | ||
plugins: [Phoenix.LiveView.HTMLFormatter], | ||
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
AWS_ACCESS_KEY_ID= | ||
AWS_SECRET_ACCESS_KEY= | ||
|
||
## Single Sign-on configuration. | ||
### Used for local dev, cloud environments make use of Terraform env vars | ||
# export KEYCLOAK_ISSUER= | ||
# export KEYCLOAK_CLIENT_ID= | ||
# export KEYCLOAK_CLIENT_SECRET= | ||
# export KEYCLOAK_IDP_HINT=oidc-mbta-entraid |
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
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
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,33 @@ | ||
defmodule DocumentViewerWeb.Plugs.EnsureRole do | ||
require Plug.Conn | ||
|
||
@moduledoc """ | ||
Checks whether the user in the assigns has ANY of the given roles, redirects if they do | ||
not. This is useful for scoping parts of the app to the specific roles. For liveviews you | ||
should also use the `DocumentViewerWeb.RequireRole` hook. | ||
""" | ||
require Logger | ||
use DocumentViewerWeb, :controller | ||
|
||
@impl true | ||
def init(opts), do: opts | ||
|
||
@impl true | ||
def call(conn, %{roles: roles}) do | ||
if Enum.any?(roles, fn role -> role in conn.assigns.current_user.roles end) do | ||
conn | ||
else | ||
# If a user gets a failure from Ueberauth, we want to redirect them away from this site. | ||
# Since everything on this site requires authorization, they will get trapped | ||
# in an infinite loop of redirects otherwise. | ||
Logger.error( | ||
"Ueberauth error: user #{conn.assigns.current_user.id} tried to log in " <> | ||
"without correct user permissions." | ||
) | ||
|
||
conn | ||
|> Guardian.Plug.sign_out(AuthManager, []) | ||
|> redirect(external: "https://www.mbta.com") | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule DocumentViewerWeb.Plugs.MountCurrentUser do | ||
@moduledoc """ | ||
This sets the logged in user in the assigns. Useful for subsequent plugs like checking user roles. | ||
Also sets a sentry context if the user exists. | ||
""" | ||
|
||
use DocumentViewerWeb, :controller | ||
require Plug.Conn | ||
|
||
@impl true | ||
def init(opts), do: opts | ||
|
||
@impl true | ||
def call(conn, _args) do | ||
case Guardian.Plug.current_resource(conn) do | ||
%{user: current_user} -> | ||
Plug.Conn.assign(conn, :current_user, current_user) | ||
|
||
_ -> | ||
Plug.Conn.assign(conn, :current_user, nil) | ||
end | ||
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
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
Oops, something went wrong.