UNPKG

@cobuildlab/auth0-utils

Version:

This is package to deal with common scenarios working with auth0 platform

79 lines (78 loc) 4.24 kB
import { AccessTokenAuth0 } from './types'; import { Response as NodeFetchRespose } from 'node-fetch'; /** * This action create a auth0 users. * * @param {string} email - Email to create the user. * @param {string} access_token - Need the access token of auth0, you need this obligatory. * @param {string} auth0UsersUrl - This is a url of auth0 project, you can get this in the doc of auth0. Example: https://your-app.us.auth0.com/api/v2/users. * @returns {Promise<any>} - Success data if created the user. * @private */ export declare const createAuth0User: (email: string, access_token: string, auth0UsersUrl: string) => Promise<any>; /** * @description Fetch user by email on auth0. * * @param {string} email - Email of the user to look all data of user in auth0. * @param {string} access_token - Api access token. * @param {string} token_type - The type of api token. * @param {string} url - Url to fetch the users by email on auth0. Example: https://your-app.us.auth0.com/api/v2/users-by-email?email=. * * @returns {Promise<string | undefined>} The id of the user to be blocked. * @private */ export declare const fetchUserByEmailOnAuth0: (email: string, access_token: string, token_type: string, url: string) => Promise<string | undefined>; /** * @description Function to fetch auth0 access token. * @param {string} fetchTokenUrl - Url to fetch auth0 token. Example: https://your-app.us.auth0.com/oauth/token. * @param {string} auth0Audience - Auth0 audience of your project. Example: https://your-app.us.auth0.com/api/v2/. * @param {string} auth0MachineClientId - Need a M2M client id. Example: IAx2aVXfXUNW1qjk4sQYtMMRoWFSM6wx. * @param {string} auth0MachineSecret - Need a M2M client secret. Example: PZJJKWuBQcUc610fyGaLP4mVV6S9kHYyHSreup8A4Ltum7yAWgPTKzX4YxkydShb. * @returns {Promise<AccessTokenAuth0>} The access token and token type for conections with the API. * @private */ export declare const fetchAccessTokenOnAuth0: (fetchTokenUrl: string, auth0Audience: string, auth0MachineClientId: string, auth0MachineSecret: string) => Promise<AccessTokenAuth0>; /** * @description Request email verification from Auth0. * * @param {string} auth_domain - Auth0's auth domain. * @param {string} access_token - Auth0's management api access token (see {@linkcode fetchAccessTokenOnAuth0}). * @param {string} user_id - Authenticated user ID. * @param {string} client_id - Auth0's machine client ID. * @param {string} provider - User's authentication provider. * * @returns {Promise<void>} - Gracefully exit if job was successfully created. * * @private */ export declare const sendAuth0EmailVerification: (auth_domain: string, access_token: string, user_id: string, client_id: string, provider: string) => Promise<void>; /** * This action updates an auth0 user. * * @param {string} user_id - ID of the user to be updated. * @param {string} access_token - Auth0 access token. Required. * @param {string} auth_domain - This is the url of the auth0 project, you can get this in the doc of auth0. Example: https://your-app.us.auth0.com/api/v2/users. * @param {Object} data - Data to be updated. * @returns {Promise<any>} - Success data if user is updated. * @private */ export declare const updateAuth0User: (user_id: string, access_token: string, auth_domain: string, data: any) => Promise<any>; /** * @param promise - Input promise. * @returns Promise Result. */ export declare function hanldeFetch<T>(promise: Promise<Response> | Promise<NodeFetchRespose>): Promise<T>; /** * This action updates an auth0 user. * * @param {string} fetchTokenUrl - Token url. * @param {string} username - Username or email. * @param {string} password - Current user password. * @param {Object} auth0Audience - Audience. * @param {string} auth0MachineClientId - Cliend id required. * @param {string} auth0MachineSecret - Secret Cliend id required. * @param {Object} scope - Data to be updated. * @returns {Promise<any>} - Success data if user is updated. * @private */ export declare const fetchUserToken: (fetchTokenUrl: string, username: string, password: string, auth0Audience: string, auth0MachineClientId: string, auth0MachineSecret: string, scope?: string) => Promise<AccessTokenAuth0>;