Skip to main content

Authentication with Username and Password

This approach requires a username and password to generate an access and refresh token.

Authentication process

The process begins by looking up the user in the database. Once the user has successfully been found, it checks the user role for an affiliate id. An access and refresh token are then created with an expiration time.

Curl Example

curl --header "Content-Type: application/json" \ --request POST \ --data '{"username": "user_name", "password": "password"}' \ https://quinix.byteconnect.us/auth

Python Example

import requests
from os import getenv

username = getenv("username")
password = getenv("password")
body = {"username" : username, "password" : password}

url = getenv("bytefederal_api_url")

request = requests.post(f"{url}/auth", json=body)
response = request.json()

The code will return:

{"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", "refresh_token": "test_refresh_token"}

NodeJS example

async function UserLogin() {
const username = process.env.USERNAME;
const password = process.env.PASSWORD;
const bodyData = {
"username": username,
"password": password
}
const url = `${process.env.BYTECONNECTURL}/auth`;
const request = await fetch(url, {
method: "POST",
body=JSON,stringify(bodyData),
headers: {
"Content-Type": "application/json"
}
}
);
const response = await request.json();
console.log(response);
}

HTTP Codes

200

Returns a JSON encoded response of an access token and an refresh token.

401

Username or password was invalid.