An open API service indexing awesome lists of open source software.

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

Secure token generator for FCS API in 10 programming languages - Generate HMAC-SHA256 tokens for frontend JavaScript authentication without exposing API keys.
https://github.com/fcsapi/token-generator

fcsapi stock-api

Last synced: 6 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# FCS API - Token Generator

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

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/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
```bash
git clone https://github.com/fcsapi/token-generator
```

### Download Single File
```bash
# 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](https://github.com/fcsapi/token-generator), click on the file you need, then click "Download raw file".

## Usage

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

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

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

### Java
```java
TokenGenerator generator = new TokenGenerator("your_access_key", "your_public_key");
Map tokenData = generator.generateToken();
```

### Ruby
```ruby
generator = FcsTokenGenerator.new('your_access_key', 'your_public_key')
token_data = generator.generate_token
```

### C#
```csharp
var generator = new TokenGenerator("your_access_key", "your_public_key");
var tokenData = generator.GenerateToken();
```

### Go
```go
generator := NewTokenGenerator("your_access_key", "your_public_key", 3600)
tokenData := generator.GenerateToken()
```

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

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

### Kotlin
```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](https://fcsapi.com)
2. Sign up for a free account
3. Get your **Access Key** and **Public Key** from the [dashboard](https://fcsapi.com/dashboard)

## Documentation

- [Forex API Documentation](https://fcsapi.com/document/forex-api)
- [Crypto API Documentation](https://fcsapi.com/document/crypto-api)
- [Stock API Documentation](https://fcsapi.com/document/stock-api)

## Support

- Email: support@fcsapi.com
- Website: [fcsapi.com](https://fcsapi.com)

## License

MIT License - see [LICENSE](LICENSE) file for details.