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 Authentication.
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
Hello, how can I check the Phoenix version ?
Thanks !
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
Other popular topics
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









