HappyBee

HappyBee

Hello!

I’m working on a rest api for a mobile app, where authentication is done via an Authentication: Bearer <access_token> for every request to rest api.

Initially, I’m able get the access token and refresh token from auth server(which was written in phoenix). In the access token and renew token, user details are embedded through some salt key.. I’m able to verify and retrieve user info from the tokens on auth server using some cryptography verify function.

My actual question is, how should I verify the bearer token on resource rest api server? Should I share the same salt key that was used in auth server to verify and then send user related data?

I would grateful if somebody could help me understand the concept. Thank you!

Showing Posts 1 to 7

darnahsan

darnahsan

from my experience I would not recommend to share the key to other services. One of the reason is if you need to update the key signing the token it will have to be propagated across. If you are concerned about sharing the key itself then use a Public Private key signing. In a gateway pattern the entity would make the call to the auth server for you and verify the token before passing you so making a call to the auth server to verify is a valid approach to take in order to not share the key

HappyBee

HappyBee OP

I thought about it the same.

What is the known/general way of doing authentication and authorisation for mobile apps and api’s?

(I don’t want to reinvent the wheel, I just want to conform)

darnahsan

darnahsan

If you look at how Google, Apple, Firebase give you an access token it could be considered a general practice. Once you log in they would provide you with JWT thay can be validated using JWKS in simple words it can be verified using the public key as the token is signed by their private key. This is the case when you give away a token to someone who doesn’t need to reach out to you for verifying the authenticity of the token but can do it on their end. but if you use non public-private mechanism the only the issuer can verify the token and you have to send it over to verify. You can cache the call till the token expiry if its a JWT as its JWT come with their own expiry duration and are not generally meant to be revoked.

HappyBee

HappyBee OP

I read somewhere that using JWT isn’t that secure.. currently I’m reading this post on StackOverflow. I’ll see if it helps.

darnahsan

darnahsan

JWT aren’t meant to manage session where you are looking for logout option. You will find a lot of debate over how good are JWT but one thing most people will agree on is that its not for session management where you have to store the token to keep track if someone is still logged in. The good part of JWT is its ability for others to verify the token you issued if they have the key and you can embed information in it. If you look at the Guardian elixir library they have Guardian DB project which allows you to store the JWT in a DB but at the same time they mention if you are storing JWT in DB you probably don’t need JWT

HappyBee

HappyBee OP

Yeah, you’re right!

I’ve been stuck with this for the past few days. Your posts are quite helpful in understanding.

For example, how is twitter, instagram apps are able to maintain the session using the token, do they use JWT’s as well?

darnahsan

darnahsan

I am not sure how Twitter or Instagram is doing it but they all have different approaches. Google gives you a JWT that you can exchange from your service for an access token to allow your app to have access to your APIs while Facebook doesn’t give you a JWT but a regular token. If you are implementing the social logins they are meant for authenticating user owns a particular account and agrees to share certain info with the service he is about to log in to. Once you get the token you would generally exchange it for an access token hence the token from Google etc doesn’t have to be long lived and doesn’t cares for a session management. The responsibility of session management relies on you and not on their token. Their token are usually valid for 30 minute or so and without a refresh token. With JWT a “session” access to service is extended using a refresh token. For how to revoke a session with a JWT there is a split opinion over should a service maintain a blacklist or a whitelist for the token validity to allow or disallow access.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
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
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
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
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
AstonJ
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
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
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
georgeguimaraes
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
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