Create custom tokens for Firebase via API endpoint
Getting Started
Usage
Built With
Contributing
Deployment
The Firebase Custom Token (FCT) API is a single serverless endpoint that can be used to generate custom tokens for Firebase.
For more information, see Create Custom Tokens from the Firebase docs.
The headers
field of every request should include the following keys:
client_email
private_key
project_id
The required keys can be found by generating a private key file from the Firebase Console:
- Open Settings > Service Accounts
- Click Generate New Private Key; confirm by clicking Generate Key
- Securely store the JSON file containing the key
Generate a custom token for a single user or batch of users, as well as optionally specify additional claims to be included in each token.
- URL:
https://fct-api.flexdevelopment.vercel.app
- Method:
POST
name | type | default | required | description |
---|---|---|---|---|
user_must_exist |
boolean |
true |
false |
check if user exists before generating custom token |
The body
of every request should have the following shape:
[
{
"uid": 20430108
}
]
Custom claims can also be specified for each user:
[
{
"developerClaims": {
"admin": true
},
"uid": 20430108
}
]
If an error is thrown, it will have the following shape:
{
"name": "GeneralError",
"message": "",
"code": 500,
"className": "general-error",
"data": {
"body": "",
"query": {
"compile": true,
"options": {}
}
},
"errors": {}
}
{
"name": "NotFound",
"message": "There is no user record corresponding to the provided identifier.",
"code": 404,
"className": "not-found",
"data": {
"codePrefix": "auth",
"req": {
"body": [
{
"uid": -1
}
],
"query": {
"user_must_exist": true
}
}
},
"errors": {
"code": "auth/user-not-found",
"uid": -1
}
}
- Firebase Admin - Interact with Firebase from privileged environments
- Vercel - Hosting platform for serverless functions