PHP
<?php
// Your API username and password
$apiUsername = 'your_username';
$apiPassword = 'your_password';
// Concatenating username and password with colon
$credentials = $apiUsername . ':' . $apiPassword;
// Base64 encode the credentials
$encodedCredentials = base64_encode($credentials);
// Creating the Basic Auth token
$basicAuthToken = 'Basic ' . $encodedCredentials;
// Output the token
echo $basicAuthToken;
Python
import base64
# Your API username and password
api_username = 'your_username'
api_password = 'your_password'
# Concatenate username and password with colon
credentials = f"{api_username}:{api_password}"
# Base64 encode the credentials
encoded_credentials = base64.b64encode(credentials.encode()).decode()
# Create the Basic Auth token
basic_auth_token = f"Basic {encoded_credentials}"
# Output the token
print(basic_auth_token)
Node.js
// Your API username and password
const apiUsername = 'your_username';
const apiPassword = 'your_password';
// Concatenate username and password with colon
const credentials = `${apiUsername}:${apiPassword}`;
// Base64 encode the credentials
const encodedCredentials = Buffer.from(credentials).toString('base64');
// Create the Basic Auth token
const basicAuthToken = `Basic ${encodedCredentials}`;
// Output the token
console.log(basicAuthToken);
Java
import java.util.Base64;
public class AuthTokenGenerator {
public static void main(String[] args) {
// Your API username and password
String apiUsername = "your_username";
String apiPassword = "your_password";
// Concatenate username and password with colon
String credentials = apiUsername + ":" + apiPassword;
// Base64 encode the credentials
String encodedCredentials = Base64.getEncoder()
.encodeToString(credentials.getBytes());
// Create the Basic Auth token
String basicAuthToken = "Basic " + encodedCredentials;
// Output the token
System.out.println(basicAuthToken);
}
}
C#
using System;
using System.Text;
class Program
{
static void Main()
{
// Your API username and password
string apiUsername = "your_username";
string apiPassword = "your_password";
// Concatenate username and password with colon
string credentials = $"{apiUsername}:{apiPassword}";
// Base64 encode the credentials
string encodedCredentials = Convert.ToBase64String(
Encoding.UTF8.GetBytes(credentials));
// Create the Basic Auth token
string basicAuthToken = $"Basic {encodedCredentials}";
// Output the token
Console.WriteLine(basicAuthToken);
}
}
Go
package main
import (
"encoding/base64"
"fmt"
)
func main() {
// Your API username and password
apiUsername := "your_username"
apiPassword := "your_password"
// Concatenate username and password with colon
credentials := apiUsername + ":" + apiPassword
// Base64 encode the credentials
encodedCredentials := base64.StdEncoding.EncodeToString(
[]byte(credentials))
// Create the Basic Auth token
basicAuthToken := "Basic " + encodedCredentials
// Output the token
fmt.Println(basicAuthToken)
}
Ruby
require 'base64'
# Your API username and password
api_username = 'your_username'
api_password = 'your_password'
# Concatenate username and password with colon
credentials = "#{api_username}:#{api_password}"
# Base64 encode the credentials
encoded_credentials = Base64.strict_encode64(credentials)
# Create the Basic Auth token
basic_auth_token = "Basic #{encoded_credentials}"
# Output the token
puts basic_auth_token