UNPKG

genesys-authentication-client-js

Version:
597 lines (518 loc) 28.3 kB
/** * Authentication API * Authentication API * * OpenAPI spec version: 9.0.000.68.2560 * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * * Swagger Codegen version: 2.4.5 * * Do not edit the class manually. * */ (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define(['ApiClient', 'model/ApiRequestOfChangePasswordOperation', 'model/ApiResponse', 'model/CloudUserDetails', 'model/DefaultOAuth2AccessToken', 'model/ErrorResponse', 'model/OpenIdUserInfo'], factory); } else if (typeof module === 'object' && module.exports) { // CommonJS-like environments that support module.exports, like Node. module.exports = factory(require('../ApiClient'), require('../model/ApiRequestOfChangePasswordOperation'), require('../model/ApiResponse'), require('../model/CloudUserDetails'), require('../model/DefaultOAuth2AccessToken'), require('../model/ErrorResponse'), require('../model/OpenIdUserInfo')); } else { // Browser globals (root is window) if (!root.AuthenticationApi) { root.AuthenticationApi = {}; } root.AuthenticationApi.AuthenticationApi = factory(root.AuthenticationApi.ApiClient, root.AuthenticationApi.ApiRequestOfChangePasswordOperation, root.AuthenticationApi.ApiResponse, root.AuthenticationApi.CloudUserDetails, root.AuthenticationApi.DefaultOAuth2AccessToken, root.AuthenticationApi.ErrorResponse, root.AuthenticationApi.OpenIdUserInfo); } }(this, function(ApiClient, ApiRequestOfChangePasswordOperation, ApiResponse, CloudUserDetails, DefaultOAuth2AccessToken, ErrorResponse, OpenIdUserInfo) { 'use strict'; /** * Authentication service. * @module api/AuthenticationApi * @version 9.0.000.68.2560 */ /** * Constructs a new AuthenticationApi. * @alias module:api/AuthenticationApi * @class * @param {module:ApiClient} [apiClient] Optional API client implementation to use, * default to {@link module:ApiClient#instance} if unspecified. */ var exports = function(apiClient) { this.apiClient = apiClient || ApiClient.instance; /** * Perform authorization * Perform authorization based on the code grant type — either Authorization Code Grant or Implicit Grant. For more information, see [Authorization Endpoint](https://tools.ietf.org/html/rfc6749#section-3.1). **Note:** For the optional **scope** parameter, the Authentication API supports only the `*` value. * @param {String} clientId The ID of the application or service that is registered as the client. You'll need to get this value from your PureEngage Cloud representative. * @param {String} redirectUri The URI that you want users to be redirected to after entering valid credentials during an Implicit or Authorization Code grant. The Authentication API includes this as part of the URI it returns in the 'Location' header. * @param {module:model/String} responseType The response type to let the Authentication API know which grant flow you're using. Possible values are `code` for Authorization Code Grant or `token` for Implicit Grant. For more information about this parameter, see [Response Type](https://tools.ietf.org/html/rfc6749#section-3.1.1). * @param {Object} opts Optional parameters * @param {String} opts.authorization Basic authorization. For example: 'Authorization: Basic Y3...MQ==' * @param {Boolean} opts.hideTenant Hide the **tenant** field in the UI for Authorization Code Grant. (default to false) * @param {module:model/String} opts.scope The scope of the access request. The Authentication API supports only the `*` value. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing HTTP response */ this.authorizeWithHttpInfo = function(clientId, redirectUri, responseType, opts) { opts = opts || {}; var postBody = null; // verify the required parameter 'clientId' is set if (clientId === undefined || clientId === null) { throw new Error("Missing the required parameter 'clientId' when calling authorize"); } // verify the required parameter 'redirectUri' is set if (redirectUri === undefined || redirectUri === null) { throw new Error("Missing the required parameter 'redirectUri' when calling authorize"); } // verify the required parameter 'responseType' is set if (responseType === undefined || responseType === null) { throw new Error("Missing the required parameter 'responseType' when calling authorize"); } var pathParams = { }; var queryParams = { 'client_id': clientId, 'hideTenant': opts['hideTenant'], 'redirect_uri': redirectUri, 'response_type': responseType, 'scope': opts['scope'], }; var collectionQueryParams = { }; var headerParams = { 'Authorization': opts['authorization'] }; var formParams = { }; var authNames = []; var contentTypes = []; var accepts = ['application/json']; var returnType = null; return this.apiClient.callApi( '/oauth/authorize', 'GET', pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * Perform authorization * Perform authorization based on the code grant type — either Authorization Code Grant or Implicit Grant. For more information, see [Authorization Endpoint](https://tools.ietf.org/html/rfc6749#section-3.1). **Note:** For the optional **scope** parameter, the Authentication API supports only the `*` value. * @param {String} clientId The ID of the application or service that is registered as the client. You'll need to get this value from your PureEngage Cloud representative. * @param {String} redirectUri The URI that you want users to be redirected to after entering valid credentials during an Implicit or Authorization Code grant. The Authentication API includes this as part of the URI it returns in the 'Location' header. * @param {module:model/String} responseType The response type to let the Authentication API know which grant flow you're using. Possible values are `code` for Authorization Code Grant or `token` for Implicit Grant. For more information about this parameter, see [Response Type](https://tools.ietf.org/html/rfc6749#section-3.1.1). * @param {Object} opts Optional parameters * @param {String} opts.authorization Basic authorization. For example: 'Authorization: Basic Y3...MQ==' * @param {Boolean} opts.hideTenant Hide the **tenant** field in the UI for Authorization Code Grant. (default to false) * @param {module:model/String} opts.scope The scope of the access request. The Authentication API supports only the `*` value. * @return {Promise} a {@link https://www.promisejs.org/|Promise} */ this.authorize = function(clientId, redirectUri, responseType, opts) { return this.authorizeWithHttpInfo(clientId, redirectUri, responseType, opts) .then(function(response_and_data) { return response_and_data.data; }); } /** * Change password * Change the user's password. * @param {module:model/ApiRequestOfChangePasswordOperation} request request * @param {Object} opts Optional parameters * @param {String} opts.authorization The OAuth 2 bearer access token you received from [/auth/v3/oauth/token](/reference/authentication/Authentication/index.html#retrieveToken). For example: \"Authorization: bearer a4b5da75-a584-4053-9227-0f0ab23ff06e\" (default to bearer) * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/ApiResponse} and HTTP response */ this.changePasswordWithHttpInfo = function(request, opts) { opts = opts || {}; var postBody = request; // verify the required parameter 'request' is set if (request === undefined || request === null) { throw new Error("Missing the required parameter 'request' when calling changePassword"); } var pathParams = { }; var queryParams = { }; var collectionQueryParams = { }; var headerParams = { 'Authorization': opts['authorization'] }; var formParams = { }; var authNames = []; var contentTypes = ['application/json']; var accepts = ['application/json']; var returnType = ApiResponse; return this.apiClient.callApi( '/change-password', 'POST', pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * Change password * Change the user's password. * @param {module:model/ApiRequestOfChangePasswordOperation} request request * @param {Object} opts Optional parameters * @param {String} opts.authorization The OAuth 2 bearer access token you received from [/auth/v3/oauth/token](/reference/authentication/Authentication/index.html#retrieveToken). For example: \"Authorization: bearer a4b5da75-a584-4053-9227-0f0ab23ff06e\" (default to bearer) * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/ApiResponse} */ this.changePassword = function(request, opts) { return this.changePasswordWithHttpInfo(request, opts) .then(function(response_and_data) { return response_and_data.data; }); } /** * Get OpenID user information by access token * Get information about a user by their OAuth 2 access token. * @param {String} authorization The OAuth 2 bearer access token you received from [/auth/v3/oauth/token](/reference/authentication/Authentication/index.html#retrieveToken). For example: \"Authorization: bearer a4b5da75-a584-4053-9227-0f0ab23ff06e\" * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/OpenIdUserInfo} and HTTP response */ this.getInfoWithHttpInfo = function(authorization) { var postBody = null; // verify the required parameter 'authorization' is set if (authorization === undefined || authorization === null) { throw new Error("Missing the required parameter 'authorization' when calling getInfo"); } var pathParams = { }; var queryParams = { }; var collectionQueryParams = { }; var headerParams = { 'Authorization': authorization }; var formParams = { }; var authNames = []; var contentTypes = []; var accepts = ['application/json']; var returnType = OpenIdUserInfo; return this.apiClient.callApi( '/openid/userinfo', 'GET', pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * Get OpenID user information by access token * Get information about a user by their OAuth 2 access token. * @param {String} authorization The OAuth 2 bearer access token you received from [/auth/v3/oauth/token](/reference/authentication/Authentication/index.html#retrieveToken). For example: \"Authorization: bearer a4b5da75-a584-4053-9227-0f0ab23ff06e\" * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/OpenIdUserInfo} */ this.getInfo = function(authorization) { return this.getInfoWithHttpInfo(authorization) .then(function(response_and_data) { return response_and_data.data; }); } /** * Get user information by access token * Get information about a user by their OAuth 2 access token. * @param {String} authorization The OAuth 2 bearer access token. For example: \"Authorization: bearer a4b5da75-a584-4053-9227-0f0ab23ff06e\" * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/CloudUserDetails} and HTTP response */ this.getInfo1WithHttpInfo = function(authorization) { var postBody = null; // verify the required parameter 'authorization' is set if (authorization === undefined || authorization === null) { throw new Error("Missing the required parameter 'authorization' when calling getInfo1"); } var pathParams = { }; var queryParams = { }; var collectionQueryParams = { }; var headerParams = { 'Authorization': authorization }; var formParams = { }; var authNames = []; var contentTypes = []; var accepts = ['application/json']; var returnType = CloudUserDetails; return this.apiClient.callApi( '/userinfo', 'GET', pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * Get user information by access token * Get information about a user by their OAuth 2 access token. * @param {String} authorization The OAuth 2 bearer access token. For example: \"Authorization: bearer a4b5da75-a584-4053-9227-0f0ab23ff06e\" * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/CloudUserDetails} */ this.getInfo1 = function(authorization) { return this.getInfo1WithHttpInfo(authorization) .then(function(response_and_data) { return response_and_data.data; }); } /** * Get user information by access token. The information will be encoded as jwt and returned in 'X-GWS-User' header * Get information about a user by their OAuth 2 access token. * @param {String} authorization The OAuth 2 bearer access token. For example: 'Authorization: bearer a4b5da75-a584-4053-9227-0f0ab23ff06e' * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/ApiResponse} and HTTP response */ this.getJwtInfoUsingGETWithHttpInfo = function(authorization) { var postBody = null; // verify the required parameter 'authorization' is set if (authorization === undefined || authorization === null) { throw new Error("Missing the required parameter 'authorization' when calling getJwtInfoUsingGET"); } var pathParams = { }; var queryParams = { }; var collectionQueryParams = { }; var headerParams = { 'Authorization': authorization }; var formParams = { }; var authNames = []; var contentTypes = []; var accepts = ['application/json']; var returnType = ApiResponse; return this.apiClient.callApi( '/jwt-userinfo', 'GET', pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * Get user information by access token. The information will be encoded as jwt and returned in 'X-GWS-User' header * Get information about a user by their OAuth 2 access token. * @param {String} authorization The OAuth 2 bearer access token. For example: 'Authorization: bearer a4b5da75-a584-4053-9227-0f0ab23ff06e' * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/ApiResponse} */ this.getJwtInfoUsingGET = function(authorization) { return this.getJwtInfoUsingGETWithHttpInfo(authorization) .then(function(response_and_data) { return response_and_data.data; }); } /** * Check connection * Return 200 if user is authenticated otherwise 403 * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/ApiResponse} and HTTP response */ this.pingWithHttpInfo = function() { var postBody = null; var pathParams = { }; var queryParams = { }; var collectionQueryParams = { }; var headerParams = { }; var formParams = { }; var authNames = []; var contentTypes = []; var accepts = ['application/json']; var returnType = ApiResponse; return this.apiClient.callApi( '/ping', 'GET', pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * Check connection * Return 200 if user is authenticated otherwise 403 * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/ApiResponse} */ this.ping = function() { return this.pingWithHttpInfo() .then(function(response_and_data) { return response_and_data.data; }); } /** * Retrieve access token * Retrieve an access token based on the grant type — Authorization Code Grant, Resource Owner Password Credentials Grant or Client Credentials Grant. For more information, see [Token Endpoint](https://tools.ietf.org/html/rfc6749). **Note:** For the optional **scope** parameter, the Authentication API supports only the `*` value. * @param {module:model/String} grantType The grant type you use to implement authentication. * @param {Object} opts Optional parameters * @param {String} opts.accept The media type the Authentication API should should use for the response. For example: 'Accept: application/x-www-form-urlencoded' * @param {String} opts.authorization Basic authorization. For example: 'Authorization: Basic Y3...MQ==' * @param {String} opts.clientId The ID of the application or service that is registered as the client. You'll need to get this value from your PureEngage Cloud representative. * @param {String} opts.code Authorization code, see (https://tools.ietf.org/html/rfc6749#section-4.1.3) for details. * @param {String} opts.password The agent's password. * @param {String} opts.refreshToken See [Refresh Token](https://tools.ietf.org/html/rfc6749#section-1.5) for details. * @param {module:model/String} opts.scope The scope of the access request. The Authentication API supports only the `*` value. * @param {String} opts.username The agent's username. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/DefaultOAuth2AccessToken} and HTTP response */ this.retrieveTokenWithHttpInfo = function(grantType, opts) { opts = opts || {}; var postBody = null; // verify the required parameter 'grantType' is set if (grantType === undefined || grantType === null) { throw new Error("Missing the required parameter 'grantType' when calling retrieveToken"); } var pathParams = { }; var queryParams = { }; var collectionQueryParams = { }; var headerParams = { 'Accept': opts['accept'], 'Authorization': opts['authorization'] }; var formParams = { 'client_id': opts['clientId'], 'code': opts['code'], 'grant_type': grantType, 'password': opts['password'], 'refresh_token': opts['refreshToken'], 'scope': opts['scope'], 'username': opts['username'] }; var authNames = []; var contentTypes = ['application/x-www-form-urlencoded']; var accepts = ['application/json']; var returnType = DefaultOAuth2AccessToken; return this.apiClient.callApi( '/oauth/token', 'POST', pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * Retrieve access token * Retrieve an access token based on the grant type — Authorization Code Grant, Resource Owner Password Credentials Grant or Client Credentials Grant. For more information, see [Token Endpoint](https://tools.ietf.org/html/rfc6749). **Note:** For the optional **scope** parameter, the Authentication API supports only the `*` value. * @param {module:model/String} grantType The grant type you use to implement authentication. * @param {Object} opts Optional parameters * @param {String} opts.accept The media type the Authentication API should should use for the response. For example: 'Accept: application/x-www-form-urlencoded' * @param {String} opts.authorization Basic authorization. For example: 'Authorization: Basic Y3...MQ==' * @param {String} opts.clientId The ID of the application or service that is registered as the client. You'll need to get this value from your PureEngage Cloud representative. * @param {String} opts.code Authorization code, see (https://tools.ietf.org/html/rfc6749#section-4.1.3) for details. * @param {String} opts.password The agent's password. * @param {String} opts.refreshToken See [Refresh Token](https://tools.ietf.org/html/rfc6749#section-1.5) for details. * @param {module:model/String} opts.scope The scope of the access request. The Authentication API supports only the `*` value. * @param {String} opts.username The agent's username. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/DefaultOAuth2AccessToken} */ this.retrieveToken = function(grantType, opts) { return this.retrieveTokenWithHttpInfo(grantType, opts) .then(function(response_and_data) { return response_and_data.data; }); } /** * Sign-out a logged in user * Sign-out the current user and invalidate either the current token or all tokens associated with the user. * @param {String} authorization The OAuth 2 bearer access token you received from [/auth/v3/oauth/token](/reference/authentication/Authentication/index.html#retrieveToken). For example: \"Authorization: bearer a4b5da75-a584-4053-9227-0f0ab23ff06e\" * @param {Object} opts Optional parameters * @param {Boolean} opts.global Specifies whether to invalidate all tokens for the current user (`true`) or only the current token (`false`). * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/ApiResponse} and HTTP response */ this.signOutWithHttpInfo = function(authorization, opts) { opts = opts || {}; var postBody = null; // verify the required parameter 'authorization' is set if (authorization === undefined || authorization === null) { throw new Error("Missing the required parameter 'authorization' when calling signOut"); } var pathParams = { }; var queryParams = { 'global': opts['global'], }; var collectionQueryParams = { }; var headerParams = { 'Authorization': authorization }; var formParams = { }; var authNames = []; var contentTypes = ['application/json']; var accepts = ['application/json']; var returnType = ApiResponse; return this.apiClient.callApi( '/sign-out', 'POST', pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * Sign-out a logged in user * Sign-out the current user and invalidate either the current token or all tokens associated with the user. * @param {String} authorization The OAuth 2 bearer access token you received from [/auth/v3/oauth/token](/reference/authentication/Authentication/index.html#retrieveToken). For example: \"Authorization: bearer a4b5da75-a584-4053-9227-0f0ab23ff06e\" * @param {Object} opts Optional parameters * @param {Boolean} opts.global Specifies whether to invalidate all tokens for the current user (`true`) or only the current token (`false`). * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/ApiResponse} */ this.signOut = function(authorization, opts) { return this.signOutWithHttpInfo(authorization, opts) .then(function(response_and_data) { return response_and_data.data; }); } /** * Sign-out a logged in user * Sign-out the current user and invalidate either the current token or all tokens associated with the user. * @param {String} authorization The OAuth 2 bearer access token you received from [/auth/v3/oauth/token](/reference/authentication/Authentication/index.html#retrieveToken). For example: \"Authorization: bearer a4b5da75-a584-4053-9227-0f0ab23ff06e\" * @param {Object} opts Optional parameters * @param {Boolean} opts.global Specifies whether to invalidate all tokens for the current user (`true`) or only the current token (`false`). * @param {String} opts.redirectUri Specifies the URI where the browser is redirected after sign-out is successful. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/ApiResponse} and HTTP response */ this.signOut1WithHttpInfo = function(authorization, opts) { opts = opts || {}; var postBody = null; // verify the required parameter 'authorization' is set if (authorization === undefined || authorization === null) { throw new Error("Missing the required parameter 'authorization' when calling signOut1"); } var pathParams = { }; var queryParams = { 'global': opts['global'], 'redirectUri': opts['redirectUri'], }; var collectionQueryParams = { }; var headerParams = { 'Authorization': authorization }; var formParams = { }; var authNames = []; var contentTypes = []; var accepts = ['application/json']; var returnType = ApiResponse; return this.apiClient.callApi( '/sign-out', 'GET', pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * Sign-out a logged in user * Sign-out the current user and invalidate either the current token or all tokens associated with the user. * @param {String} authorization The OAuth 2 bearer access token you received from [/auth/v3/oauth/token](/reference/authentication/Authentication/index.html#retrieveToken). For example: \"Authorization: bearer a4b5da75-a584-4053-9227-0f0ab23ff06e\" * @param {Object} opts Optional parameters * @param {Boolean} opts.global Specifies whether to invalidate all tokens for the current user (`true`) or only the current token (`false`). * @param {String} opts.redirectUri Specifies the URI where the browser is redirected after sign-out is successful. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/ApiResponse} */ this.signOut1 = function(authorization, opts) { return this.signOut1WithHttpInfo(authorization, opts) .then(function(response_and_data) { return response_and_data.data; }); } }; return exports; }));