|
| 1 | +# FCS API - Token Generator |
| 2 | + |
| 3 | +Generate secure tokens for frontend JavaScript authentication in **10 programming languages**. |
| 4 | + |
| 5 | +[](https://opensource.org/licenses/MIT) |
| 6 | + |
| 7 | +## Available Languages |
| 8 | + |
| 9 | +| Language | File | |
| 10 | +|----------|------| |
| 11 | +| PHP | `token-generator.php` | |
| 12 | +| Python | `token-generator.py` | |
| 13 | +| JavaScript | `token-generator.js` | |
| 14 | +| Java | `TokenGenerator.java` | |
| 15 | +| Ruby | `token_generator.rb` | |
| 16 | +| C# | `TokenGenerator.cs` | |
| 17 | +| Go | `token_generator.go` | |
| 18 | +| Rust | `token_generator.rs` | |
| 19 | +| Swift | `TokenGenerator.swift` | |
| 20 | +| Kotlin | `TokenGenerator.kt` | |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +### Clone Full Repository |
| 25 | +```bash |
| 26 | +git clone https://github.com/fcsapi/token-generator |
| 27 | +``` |
| 28 | + |
| 29 | +### Download Single File |
| 30 | +```bash |
| 31 | +# PHP only |
| 32 | +curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/token-generator.php |
| 33 | + |
| 34 | +# Python only |
| 35 | +curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/token-generator.py |
| 36 | + |
| 37 | +# JavaScript only |
| 38 | +curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/token-generator.js |
| 39 | + |
| 40 | +# Java only |
| 41 | +curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/TokenGenerator.java |
| 42 | + |
| 43 | +# Ruby only |
| 44 | +curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/token_generator.rb |
| 45 | + |
| 46 | +# C# only |
| 47 | +curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/TokenGenerator.cs |
| 48 | + |
| 49 | +# Go only |
| 50 | +curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/token_generator.go |
| 51 | + |
| 52 | +# Rust only |
| 53 | +curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/token_generator.rs |
| 54 | + |
| 55 | +# Swift only |
| 56 | +curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/TokenGenerator.swift |
| 57 | + |
| 58 | +# Kotlin only |
| 59 | +curl -O https://raw.githubusercontent.com/fcsapi/token-generator/main/TokenGenerator.kt |
| 60 | +``` |
| 61 | + |
| 62 | +### Or Download from GitHub |
| 63 | +Go to [GitHub](https://github.com/fcsapi/token-generator), click on the file you need, then click "Download raw file". |
| 64 | + |
| 65 | +## Usage |
| 66 | + |
| 67 | +### PHP |
| 68 | +```php |
| 69 | +$generator = new FcsTokenGenerator('your_access_key', 'your_public_key'); |
| 70 | +$tokenData = $generator->generateToken(); |
| 71 | +// Returns: ['_token' => '...', '_expiry' => 1234567890, '_public_key' => '...'] |
| 72 | +``` |
| 73 | + |
| 74 | +### Python |
| 75 | +```python |
| 76 | +generator = FcsTokenGenerator('your_access_key', 'your_public_key') |
| 77 | +token_data = generator.generate_token() |
| 78 | +# Returns: {'_token': '...', '_expiry': 1234567890, '_public_key': '...'} |
| 79 | +``` |
| 80 | + |
| 81 | +### JavaScript (Node.js) |
| 82 | +```javascript |
| 83 | +const generator = new FcsTokenGenerator('your_access_key', 'your_public_key'); |
| 84 | +const tokenData = generator.generateToken(); |
| 85 | +// Returns: { _token: '...', _expiry: 1234567890, _public_key: '...' } |
| 86 | +``` |
| 87 | + |
| 88 | +### Java |
| 89 | +```java |
| 90 | +TokenGenerator generator = new TokenGenerator("your_access_key", "your_public_key"); |
| 91 | +Map<String, Object> tokenData = generator.generateToken(); |
| 92 | +``` |
| 93 | + |
| 94 | +### Ruby |
| 95 | +```ruby |
| 96 | +generator = FcsTokenGenerator.new('your_access_key', 'your_public_key') |
| 97 | +token_data = generator.generate_token |
| 98 | +``` |
| 99 | + |
| 100 | +### C# |
| 101 | +```csharp |
| 102 | +var generator = new TokenGenerator("your_access_key", "your_public_key"); |
| 103 | +var tokenData = generator.GenerateToken(); |
| 104 | +``` |
| 105 | + |
| 106 | +### Go |
| 107 | +```go |
| 108 | +generator := NewTokenGenerator("your_access_key", "your_public_key", 3600) |
| 109 | +tokenData := generator.GenerateToken() |
| 110 | +``` |
| 111 | + |
| 112 | +### Rust |
| 113 | +```rust |
| 114 | +let generator = TokenGenerator::new("your_access_key", "your_public_key", None); |
| 115 | +let token_data = generator.generate_token(); |
| 116 | +``` |
| 117 | + |
| 118 | +### Swift |
| 119 | +```swift |
| 120 | +let generator = FcsTokenGenerator(accessKey: "your_access_key", publicKey: "your_public_key") |
| 121 | +let tokenData = generator.generateToken() |
| 122 | +``` |
| 123 | + |
| 124 | +### Kotlin |
| 125 | +```kotlin |
| 126 | +val generator = FcsTokenGenerator("your_access_key", "your_public_key") |
| 127 | +val tokenData = generator.generateToken() |
| 128 | +``` |
| 129 | + |
| 130 | +## Token Expiry Options |
| 131 | + |
| 132 | +| Seconds | Duration | |
| 133 | +|---------|----------| |
| 134 | +| 300 | 5 minutes | |
| 135 | +| 900 | 15 minutes | |
| 136 | +| 1800 | 30 minutes | |
| 137 | +| 3600 | 1 hour (default) | |
| 138 | +| 86400 | 24 hours | |
| 139 | + |
| 140 | +## How It Works |
| 141 | + |
| 142 | +1. **Backend** generates a secure token using HMAC-SHA256 |
| 143 | +2. **Backend** sends token data to frontend (via API or meta tags) |
| 144 | +3. **Frontend** uses token for FCS API calls (no API key exposed) |
| 145 | + |
| 146 | +``` |
| 147 | +┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ |
| 148 | +│ Backend │ │ Frontend │ │ FCS API │ |
| 149 | +│ (Your Server) │ │ (Browser) │ │ │ |
| 150 | +└────────┬────────┘ └────────┬────────┘ └────────┬────────┘ |
| 151 | + │ │ │ |
| 152 | + │ 1. Generate Token │ │ |
| 153 | + │ (using access_key) │ │ |
| 154 | + │ │ │ |
| 155 | + │ 2. Send token data │ │ |
| 156 | + │ ─────────────────────────>│ │ |
| 157 | + │ │ │ |
| 158 | + │ │ 3. API Request │ |
| 159 | + │ │ (with token) │ |
| 160 | + │ │ ─────────────────────────>│ |
| 161 | + │ │ │ |
| 162 | + │ │ 4. Response │ |
| 163 | + │ │ <─────────────────────────│ |
| 164 | + │ │ │ |
| 165 | +``` |
| 166 | + |
| 167 | +## Get API Keys |
| 168 | + |
| 169 | +1. Visit [FCS API](https://fcsapi.com) |
| 170 | +2. Sign up for a free account |
| 171 | +3. Get your **Access Key** and **Public Key** from the [dashboard](https://fcsapi.com/dashboard) |
| 172 | + |
| 173 | +## Documentation |
| 174 | + |
| 175 | +- [Forex API Documentation](https://fcsapi.com/document/forex-api) |
| 176 | +- [Crypto API Documentation](https://fcsapi.com/document/crypto-api) |
| 177 | +- [Stock API Documentation](https://fcsapi.com/document/stock-api) |
| 178 | + |
| 179 | +## Support |
| 180 | + |
| 181 | +- Email: support@fcsapi.com |
| 182 | +- Website: [fcsapi.com](https://fcsapi.com) |
| 183 | + |
| 184 | +## License |
| 185 | + |
| 186 | +MIT License - see [LICENSE](LICENSE) file for details. |
0 commit comments