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

The code in every language

Each example is the inside of main, written in every language API Maker runs : pick yours in the tabs, and every page shows it from then on. The types a call takes (GetAll, DeepItem…) are those of am : from am import GetAll in Python, use am::GetAll; in Rust, import am.GetAll; in Java and Kotlin ; PHP and C# have them without an import, Go names them am.GetAll.

Who calls : g.req.auth

Every provider which checked a token of the call leaves what it found in g.req.auth : the application in authAMUser, the person in authAMDB, authGoogle, authAzure, authAWS or authCustom. The sign-in providers page says how each one is set up.

The API user

The application behind x-am-authorization, from the token API.

const apiUserAuth = g.req.auth.authAMUser; // the API user of the token of x-am-authorization
api_user_auth = g.req.auth.authAMUser  # the API user of the token of x-am-authorization
$apiUserAuth = $g->req->auth->authAMUser; // the API user of the token of x-am-authorization
var apiUserAuth = g.Req.Auth.GetObject("authAMUser"); // the API user of the token of x-am-authorization
apiUserAuth := g.Req.Auth().Map("authAMUser") // the API user of the token of x-am-authorization
let api_user_auth = &g.req.auth()["authAMUser"]; // the API user of the token of x-am-authorization
JsonObject apiUserAuth = g.req.getAuth().getObject("authAMUser"); // the API user of the token of x-am-authorization
val apiUserAuth = g.req.auth.getObject("authAMUser") // the API user of the token of x-am-authorization

A person of your users table

The person behind x-am-user-authorization, a row of the table of a DB token generator.

const databaseUserAuth = g.req.auth.authAMDB; // the row of the person, without its password
database_user_auth = g.req.auth.authAMDB  # the row of the person, without its password
$databaseUserAuth = $g->req->auth->authAMDB; // the row of the person, without its password
var databaseUserAuth = g.Req.Auth.GetObject("authAMDB"); // the row of the person, without its password
databaseUserAuth := g.Req.Auth().Map("authAMDB") // the row of the person, without its password
let database_user_auth = &g.req.auth()["authAMDB"]; // the row of the person, without its password
JsonObject databaseUserAuth = g.req.getAuth().getObject("authAMDB"); // the row of the person, without its password
val databaseUserAuth = g.req.auth.getObject("authAMDB") // the row of the person, without its password

A login API which gets both tokens

import * as T from 'types';

// A login API (apiAccessType : IS_PUBLIC) : the token of the API user 'default' for the app, and the token of the
// person whose email and password the body brings, checked by the DB token generator 'users_tg'.
async function main(g: T.IAMGlobal) {
    const password = await g.sys.system.getSecret('common.apiUserPasswords.default');
    const [app, person] = await g.sys.system.getToken([
        { u: 'default', p: password },
        { name: 'users_tg', u: g.req.body.email, p: g.req.body.password },
    ]);
    return { amToken: app.token, amDbToken: person.token, refreshToken: person.refresh_token };
}
module.exports = main;
from am import G, GetToken


# A login API (apiAccessType : IS_PUBLIC) : the token of the API user 'default' for the app, and the token of the
# person whose email and password the body brings, checked by the DB token generator 'users_tg'.
async def main(g: G):
    password = await g.sys.system.get_secret('common.apiUserPasswords.default')
    app, person = await g.sys.system.get_tokens([
        GetToken('default', password),
        GetToken(g.req.body.email, g.req.body.password, name='users_tg'),
    ])
    return {'amToken': app.token, 'amDbToken': person.token, 'refreshToken': person.refresh_token}
<?php
// A login API (apiAccessType : IS_PUBLIC) : the token of the API user 'default' for the app, and the token of the
// person whose email and password the body brings, checked by the DB token generator 'users_tg'.
function main(AmG $g)
{
    $password = $g->sys->system->getSecret('common.apiUserPasswords.default');
    [$app, $person] = $g->sys->system->getTokens([
        new GetToken('default', $password),
        new GetToken($g->req->body->email, $g->req->body->password, name: 'users_tg'),
    ]);
    return ['amToken' => $app->token, 'amDbToken' => $person->token, 'refreshToken' => $person->refresh_token];
}
// A login API (apiAccessType : IS_PUBLIC) : the token of the API user 'default' for the app, and the token of the
// person whose email and password the body brings, checked by the DB token generator 'users_tg'.
file static class Api
{
    public static async Task<object?> Main(G g)
    {
        var password = (await g.Sys.System.GetSecret("common.apiUserPasswords.default"))?.GetValue<string>();
        var tokens = await g.Sys.System.GetTokens([
            new GetToken("default", password),
            new GetToken(g.Req.Body.GetString("email"), g.Req.Body.GetString("password")) { Name = "users_tg" },
        ]);
        return new { amToken = tokens[0].Token, amDbToken = tokens[1].Token, refreshToken = tokens[1].RefreshToken };
    }
}
// A login API (apiAccessType : IS_PUBLIC) : the token of the API user 'default' for the app, and the token of the
// person whose email and password the body brings, checked by the DB token generator 'users_tg'.
package code

import "apimaker/am"

