Skip to content
This page View Markdown Open in ChatGPT Open in Claude

Auth of an API user

Every non-public API needs the token of an API user : the application calling. It is the first of the two gates.

Header x-am-authorization: <token>
Get it POST /api/system-api/<user path>/token with { "u", "p", "expiresInSeconds"? }
Answer { "token", "refresh_token", "expires_in" }
In code g.req.auth.authAMUser : the API user, with its name and groups.
Get the token
{ "u": "default", "p": "12345", "expiresInSeconds": 259200 }
Who is calling
const apiUser = g.req.auth.authAMUser;
g.logger.log(apiUser.name, apiUser.groups);
Who is calling
api_user = g.req.auth.authAMUser
g.logger.log(api_user.name, api_user.groups)
Who is calling
$apiUser = $g->req->auth->authAMUser;
$g->logger->log($apiUser->name, $apiUser->groups);
Who is calling
var apiUser = g.Req.Auth.GetObject("authAMUser");
g.Logger.Log(apiUser.GetString("name"), apiUser["groups"]);
Who is calling
apiUser := g.Req.Auth().Map("authAMUser")
g.Logger.Log(apiUser.String("name"), apiUser.List("groups"))
Who is calling
let api_user = &g.req.auth()["authAMUser"];
g.logger.log(format!("{} {}", api_user["name"], api_user["groups"]));
Who is calling
JsonObject apiUser = g.req.getAuth().getObject("authAMUser");
g.logger.log(apiUser.getString("name"), apiUser.getList("groups"));
Who is calling
val apiUser = g.req.auth.getObject("authAMUser")
g.logger.log(apiUser.getString("name"), apiUser.getList("groups"))
  • expiresInSeconds is optional : Tokens Expire After of the Deployment Settings otherwise, 72 hours by default. Refresh with { "refresh_token" } while the refresh token is valid (refreshTokenValidForS after the token expired, 900 seconds by default).
  • The groups of the API user decide which APIs, tables and fields the application reaches. A person token, when the API asks for one, narrows it further.