apoeco

apoeco

Hello everyone, this is my first post here!

I am a newbie in Elixir and Phoenix (ex Ruby/Rails :wink: ) and I am having some hard time
trying to figure out how to properly set authentication in my project (Phoenix/React).

I was looking at Phoenix.Token today (as I will probably try to roll out my own authentication library/plug)
and noticed that it is using Plug.Crypto.MessageVerifier.

As MessageVerifier docs are mentioning

MessageVerifier makes it easy to generate and verify messages
which are signed to prevent tampering.

On the other hand I took a look at Plug.Crypto.MessageEncryptor .

As MessageEncryptor docs are mentioning

MessageEncryptor is a simple way to encrypt values which get stored
somewhere you don’t trust.
The encrypted key, initialization vector, cipher text, and cipher tag
are base64url encoded and returned to you.
This can be used in situations similar to the MessageVerifier, but where
you don’t want users to be able to determine the value of the payload.

So I need to ask this!

Given the fact that our js/socket clients are not trusted, why does Phoenix.Token use MessageVerifier over MessageEncryptor?
I must also note that there is a get_secret private function defined and used inside of Phoenix.Token that I really didn’t check out :blush:

Most Liked

bobbypriambodo

bobbypriambodo

Hello and welcome!

Because most of the time, signed token (as opposed to encrypted token) is enough. You usually only store safe-to-know values as the token payload, such as the user’s ID. This is also the case with JWT, the messages are signed to prevent tampering, but they’re not encrypted, so you can inspect the payload with JWT decoders available online.

Encrypted messages make sense if the payload of the message is sensitive, maybe if you store the user’s home address or any kind of private values in the payload (I don’t know why you would, though).

To sum up, authentication tokens usually are safe enough (meaning that the payload is not that private) such that using MessageVerifier will suffice. It is also secure in the sense that end users can’t tamper with the data, since the token is signed using your secret_key_base.

Do note that both tokens generated by MessageVerifier and MessageEncryptor are vulnerable to a form of session hijacking if someone can get hold of your token (even when encrypted).

apoeco

apoeco OP

First of all, thank you a lot for that quick response!

Well yes, that makes sense… :smile:

Maybe off topic question

That’s true. Does this hold true with JWT also? I guess so…

Last Post!

apoeco

apoeco OP

This is exactly what I imagined… :smiling_imp:
My goal is to build a phoenix project that exposes an API (for a mobile app later on) and also serves a SPA (React) .
So I was thinking that I could probably do the register/login part with plain old server-rendered html forms (using form_for) to prevent CSRF attacks and after a successful login redirect to the SPA (something like "/app") passing down a Phoenix.Token through window.userToken that only stores the user’s ID.
After that the SPA would connect to a Phoenix.Channel and interact with the API only via the channel, using the token for authorization/authentication.

Even if I don’t save the token in localStorage and save it in-memory (redux store), it may still be possible that the token might be leaked in someway from the Javascript application I think…

I wonder what is the best way to achieve the behaviour I mentioned above (SPA consuming the API via Phoenix.Channels)… :confounded: :confounded:

P.S. I am considering https and wss as standards… :smiley_cat:

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews