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
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
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
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Background
Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
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
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Other popular topics
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
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
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
by Lance Halvorsen
Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New








