Rya
Issue:
I’m currently trying to implement support for openID authentication using guardian for a RESTful api.
The api i’m currently working with supports authentication with a password stored as a hash on the api’s db. I’d like to add another option to login using openID through authelia.
All users have a :distant, :boolean field used to denote wether a user authenticates through a password in the db or authelia. I want to make it so that guardian generates a token itself only when a user is not distant. If it is distant i want instead for guardian to store the token given by authelia, and use that token afterwards. That way i can use the protected endpoints of my project (based on the EnsureAuthenticated Plug) without any modifications
Goal:
I want to modify the way guardian creates and verifies tokens to switch between verifying the password itself or letting authelia handle verifications/token creation.
I want the resulting token to be used transparently by the EnsureAuthneicated Guardian plug so that i don’t have to modifiy the endpoints of my project.
I don’t fully understand the authentication life cycle of the phoenix connection, so i don’t know where to start.
Current pipeline
This is the pipeline is use for authentication. ideally i’d like to only modify this part so that changes are transparent for the rest of the code (apart from the new routes needed to authenticate through authelia ofc.)
defmodule Backend24hWeb.Auth.SwimmerPipeline do
use Guardian.Plug.Pipeline, otp_app: :backend24,
module: Backend24hWeb.Auth.GuardianNageur,
error_handler: Backend24hWeb.Auth.GuardianErrorHandler
plug Guardian.Plug.VerifySession
plug Guardian.Plug.VerifyHeader
plug Guardian.Plug.EnsureAuthenticated
plug Guardian.Plug.LoadResource
end
Thanks in advance.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
itzmidinesh
I understand you’re trying to integrate Authelia OpenID authentication alongside your existing Guardian password-based auth. Based on your description, there are a few key areas you might want to focus on:
Would you mind sharing what you’ve tried so far in terms of Guardian customization? That would help me give more specific guidance.
Rya
I have a standard password based verification that uses the default
encode_and_sign/3function provided by elixir:user controller:
GuardianUser.authenticatejust checks that the email is correct and creates a new token with the defaultencode_and_signfunction.Now what i want to add is another endpoint that is the callback used in a OIDC request, where i get a token and claims back after a successful authentication:
Doing things this way would allow the verify session plug of my pipeline to handle token verfication, and i wouldn’t need to change any of my endpoints. I can’t quite wrap my head around what encode_and_sign does exactly but i believe this could work.
For reference here is the (currently incomplete) GuardianUser module:
itzmidinesh
After verifying the data from the callback and retrieving or creating the user, you can use the create_token function in GuardianUser.
Then, use the token and user to set the necessary data, and return JSON in a similar way to the authorize_account function in the user controller.
I hope this helps you get started on resolving the issue. I’m on mobile and unable to provide a code example this week, but feel free to reach out if you have any questions!