func Main(g *am.G) (any, error) {
    secret, err := g.Sys.System.GetSecret("common.apiUserPasswords.default")
    if err != nil {
        return nil, err
    }
    password, _ := secret.(string)
    body := g.Req.Body()
    tokens, err := g.Sys.System.GetTokens([]am.GetToken{
        {U: "default", P: password},
        {Name: "users_tg", U: body.String("email"), P: body.String("password")},
    })
    if err != nil {
        return nil, err
    }
    return am.M{"amToken": tokens[0].Token, "amDbToken": tokens[1].Token, "refreshToken": tokens[1].RefreshToken}, nil
}
// A login API (apiAccessType : IS_PUBLIC) : the token of the API user 'default' for the app, and the token of the
// person whose email and password the body brings, checked by the DB token generator 'users_tg'.
use am::{Errors, G, GetToken, Value, json};

pub fn main(g: &mut G) -> Result<Value, Errors> {
    let password = g.sys.system.get_secret("common.apiUserPasswords.default", None)?;
    let body = g.req.body();
    let tokens = g.sys.system.get_tokens(vec![
        GetToken::new("default", password.as_str().unwrap_or_default()),
        GetToken::new(body["email"].as_str().unwrap_or_default(), body["password"].as_str().unwrap_or_default()).name("users_tg"),
    ])?;
    Ok(json!({ "amToken": tokens[0].token, "amDbToken": tokens[1].token, "refreshToken": tokens[1].refresh_token }))
}
// A login API (apiAccessType : IS_PUBLIC) : the token of the API user 'default' for the app, and the token of the
// person whose email and password the body brings, checked by the DB token generator 'users_tg'.
import am.G;
import am.GetToken;
import am.JsonObject;
import am.TokenResponse;
import java.util.List;

class Api {
    static Object main(G g) {
        String password = (String) g.sys.system.getSecret("common.apiUserPasswords.default");
        JsonObject body = g.req.getBody();
        List<TokenResponse> tokens = g.sys.system.getTokens(List.of(
            new GetToken("default", password),
            new GetToken(body.getString("email"), body.getString("password")).name("users_tg")));
        return JsonObject.of("amToken", tokens.get(0).getToken(), "amDbToken", tokens.get(1).getToken(), "refreshToken", tokens.get(1).getRefreshToken());
    }
}
// A login API (apiAccessType : IS_PUBLIC) : the token of the API user 'default' for the app, and the token of the
// person whose email and password the body brings, checked by the DB token generator 'users_tg'.
import am.G
import am.GetToken

fun main(g: G): Any? {
    val password = g.sys.system.getSecret("common.apiUserPasswords.default") as String
    val body = g.req.body
    val (app, person) = g.sys.system.getTokens(
        listOf(
            GetToken("default", password),
            GetToken(body.getString("email"), body.getString("password")).name("users_tg"),
        ),
    )
    return mapOf("amToken" to app.token, "amDbToken" to person.token, "refreshToken" to person.refreshToken)
}
  • The token of a person, a row of the table of the token generator users_tg, from the token API :
1
2
3
4
5
{
    "name": "users_tg",
    "u": "USER_NAME",
    "p": "PASSWORD"
}

Google, Azure AD and AWS Cognito

The opened token of the provider, with the columns its groupsDataSource selected from your table.

Google

const googleAuth = g.req.auth.authGoogle; // the opened token of x-google-authorization
google_auth = g.req.auth.authGoogle  # the opened token of x-google-authorization
$googleAuth = $g->req->auth->authGoogle; // the opened token of x-google-authorization
var googleAuth = g.Req.Auth.GetObject("authGoogle"); // the opened token of x-google-authorization
googleAuth := g.Req.Auth().Map("authGoogle") // the opened token of x-google-authorization
let google_auth = &g.req.auth()["authGoogle"]; // the opened token of x-google-authorization
JsonObject googleAuth = g.req.getAuth().getObject("authGoogle"); // the opened token of x-google-authorization
val googleAuth = g.req.auth.getObject("authGoogle") // the opened token of x-google-authorization

Azure AD

const azureAuth = g.req.auth.authAzure; // the opened token of x-azure-authorization
azure_auth = g.req.auth.authAzure  # the opened token of x-azure-authorization
$azureAuth = $g->req->auth->authAzure; // the opened token of x-azure-authorization
var azureAuth = g.Req.Auth.GetObject("authAzure"); // the opened token of x-azure-authorization
azureAuth := g.Req.Auth().Map("authAzure") // the opened token of x-azure-authorization
let azure_auth = &g.req.auth()["authAzure"]; // the opened token of x-azure-authorization
JsonObject azureAuth = g.req.getAuth().getObject("authAzure"); // the opened token of x-azure-authorization
val azureAuth = g.req.auth.getObject("authAzure") // the opened token of x-azure-authorization

AWS Cognito

const awsAuth = g.req.auth.authAWS; // the opened token of x-aws-authorization
aws_auth = g.req.auth.authAWS  # the opened token of x-aws-authorization
$awsAuth = $g->req->auth->authAWS; // the opened token of x-aws-authorization
var awsAuth = g.Req.Auth.GetObject("authAWS"); // the opened token of x-aws-authorization
awsAuth := g.Req.Auth().Map("authAWS") // the opened token of x-aws-authorization
let aws_auth = &g.req.auth()["authAWS"]; // the opened token of x-aws-authorization
JsonObject awsAuth = g.req.getAuth().getObject("authAWS"); // the opened token of x-aws-authorization
val awsAuth = g.req.auth.getObject("authAWS") // the opened token of x-aws-authorization

A provider of your own

The result of your token validator, in g.req.auth.authCustom : see the custom provider example.