Skip to content

How to protect routes using oidcc in phoenix? #357

Answered by maennchen
Lionstiger asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @Lionstiger

There's two ways how oidcc plugs help you with your application:

  • Header based auth (APIs)
  • Login Flow in Application

Judging by you using phx_gen_oidcc, you want to do the latter.

The generator of phx_gen_oidcc puts the OpenID claims into the session:
https://github.com/erlef/phx_gen_oidcc/blob/2b1b75296d5f8d758f2d61894edbf04319d40455/priv/templates/oidcc_controller.exs#L32

You can create your own plug checking if the claims are present in the session and include it in your router or controller for all the protected routes.

defmodule MyAppWeb.Router do
  use Phoenix.Router

  pipeline :browser do
    plug :fetch_session
    plug :accepts, ["html"]
  end

  pipeline :prote…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@Lionstiger
Comment options

@maennchen
Comment options

@Lionstiger
Comment options

@maennchen
Comment options

@Lionstiger
Comment options

Answer selected by maennchen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants