Skip to content

Secure token generator for FCS API in 10 programming languages - Generate HMAC-SHA256 tokens for frontend JavaScript authentication without exposing API keys.

Notifications You must be signed in to change notification settings

fcsapi/token-generator

FCS API - Token Generator

Generate secure tokens for frontend JavaScript authentication in 10 programming languages.

License: MIT

Available Languages

Language File
PHP token-generator.php
Python token-generator.py
JavaScript token-generator.js
Java TokenGenerator.java
Ruby token_generator.rb
C# TokenGenerator.cs
Go token_generator.go
Rust token_generator.rs
Swift TokenGenerator.swift
Kotlin TokenGenerator.kt

Installation

Clone Full Repository

git clone https://github.com/fcsapi/token-generator

Download Single File

# PHP only
curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/token-generator.php

# Python only
curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/token-generator.py

# JavaScript only
curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/token-generator.js

# Java only
curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/TokenGenerator.java

# Ruby only
curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/token_generator.rb

# C# only
curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/TokenGenerator.cs

# Go only
curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/token_generator.go

# Rust only
curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/token_generator.rs

# Swift only
curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/TokenGenerator.swift

# Kotlin only
curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/TokenGenerator.kt

Or Download from GitHub

Go to GitHub, click on the file you need, then click "Download raw file".

Usage

PHP

$generator = new FcsTokenGenerator('your_access_key', 'your_public_key');
$tokenData = $generator->generateToken();
// Returns: ['_token' => '...', '_expiry' => 1234567890, '_public_key' => '...']

Python

generator = FcsTokenGenerator('your_access_key', 'your_public_key')
token_data = generator.generate_token()
# Returns: {'_token': '...', '_expiry': 1234567890, '_public_key': '...'}

JavaScript (Node.js)

const generator = new FcsTokenGenerator('your_access_key', 'your_public_key');
const tokenData = generator.generateToken();
// Returns: { _token: '...', _expiry: 1234567890, _public_key: '...' }

Java

TokenGenerator generator = new TokenGenerator("your_access_key", "your_public_key");
Map<String, Object> tokenData = generator.generateToken();

Ruby

generator = FcsTokenGenerator.new('your_access_key', 'your_public_key')
token_data = generator.generate_token

C#

var generator = new TokenGenerator("your_access_key", "your_public_key");
var tokenData = generator.GenerateToken();

Go

generator := NewTokenGenerator("your_access_key", "your_public_key", 3600)
tokenData := generator.GenerateToken()

Rust

let generator = TokenGenerator::new("your_access_key", "your_public_key", None);
let token_data = generator.generate_token();

Swift

let generator = FcsTokenGenerator(accessKey: "your_access_key", publicKey: "your_public_key")
let tokenData = generator.generateToken()

Kotlin

val generator = FcsTokenGenerator("your_access_key", "your_public_key")
val tokenData = generator.generateToken()

Token Expiry Options

Seconds Duration
300 5 minutes
900 15 minutes
1800 30 minutes
3600 1 hour (default)
86400 24 hours

How It Works

  1. Backend generates a secure token using HMAC-SHA256
  2. Backend sends token data to frontend (via API or meta tags)
  3. Frontend uses token for FCS API calls (no API key exposed)
┌─────────────────┐         ┌─────────────────┐         ┌─────────────────┐
│     Backend     │         │    Frontend     │         │    FCS API      │
│  (Your Server)  │         │   (Browser)     │         │                 │
└────────┬────────┘         └────────┬────────┘         └────────┬────────┘
         │                           │                           │
         │  1. Generate Token        │                           │
         │  (using access_key)       │                           │
         │                           │                           │
         │  2. Send token data       │                           │
         │ ─────────────────────────>│                           │
         │                           │                           │
         │                           │  3. API Request           │
         │                           │  (with token)             │
         │                           │ ─────────────────────────>│
         │                           │                           │
         │                           │  4. Response              │
         │                           │ <─────────────────────────│
         │                           │                           │

Get API Keys

  1. Visit FCS API
  2. Sign up for a free account
  3. Get your Access Key and Public Key from the dashboard

Documentation

Support

License

MIT License - see LICENSE file for details.

About

Secure token generator for FCS API in 10 programming languages - Generate HMAC-SHA256 tokens for frontend JavaScript authentication without exposing API keys.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published