GithubHelp home page GithubHelp logo

flex-development / fct-api Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 2.32 MB

Generate custom tokens for Firebase via API endpoint. API usage tracked with Google Analytics.

Home Page: https://fct-api.flexdevelopment.vercel.app

License: BSD 3-Clause "New" or "Revised" License

JavaScript 23.28% TypeScript 76.72%
firebase-admin firebase-auth firebase serverless serverless-api serverless-functions vercel google-analytics measurement-protocol

fct-api's Introduction

Firebase Custom Token API

Create custom tokens for Firebase via API endpoint

TypeScript

Overview

Getting Started
Usage
Built With
Contributing
Deployment

Getting Started

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.

Usage

Authorization

The headers field of every request should include the following keys:

  • client_email
  • private_key
  • project_id

FCT API - Headers

The required keys can be found by generating a private key file from the Firebase Console:

  1. Open Settings > Service Accounts
  2. Click Generate New Private Key; confirm by clicking Generate Key
  3. Securely store the JSON file containing the key

Create Custom Token

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

Query Parameters

name type default required description
user_must_exist boolean true false check if user exists before generating custom token

Request Body

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
  }
]

Sample Response

Default

FCT API - Success Response

With developerClaims

FCT API - Success Response 2

With user_must_exist: false

FCT API - Success Response 3

Errors

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": {}
}

404 Sample

{
  "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
  }
}

Built With

  • Firebase Admin - Interact with Firebase from privileged environments
  • Vercel - Hosting platform for serverless functions

fct-api's People

Contributors

unicornware avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.