UNPKG

auth0

Version:

Auth0 Node.js SDK for the Management API v2.

594 lines (593 loc) 40.7 kB
"use strict"; // This file was auto-generated by Fern from our API Definition. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClientsClient = void 0; const BaseClient_js_1 = require("../../../../BaseClient.js"); const core = __importStar(require("../../../../core/index.js")); const headers_js_1 = require("../../../../core/headers.js"); const environments = __importStar(require("../../../../environments.js")); const handleNonStatusCodeError_js_1 = require("../../../../errors/handleNonStatusCodeError.js"); const errors = __importStar(require("../../../../errors/index.js")); const Management = __importStar(require("../../../index.js")); const Client_js_1 = require("../resources/connections/client/Client.js"); const Client_js_2 = require("../resources/credentials/client/Client.js"); class ClientsClient { constructor(options) { this._options = (0, BaseClient_js_1.normalizeClientOptionsWithAuth)(options); } get credentials() { var _a; return ((_a = this._credentials) !== null && _a !== void 0 ? _a : (this._credentials = new Client_js_2.CredentialsClient(this._options))); } get connections() { var _a; return ((_a = this._connections) !== null && _a !== void 0 ? _a : (this._connections = new Client_js_1.ConnectionsClient(this._options))); } /** * Retrieve clients (applications and SSO integrations) matching provided filters. A list of fields to include or exclude may also be specified. * For more information, read <a href="https://www.auth0.com/docs/get-started/applications"> Applications in Auth0</a> and <a href="https://www.auth0.com/docs/authenticate/single-sign-on"> Single Sign-On</a>. * * <ul> * <li> * The following can be retrieved with any scope: * <code>client_id</code>, <code>app_type</code>, <code>name</code>, and <code>description</code>. * </li> * <li> * The following properties can only be retrieved with the <code>read:clients</code> or * <code>read:client_keys</code> scope: * <code>callbacks</code>, <code>oidc_logout</code>, <code>allowed_origins</code>, * <code>web_origins</code>, <code>tenant</code>, <code>global</code>, <code>config_route</code>, * <code>callback_url_template</code>, <code>jwt_configuration</code>, * <code>jwt_configuration.lifetime_in_seconds</code>, <code>jwt_configuration.secret_encoded</code>, * <code>jwt_configuration.scopes</code>, <code>jwt_configuration.alg</code>, <code>api_type</code>, * <code>logo_uri</code>, <code>allowed_clients</code>, <code>owners</code>, <code>custom_login_page</code>, * <code>custom_login_page_off</code>, <code>sso</code>, <code>addons</code>, <code>form_template</code>, * <code>custom_login_page_codeview</code>, <code>resource_servers</code>, <code>client_metadata</code>, * <code>mobile</code>, <code>mobile.android</code>, <code>mobile.ios</code>, <code>allowed_logout_urls</code>, * <code>token_endpoint_auth_method</code>, <code>is_first_party</code>, <code>oidc_conformant</code>, * <code>is_token_endpoint_ip_header_trusted</code>, <code>initiate_login_uri</code>, <code>grant_types</code>, * <code>refresh_token</code>, <code>refresh_token.rotation_type</code>, <code>refresh_token.expiration_type</code>, * <code>refresh_token.leeway</code>, <code>refresh_token.token_lifetime</code>, <code>refresh_token.policies</code>, <code>organization_usage</code>, * <code>organization_require_behavior</code>. * </li> * <li> * The following properties can only be retrieved with the * <code>read:client_keys</code> or <code>read:client_credentials</code> scope: * <code>encryption_key</code>, <code>encryption_key.pub</code>, <code>encryption_key.cert</code>, * <code>client_secret</code>, <code>client_authentication_methods</code> and <code>signing_key</code>. * </li> * </ul> * * @param {Management.ListClientsRequestParameters} request * @param {ClientsClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Management.BadRequestError} * @throws {@link Management.UnauthorizedError} * @throws {@link Management.ForbiddenError} * @throws {@link Management.TooManyRequestsError} * * @example * await client.clients.list({ * fields: "fields", * include_fields: true, * page: 1, * per_page: 1, * include_totals: true, * is_global: true, * is_first_party: true, * app_type: "app_type", * q: "q" * }) */ list() { return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) { const list = core.HttpResponsePromise.interceptFunction((request) => __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r; const { fields, include_fields: includeFields, page = 0, per_page: perPage = 50, include_totals: includeTotals = true, is_global: isGlobal, is_first_party: isFirstParty, app_type: appType, q, } = request; const _queryParams = {}; if (fields !== undefined) { _queryParams["fields"] = fields; } if (includeFields !== undefined) { _queryParams["include_fields"] = (_a = includeFields === null || includeFields === void 0 ? void 0 : includeFields.toString()) !== null && _a !== void 0 ? _a : null; } if (page !== undefined) { _queryParams["page"] = (_b = page === null || page === void 0 ? void 0 : page.toString()) !== null && _b !== void 0 ? _b : null; } if (perPage !== undefined) { _queryParams["per_page"] = (_c = perPage === null || perPage === void 0 ? void 0 : perPage.toString()) !== null && _c !== void 0 ? _c : null; } if (includeTotals !== undefined) { _queryParams["include_totals"] = (_d = includeTotals === null || includeTotals === void 0 ? void 0 : includeTotals.toString()) !== null && _d !== void 0 ? _d : null; } if (isGlobal !== undefined) { _queryParams["is_global"] = (_e = isGlobal === null || isGlobal === void 0 ? void 0 : isGlobal.toString()) !== null && _e !== void 0 ? _e : null; } if (isFirstParty !== undefined) { _queryParams["is_first_party"] = (_f = isFirstParty === null || isFirstParty === void 0 ? void 0 : isFirstParty.toString()) !== null && _f !== void 0 ? _f : null; } if (appType !== undefined) { _queryParams["app_type"] = appType; } if (q !== undefined) { _queryParams["q"] = q; } const _authRequest = yield this._options.authProvider.getAuthRequest(); let _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_g = this._options) === null || _g === void 0 ? void 0 : _g.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_h = this._options.fetcher) !== null && _h !== void 0 ? _h : core.fetcher)({ url: core.url.join((_k = (_j = (yield core.Supplier.get(this._options.baseUrl))) !== null && _j !== void 0 ? _j : (yield core.Supplier.get(this._options.environment))) !== null && _k !== void 0 ? _k : environments.ManagementEnvironment.Default, "clients"), method: "GET", headers: _headers, queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams), timeoutMs: ((_o = (_l = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _l !== void 0 ? _l : (_m = this._options) === null || _m === void 0 ? void 0 : _m.timeoutInSeconds) !== null && _o !== void 0 ? _o : 60) * 1000, maxRetries: (_p = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _p !== void 0 ? _p : (_q = this._options) === null || _q === void 0 ? void 0 : _q.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_r = this._options) === null || _r === void 0 ? void 0 : _r.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Management.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Management.UnauthorizedError(_response.error.body, _response.rawResponse); case 403: throw new Management.ForbiddenError(_response.error.body, _response.rawResponse); case 429: throw new Management.TooManyRequestsError(_response.error.body, _response.rawResponse); default: throw new errors.ManagementError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/clients"); })); let _offset = (request === null || request === void 0 ? void 0 : request.page) != null ? request === null || request === void 0 ? void 0 : request.page : 0; const dataWithRawResponse = yield list(request).withRawResponse(); return new core.Page({ response: dataWithRawResponse.data, rawResponse: dataWithRawResponse.rawResponse, hasNextPage: (response) => { var _a, _b; return ((_a = response === null || response === void 0 ? void 0 : response.clients) !== null && _a !== void 0 ? _a : []).length >= Math.floor((_b = request === null || request === void 0 ? void 0 : request.per_page) !== null && _b !== void 0 ? _b : 50); }, getItems: (response) => { var _a; return (_a = response === null || response === void 0 ? void 0 : response.clients) !== null && _a !== void 0 ? _a : []; }, loadPage: (_response) => { _offset += 1; return list(core.setObjectProperty(request, "page", _offset)); }, }); }); } /** * Create a new client (application or SSO integration). For more information, read <a href="https://www.auth0.com/docs/get-started/auth0-overview/create-applications">Create Applications</a> * <a href="https://www.auth0.com/docs/authenticate/single-sign-on/api-endpoints-for-single-sign-on>">API Endpoints for Single Sign-On</a>. * * Notes: * - We recommend leaving the `client_secret` parameter unspecified to allow the generation of a safe secret. * - The <code>client_authentication_methods</code> and <code>token_endpoint_auth_method</code> properties are mutually exclusive. Use * <code>client_authentication_methods</code> to configure the client with Private Key JWT authentication method. Otherwise, use <code>token_endpoint_auth_method</code> * to configure the client with client secret (basic or post) or with no authentication method (none). * - When using <code>client_authentication_methods</code> to configure the client with Private Key JWT authentication method, specify fully defined credentials. * These credentials will be automatically enabled for Private Key JWT authentication on the client. * - To configure <code>client_authentication_methods</code>, the <code>create:client_credentials</code> scope is required. * - To configure <code>client_authentication_methods</code>, the property <code>jwt_configuration.alg</code> must be set to RS256. * * <div class="alert alert-warning">SSO Integrations created via this endpoint will accept login requests and share user profile information.</div> * * @param {Management.CreateClientRequestContent} request * @param {ClientsClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Management.BadRequestError} * @throws {@link Management.UnauthorizedError} * @throws {@link Management.ForbiddenError} * @throws {@link Management.ConflictError} * @throws {@link Management.TooManyRequestsError} * * @example * await client.clients.create({ * name: "name" * }) */ create(request, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__create(request, requestOptions)); } __create(request, requestOptions) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const _authRequest = yield this._options.authProvider.getAuthRequest(); let _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.ManagementEnvironment.Default, "clients"), method: "POST", headers: _headers, contentType: "application/json", queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams, requestType: "json", body: request, timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000, maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Management.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Management.UnauthorizedError(_response.error.body, _response.rawResponse); case 403: throw new Management.ForbiddenError(_response.error.body, _response.rawResponse); case 409: throw new Management.ConflictError(_response.error.body, _response.rawResponse); case 429: throw new Management.TooManyRequestsError(_response.error.body, _response.rawResponse); default: throw new errors.ManagementError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "POST", "/clients"); }); } /** * Retrieve client details by ID. Clients are SSO connections or Applications linked with your Auth0 tenant. A list of fields to include or exclude may also be specified. * For more information, read <a href="https://www.auth0.com/docs/get-started/applications"> Applications in Auth0</a> and <a href="https://www.auth0.com/docs/authenticate/single-sign-on"> Single Sign-On</a>. * <ul> * <li> * The following properties can be retrieved with any of the scopes: * <code>client_id</code>, <code>app_type</code>, <code>name</code>, and <code>description</code>. * </li> * <li> * The following properties can only be retrieved with the <code>read:clients</code> or * <code>read:client_keys</code> scopes: * <code>callbacks</code>, <code>oidc_logout</code>, <code>allowed_origins</code>, * <code>web_origins</code>, <code>tenant</code>, <code>global</code>, <code>config_route</code>, * <code>callback_url_template</code>, <code>jwt_configuration</code>, * <code>jwt_configuration.lifetime_in_seconds</code>, <code>jwt_configuration.secret_encoded</code>, * <code>jwt_configuration.scopes</code>, <code>jwt_configuration.alg</code>, <code>api_type</code>, * <code>logo_uri</code>, <code>allowed_clients</code>, <code>owners</code>, <code>custom_login_page</code>, * <code>custom_login_page_off</code>, <code>sso</code>, <code>addons</code>, <code>form_template</code>, * <code>custom_login_page_codeview</code>, <code>resource_servers</code>, <code>client_metadata</code>, * <code>mobile</code>, <code>mobile.android</code>, <code>mobile.ios</code>, <code>allowed_logout_urls</code>, * <code>token_endpoint_auth_method</code>, <code>is_first_party</code>, <code>oidc_conformant</code>, * <code>is_token_endpoint_ip_header_trusted</code>, <code>initiate_login_uri</code>, <code>grant_types</code>, * <code>refresh_token</code>, <code>refresh_token.rotation_type</code>, <code>refresh_token.expiration_type</code>, * <code>refresh_token.leeway</code>, <code>refresh_token.token_lifetime</code>, <code>refresh_token.policies</code>, <code>organization_usage</code>, * <code>organization_require_behavior</code>. * </li> * <li> * The following properties can only be retrieved with the <code>read:client_keys</code> or <code>read:client_credentials</code> scopes: * <code>encryption_key</code>, <code>encryption_key.pub</code>, <code>encryption_key.cert</code>, * <code>client_secret</code>, <code>client_authentication_methods</code> and <code>signing_key</code>. * </li> * </ul> * * @param {string} id - ID of the client to retrieve. * @param {Management.GetClientRequestParameters} request * @param {ClientsClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Management.BadRequestError} * @throws {@link Management.UnauthorizedError} * @throws {@link Management.ForbiddenError} * @throws {@link Management.NotFoundError} * @throws {@link Management.TooManyRequestsError} * * @example * await client.clients.get("id", { * fields: "fields", * include_fields: true * }) */ get(id, request = {}, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__get(id, request, requestOptions)); } __get(id_1) { return __awaiter(this, arguments, void 0, function* (id, request = {}, requestOptions) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; const { fields, include_fields: includeFields } = request; const _queryParams = {}; if (fields !== undefined) { _queryParams["fields"] = fields; } if (includeFields !== undefined) { _queryParams["include_fields"] = (_a = includeFields === null || includeFields === void 0 ? void 0 : includeFields.toString()) !== null && _a !== void 0 ? _a : null; } const _authRequest = yield this._options.authProvider.getAuthRequest(); let _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_b = this._options) === null || _b === void 0 ? void 0 : _b.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_c = this._options.fetcher) !== null && _c !== void 0 ? _c : core.fetcher)({ url: core.url.join((_e = (_d = (yield core.Supplier.get(this._options.baseUrl))) !== null && _d !== void 0 ? _d : (yield core.Supplier.get(this._options.environment))) !== null && _e !== void 0 ? _e : environments.ManagementEnvironment.Default, `clients/${core.url.encodePathParam(id)}`), method: "GET", headers: _headers, queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams), timeoutMs: ((_h = (_f = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _f !== void 0 ? _f : (_g = this._options) === null || _g === void 0 ? void 0 : _g.timeoutInSeconds) !== null && _h !== void 0 ? _h : 60) * 1000, maxRetries: (_j = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _j !== void 0 ? _j : (_k = this._options) === null || _k === void 0 ? void 0 : _k.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_l = this._options) === null || _l === void 0 ? void 0 : _l.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Management.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Management.UnauthorizedError(_response.error.body, _response.rawResponse); case 403: throw new Management.ForbiddenError(_response.error.body, _response.rawResponse); case 404: throw new Management.NotFoundError(_response.error.body, _response.rawResponse); case 429: throw new Management.TooManyRequestsError(_response.error.body, _response.rawResponse); default: throw new errors.ManagementError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/clients/{id}"); }); } /** * Delete a client and related configuration (rules, connections, etc). * * @param {string} id - ID of the client to delete. * @param {ClientsClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Management.BadRequestError} * @throws {@link Management.UnauthorizedError} * @throws {@link Management.ForbiddenError} * @throws {@link Management.TooManyRequestsError} * * @example * await client.clients.delete("id") */ delete(id, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__delete(id, requestOptions)); } __delete(id, requestOptions) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const _authRequest = yield this._options.authProvider.getAuthRequest(); let _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.ManagementEnvironment.Default, `clients/${core.url.encodePathParam(id)}`), method: "DELETE", headers: _headers, queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams, timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000, maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: undefined, rawResponse: _response.rawResponse }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Management.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Management.UnauthorizedError(_response.error.body, _response.rawResponse); case 403: throw new Management.ForbiddenError(_response.error.body, _response.rawResponse); case 429: throw new Management.TooManyRequestsError(_response.error.body, _response.rawResponse); default: throw new errors.ManagementError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "DELETE", "/clients/{id}"); }); } /** * Updates a client's settings. For more information, read <a href="https://www.auth0.com/docs/get-started/applications"> Applications in Auth0</a> and <a href="https://www.auth0.com/docs/authenticate/single-sign-on"> Single Sign-On</a>. * * Notes: * - The `client_secret` and `signing_key` attributes can only be updated with the `update:client_keys` scope. * - The <code>client_authentication_methods</code> and <code>token_endpoint_auth_method</code> properties are mutually exclusive. Use <code>client_authentication_methods</code> to configure the client with Private Key JWT authentication method. Otherwise, use <code>token_endpoint_auth_method</code> to configure the client with client secret (basic or post) or with no authentication method (none). * - When using <code>client_authentication_methods</code> to configure the client with Private Key JWT authentication method, only specify the credential IDs that were generated when creating the credentials on the client. * - To configure <code>client_authentication_methods</code>, the <code>update:client_credentials</code> scope is required. * - To configure <code>client_authentication_methods</code>, the property <code>jwt_configuration.alg</code> must be set to RS256. * - To change a client's <code>is_first_party</code> property to <code>false</code>, the <code>organization_usage</code> and <code>organization_require_behavior</code> properties must be unset. * * @param {string} id - ID of the client to update. * @param {Management.UpdateClientRequestContent} request * @param {ClientsClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Management.BadRequestError} * @throws {@link Management.UnauthorizedError} * @throws {@link Management.ForbiddenError} * @throws {@link Management.NotFoundError} * @throws {@link Management.TooManyRequestsError} * * @example * await client.clients.update("id") */ update(id, request = {}, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__update(id, request, requestOptions)); } __update(id_1) { return __awaiter(this, arguments, void 0, function* (id, request = {}, requestOptions) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const _authRequest = yield this._options.authProvider.getAuthRequest(); let _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.ManagementEnvironment.Default, `clients/${core.url.encodePathParam(id)}`), method: "PATCH", headers: _headers, contentType: "application/json", queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams, requestType: "json", body: request, timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000, maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Management.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Management.UnauthorizedError(_response.error.body, _response.rawResponse); case 403: throw new Management.ForbiddenError(_response.error.body, _response.rawResponse); case 404: throw new Management.NotFoundError(_response.error.body, _response.rawResponse); case 429: throw new Management.TooManyRequestsError(_response.error.body, _response.rawResponse); default: throw new errors.ManagementError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "PATCH", "/clients/{id}"); }); } /** * Rotate a client secret. * * This endpoint cannot be used with clients configured with Private Key JWT authentication method (client_authentication_methods configured with private_key_jwt). The generated secret is NOT base64 encoded. * * For more information, read <a href="https://www.auth0.com/docs/get-started/applications/rotate-client-secret">Rotate Client Secrets</a>. * * @param {string} id - ID of the client that will rotate secrets. * @param {ClientsClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Management.BadRequestError} * @throws {@link Management.UnauthorizedError} * @throws {@link Management.ForbiddenError} * @throws {@link Management.NotFoundError} * @throws {@link Management.TooManyRequestsError} * * @example * await client.clients.rotateSecret("id") */ rotateSecret(id, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__rotateSecret(id, requestOptions)); } __rotateSecret(id, requestOptions) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const _authRequest = yield this._options.authProvider.getAuthRequest(); let _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.ManagementEnvironment.Default, `clients/${core.url.encodePathParam(id)}/rotate-secret`), method: "POST", headers: _headers, queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams, timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000, maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Management.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Management.UnauthorizedError(_response.error.body, _response.rawResponse); case 403: throw new Management.ForbiddenError(_response.error.body, _response.rawResponse); case 404: throw new Management.NotFoundError(_response.error.body, _response.rawResponse); case 429: throw new Management.TooManyRequestsError(_response.error.body, _response.rawResponse); default: throw new errors.ManagementError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "POST", "/clients/{id}/rotate-secret"); }); } } exports.ClientsClient = ClientsClient;