Generate authorization token for local user - Fabric

Generate authorization token for local user

cURL

curl --request POST \
  --url https://prod01-apigw.yourcompany.fabric.zone/api-identity/auth/local/login \
  --header 'Content-Type: application/json' \
  --header 'x-site-context: <x-site-context>' \
  --data '\n{\n  "accountId": 4781348886,\n  "username": "john@fabric.inc",\n  "password": "joHn@123456789!"\n}'

Python

import requests

url = "https://prod01-apigw.yourcompany.fabric.zone/api-identity/auth/local/login"

payload = {
    "accountId": 4781348886,
    "username": "john@fabric.inc",
    "password": "joHn@123456789!"
}
headers = {
    "x-site-context": "<x-site-context>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)

JavaScript

const options = {
  method: 'POST',
  headers: {'x-site-context': '<x-site-context>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    accountId: 4781348886,
    username: 'john@fabric.inc',
    password: 'joHn@123456789!'
  })
};

fetch('https://prod01-apigw.yourcompany.fabric.zone/api-identity/auth/local/login', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));

PHP

<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://prod01-apigw.yourcompany.fabric.zone/api-identity/auth/local/login",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",\
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'accountId' => 4781348886,
    'username' => 'john@fabric.inc',
    'password' => 'joHn@123456789!'
  ]),
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json",
    "x-site-context: <x-site-context>"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
?>

Go

package main

import (
    "fmt"
    "strings"
    "net/http"
    "io"
)

func main() {

url := "https://prod01-apigw.yourcompany.fabric.zone/api-identity/auth/local/login"

payload := strings.NewReader("{\n  \"accountId\": 4781348886,\n  \"username\": \"john@fabric.inc\",\n  \"password\": \"joHn@123456789!\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("x-site-context", "<x-site-context>")
    req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
    body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))
}

Java

HttpResponse<String> response = Unirest.post("https://prod01-apigw.yourcompany.fabric.zone/api-identity/auth/local/login")
  .header("x-site-context", "<x-site-context>")
  .header("Content-Type", "application/json")
  .body("{\n  \"accountId\": 4781348886,\n  \"username\": \"john@fabric.inc\",\n  \"password\": \"joHn@123456789!\"\n}")
  .asString();

Ruby

require 'uri'
require 'net/http'

url = URI("https://prod01-apigw.yourcompany.fabric.zone/api-identity/auth/local/login")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-site-context"] = '<x-site-context>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"accountId\": 4781348886,\n  \"username\": \"john@fabric.inc\",\n  \"password\": \"joHn@123456789!\"\n}"

response = http.request(request)
puts response.read_body

Responses

Success (200)

{
  "_id": "60c3a2c476f9c21239d836ca",
  "account": {
    "accountId": 8739392294
  },
  "roles": [
    "Admin"
  ],
  "permissions": [
    "read:user"
  ],
  "refreshToken": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVC.eyJpZCI6IjYwYzNhMmM0....",
  "accessToken": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVC.eyJpZCI6IjYwYzNhMmM0...."
}

Bad Request (400)

{
  "code": "BAD_REQUEST",
  "message": "Bad Request"
}

Internal Server Error (500)

{
  "code": "INTERNAL_SERVER_ERROR",
  "message": "Internal server error."
}

Headers

Body

Response