¶ Available Node Modules
Currently, the following Node Modules can be used in the GenAuth Pipeline:
- GenAuth SDK for Node.js (opens new window)
- Network request library axios (opens new window)
- lodash
- GenAuth built-in tool set function utils
¶ GenAuth SDK for Node.js
For security reasons, GenAuth will be initialized in a special way using your user pool ID (userPoolId) and user pool key (secret) authing-js-sdk, this process will not send your user pool key to the public network. You can use the global variable authing, **do not initialize the SDK again! **
Developers can directly use the authing instance after initialization, no need to initialize manually! GenAuth Pipeline will automatically help developers take care of the initialization process.
As shown below:
async function pipe(user, context, callback) {
// Judge whether the user's mailbox ends with @genauth.ai
if (!user.email.endsWith("@genauth.ai")) {
return callback(null, user, context);
}
try {
// Call API to add a role to the user
await authing.roles.addUsers("ROLE", [user.id]);
} catch (error) {}
callback(null, user, context);
}
In addUsers(), we use env.ROOT_GROUP_ID to obtain the group ID through the environment variable, which avoids hard coding. For how to use environment variables in Pipeline functions, see Using Environment Variables. For how to use callbacks and the complete API of Pipeline functions, see Pipeline Function API Documentation.
¶ Network request library
Currently GenAuth supports the use of axios and supports async/await syntax 🚀!
For detailed documentation of axios, please go to its official documentation (opens new window).
¶ lodash
Developers need to import manually:
const lodash = require("lodash");
For detailed documentation, please go to its official documentation (opens new window).
¶ Built-in tool set utils
GenAuth has some built-in encapsulated practical functions for developers to call directly.
Developers need to import manually:
const utils = require("./utils");
¶ Check if the IP is within the IP range
Usage:
utils.ipRangeCheck(IP, [start, end]);
The return value is boolean.
Example: The following Pipeline function implements the function of registering an IP range whitelist.
async function pipe(context, callback) {
const utils = require("./utils");
const ip = context.ip;
if (ip && utils.ipRangeCheck(ip, ["110.53.254.1", "110.53.254.255"])) {
return callback(null, context);
}
return callback(new Error("Access Denied!"));
}
¶ Other Node built-in modules
GenAuth Pipeline uses the node8 engine, and all node8 built-in modules (opens new window) can be used, such as querystring, etc.
