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.
A person of your users table¶
The person behind x-am-user-authorization, a row of the table of a DB token generator.
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 :
Google, Azure AD and AWS Cognito¶
The opened token of the provider, with the columns its groupsDataSource selected from your table.
Google¶
Azure AD¶
AWS Cognito¶
A provider of your own¶
The result of your token validator, in g.req.auth.authCustom : see the custom provider example.