aniruddhasd
Create custom tokens for firebase authentication?
Hi, I am using Firebase as my auth server with my phoenix application. I am using Admin SDK to verify id_tokens generated by my firebase client sdk. My requirement is to be able to impersonate users and to achieve this i want to generate custom tokens from admin sdk like mentioned here
Has anyone done this or can help me with this?
Most Liked
timothy
Hi, I know this is an old thread, but I just wanted to share how I did this for anyone stumbling on this (like I did).
I followed the docs from: Create Custom Tokens | Firebase Documentation.
You can use Joken to create the token, you only need the private key and the email address of your service account.
email = "your@service.account"
private_key = "..."
# Create the signer, this needs to be "RS256"
signer = Joken.Signer.create("RS256", %{"pem" => private_key})
# Configure the claims
token_config =
Joken.Config.default_claims(
default_exp: 60 * 60,
skip: [:jti, :nbf],
iss: email,
aud: "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit"
)
|> Joken.Config.add_claim("sub", fn -> email end, &(&1 == email))
# Create the token
token =
Joken.generate_and_sign!(
token_config,
%{"uid" => uid}, # This can be empty but you probably want to pas the Firebase UID of the user
signer
)
3
Popular in Questions
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
Hey,
I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New
I have a super simple question about elixir - how would I take a file like this
foo bar baz
and output a new file that enumerates th...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Other popular topics
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Hello guys,
I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New








