CognosExt / jcognos

Library to make working with the Cognos API easier
GNU General Public License v3.0
12 stars 1 forks source link

Problems to authenticate - maybe missing the Namespace #6

Closed xumes closed 6 years ago

xumes commented 6 years ago

Hello, I am trying again to use this lib, have made some progress, but I still have issues.

Do yo mind in check what I am doing wrong? I just realized that I am not passing the Namespace, as I do in another library.

Here is my code:

const jCognos = require('jcognos')
require('dotenv').config()

const config = {
    serviceUrl: 'http://zcogwass1.boulder.ibm.com:9305/bi/v1/disp/',
    serviceUsername: process.env.USERNAME,
    servicePassword: process.env.PASSWORD
}

jCognos.getCognos(config.serviceUrl)
    .then(lCognos => {
        //console.log('ready for login', lCognos)
        lCognos
            .login(config.serviceUsername, config.servicePassword)
            .then(result=>{
                console.log('login result: ', result)
            })
            .catch(err => {console.log('bad login', err)})
    })
    .catch(e => {console.log('error: ', e)})

This is the long result from the .login() method (I just removed my password):

{ status: 200,
  statusText: 'OK',
  headers: 
   { 'x-powered-by': 'Servlet/3.1',
     'x-ca-affinity': '1023335179',
     'cache-control': 'no-cache',
     expires: 'Thu, 01 Jan 1970 00:00:00 GMT',
     'content-id': '-18f816e9:164b28cfdb4:-6b29',
     'content-type': 'text/html; charset=UTF-8',
     'content-language': 'en-US',
     'content-length': '7848',
     connection: 'Close',
     date: 'Tue, 31 Jul 2018 14:20:57 GMT' },
  config: 
   { adapter: [Function: httpAdapter],
     transformRequest: { '0': [Function: transformRequest] },
     transformResponse: { '0': [Function: transformResponse] },
     timeout: 0,
     xsrfCookieName: 'XSRF-TOKEN',
     xsrfHeaderName: 'X-XSRF-TOKEN',
     maxContentLength: -1,
     headers: 
      { Accept: 'application/json, text/plain, */*',
        'Content-Type': 'application/json; charset=UTF-8',
        'X-Requested-With': 'XMLHttpRequest',
        Cookie: 'XSRF-TOKEN=XjNuxco6oLwgLBQnrWQYYoLjCkTQufx3',
        'User-Agent': 'axios/0.18.0',
        'Content-Length': 179 },
     method: 'post',
     jar: 
      CookieJar {
        store: { idx: { 'ibm.com': 
   { '/bi': 
      { 'XSRF-TOKEN': Cookie="XSRF-TOKEN=XjNuxco6oLwgLBQnrWQYYoLjCkTQufx3; Domain=ibm.com; Path=/bi; hostOnly=false; aAge=716ms; cAge=720ms" } } } } },
     withCredentials: true,
     url: 'http://zcogwass1.boulder.ibm.com:9305/bi/v1/disp/bi/v1/login',
     data: '{"parameters":[{"name":"CAMNamespace"},{"name":"h_CAM_action","value":"logonAs"},{"name":"CAMUsername","value":"rmsantos@<<rest of my e-mail>>"},{"name":"CAMPassword","value":"<<my password>>"}]}',
     maxRedirects: 0,
     validateStatus: [Function: validateStatus] },
  request: 
   ClientRequest {
     domain: null,
     _events: 
      { error: [Function: handleRequestError],
        prefinish: [Function: requestOnPrefinish] },
     _eventsCount: 2,
     _maxListeners: undefined,
     output: [],
     outputEncodings: [],
     outputCallbacks: [],
     outputSize: 0,
     writable: true,
     _last: true,
     upgrading: false,
     chunkedEncoding: false,
     shouldKeepAlive: false,
     useChunkedEncodingByDefault: true,
     sendDate: false,
     _removedConnection: false,
     _removedContLen: false,
     _removedTE: false,
     _contentLength: 179,
     _hasBody: true,
     _trailer: '',
     finished: true,
     _headerSent: true,
     socket: 
      Socket {
        connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: 'zcogwass1.boulder.ibm.com',
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 8,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        _bytesDispatched: 501,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: null,
        _server: null,
        parser: null,
        _httpMessage: [Circular],
        read: [Function],
        _consuming: true,
        _idleNext: null,
        _idlePrev: null,
        _idleTimeout: -1,
        [Symbol(asyncId)]: 23,
        [Symbol(bytesRead)]: 8170 },
     connection: 
      Socket {
        connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: 'zcogwass1.boulder.ibm.com',
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 8,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        _bytesDispatched: 501,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: null,
        _server: null,
        parser: null,
        _httpMessage: [Circular],
        read: [Function],
        _consuming: true,
        _idleNext: null,
        _idlePrev: null,
        _idleTimeout: -1,
        [Symbol(asyncId)]: 23,
        [Symbol(bytesRead)]: 8170 },
     _header: 'POST /bi/v1/disp/bi/v1/login HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/json; charset=UTF-8\r\nX-Requested-With: XMLHttpRequest\r\nCookie: XSRF-TOKEN=XjNuxco6oLwgLBQnrWQYYoLjCkTQufx3\r\nUser-Agent: axios/0.18.0\r\nContent-Length: 179\r\nHost: zcogwass1.boulder.ibm.com:9305\r\nConnection: close\r\n\r\n',
     _onPendingData: [Function: noopPendingOutput],
     agent: 
      Agent {
        domain: null,
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        defaultPort: 80,
        protocol: 'http:',
        options: [Object],
        requests: {},
        sockets: [Object],
        freeSockets: {},
        keepAliveMsecs: 1000,
        keepAlive: false,
        maxSockets: Infinity,
        maxFreeSockets: 256 },
     socketPath: undefined,
     timeout: undefined,
     method: 'POST',
     path: '/bi/v1/disp/bi/v1/login',
     _ended: true,
     res: 
      IncomingMessage {
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        socket: [Object],
        connection: [Object],
        httpVersionMajor: 1,
        httpVersionMinor: 1,
        httpVersion: '1.1',
        complete: true,
        headers: [Object],
        rawHeaders: [Array],
        trailers: {},
        rawTrailers: [],
        upgrade: false,
        url: '',
        method: null,
        statusCode: 200,
        statusMessage: 'OK',
        client: [Object],
        _consuming: true,
        _dumped: false,
        req: [Circular],
        read: [Function] },
     aborted: undefined,
     timeoutCb: null,
     upgradeOrConnect: false,
     parser: null,
     maxHeadersCount: null,
     [Symbol(outHeadersKey)]: 
      { accept: [Array],
        'content-type': [Array],
        'x-requested-with': [Array],
        cookie: [Array],
        'user-agent': [Array],
        'content-length': [Array],
        host: [Array] } },
  data: '<!DOCTYPE html><html lang=""><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="expires" content="0"><link rel="stylesheet" type="text/css" href="/skins/corporate/portal/default.css"><link rel="stylesheet" type="text/css" href="/skins/corporate/fonts.css"><script xmlns:xts="http://developer.cognos.com/schemas/xts/" xmlns:xos="http://developer.cognos.com/schemas/xts/output/" language="javascript" src="/ps/portal/js/cookie_jar.js"></script><script xmlns:xts="http://developer.cognos.com/schemas/xts/" xmlns:xos="http://developer.cognos.com/schemas/xts/output/" language="javascript">\n\t\t\t\t\tvar g_PS_sParamDelimiter = "|";\n\t\t\t\t\tvar g_PS_sNameValueDelimiter = ":";\n\t\t\t\t\t\n\t\t\t\t\tvar g_PS_sCookiePath = "";\n\t\t\t\t\tvar g_PS_sCookieDomain = ".ibm.com";\n\t\t\t\t\n\t\t\t\t\tvar g_PS_browser = \'other\';\n\t\t\t\t\tvar g_PS_emptyHistoryThreshold = \'1\';\n\t\t\t\t\t\n\t\t\t\t\tvar g_PS_isModal = \'false\';\n\t\t\t\t\tvar g_PS_callBackMode = \'parent\';\n\t\t\t\t\tvar g_PS_callBackFunctionName = \'ccModalCallBack\';\n\t\t\t\t\tvar g_PS_callBackTargetJSVar = null;\n\t\t\t\t\ttry {\n\t\t\t\t\t    g_PS_callBackTargetJSVar = window.opener && typeof window.opener.ccModalCallBack != "undefined" ? window.opener : parent;\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t    \n\t\t\t\t\t    \n\t\t\t\t\t    g_PS_isModal = \'false\';\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tvar g_PS_msg_PasswordVerifyFailed = "The passwords you typed do not match. Please retype the new password in both text boxes.";\n\t\t\t\t\t\n\t\t\t\t\tvar g_PS_cmdOK_enabled = true;\n\t\t\t\t\t\n\t\t\t\t\tvar g_PS_errURL = \'\';\n\t\t\t\t\tvar g_PS_errURLTooLong = \'false\';\n\t\t\t\t\t\n\t\t\t\t\tvar g_PS_webContent = \'/ps\';\n\t\t\t\t\tvar g_PS_locale = "";\n\t\t\t\t\t\n\t\t\t\t\tvar g_PS_isPasswordResetConfirmation = false;\n\t\t\t\t\tvar g_PS_enablePasswordResetAction = false;\n\n\t\t\t\t    \n\t\t\t\t\t\n\t\t\t\t\tvar g_PS_isCloseMorphlet = false;\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t</script><script xmlns:xts="http://developer.cognos.com/schemas/xts/" xmlns:xos="http://developer.cognos.com/schemas/xts/output/" language="javascript">\n\t\t\t\t\t\t\tvar g_PS_isQS = \'false\';\n\t\t\t\t\t\t</script><script xmlns:xts="http://developer.cognos.com/schemas/xts/" xmlns:xos="http://developer.cognos.com/schemas/xts/output/" language="javascript" src="/ps/portal/js/faulterror.js"></script><script xmlns:xts="http://developer.cognos.com/schemas/xts/" xmlns:xos="http://developer.cognos.com/schemas/xts/output/" xmlns:mt="http://developer.cognos.com/schemas/xts/logicsheets/presentation/main/mt" language="javascript" src="/ccl/helpDocs.js"></script><script xmlns:xts="http://developer.cognos.com/schemas/xts/" xmlns:xos="http://developer.cognos.com/schemas/xts/output/" xmlns:mt="http://developer.cognos.com/schemas/xts/logicsheets/presentation/main/mt" language="javascript">\n\t\t\tfunction help(sContext)\n\t\t\t{\n\t\t\t\tif (!sContext) {\n\t\t\t\t\tsContext = "";\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tgotoHelp("", "ug_cc", sContext,"");\n\t\t\t}\n\t\t</script><script language="JavaScript">\n\t\t\t\t\tif (document.addEventListener) {\n\t\t\t\t\t\twindow.addEventListener("beforeunload", function(){}, false);\n\t\t\t\t\t} else if (document.attachEvent) {\n\t\t\t\t\t\twindow.attachEvent("onbeforeunload", function(){});\n\t\t\t\t\t}\n\t\t\t\t</script><title>IBM Cognos Software</title></head><body onload="if (window.init) init();" style="margin:3px;" role="region" aria-labelledby="IDS_ERROR_DIALOG_TITLE"><span id="IDS_ERROR_DIALOG_TITLE" style="position: absolute;margin-left: -9999px; margin-top: -9999px; ">IBM Cognos Software Error dialog</span><form style="margin:0px;padding:0px;" method="post" action="/bi/v1/disp/bi/v1/login" name="pform"><a href="#maincontent" tabindex="0" class="showOnFocus">Skip to main content</a><table border="0" width="100%" cellspacing="0" cellpadding="0" class="dialogHeader" style="height:28px;" role="presentation"><tr><td class="dialogHeaderTitle" nowrap>IBM Cognos Software</td><td width="100%"></td><td class="dialogHeaderLink" nowrap><a href="javascript:processCommand(\'help\')" class="dialogHeaderLinkColor">Help</a></td><td class="dialogHeaderLink"><a href="javascript:processCommand(\'close\')" class="dialogHeaderLinkColor"><img height="16" width="16" vspace="2" border="0" class="dialogHeaderCloseButton" onmouseover="this.className = \'dialogHeaderCloseButtonOver\'" onmouseout="this.className = \'dialogHeaderCloseButton\'" src="/skins/corporate/portal/images/close.gif" role="button" alt="Close" title="Close"></a></td></tr></table><!--<ERROR_COMPONENT>ps</ERROR_COMPONENT><ERROR_CODE>DPR-ERR-2008</ERROR_CODE><ERROR_MSG>The dispatcher is unable to process the request. The request is directed to an unknown service name: bi.</ERROR_MSG>--><table width="100%" border="0" cellspacing="0" cellpadding="0" role="presentation"><tr><td><img src="/ps/images/space.gif" alt="" width="1" height="10"></td></tr></table><table width="100%" border="0" cellspacing="0" cellpadding="0" style="padding-left:5px;" role="presentation"><tr><td class="dialogHeaderText">DPR-ERR-2008</td></tr></table><table width="100%" border="0" cellspacing="0" cellpadding="0" role="presentation"><tr><td><img src="/ps/images/space.gif" alt="" width="1" height="10"></td></tr></table><table width="100%" border="0" cellspacing="0" cellpadding="0" role="presentation"><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="3" role="presentation"><tr><td width="1" height="1"><img src="/ps/images/space.gif" width="1" height="1" alt=""></td><td width="100%"><table border="0" cellspacing="0" cellpadding="0" role="presentation"><tr><td><img src="/ps/portal/images/msg_error.gif" alt="" width="32" height="32" border="0"></td><td class="formText">&nbsp;&nbsp;&nbsp;</td><td class="formText" valign="top">The dispatcher is unable to process the request. The request is directed to an unknown service name: bi.</td></tr></table></td></tr></table><script type="text/javascript" language="JavaScript">\n\t\t\t\t\t\t\tvar imgExpand   = new Image();\n\t\t\t\t\t\t\tvar imgCollapse = new Image();\n\t\t\t\t\t\t\timgExpand.alt = "Expand";\n\t\t\t\t\t\t\timgExpand.title = "Expand";\n\t\t\t\t\t\t\timgExpand.src = "/skins/corporate/portal/images/prompt_option_expand.gif";\n\t\t\t\t\t\t\timgCollapse.src   = "/skins/corporate/portal/images/prompt_option_collapse.gif";\n\t\t\t\t\t\t\timgCollapse.alt = "Collapse";\n\t\t\t\t\t\t\timgCollapse.title = "Collapse";\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfunction toggleDynamicSection(name) {\n\t\t\t\t\t\t\t\tvar img = document.getElementById("img_" + name);\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tif(document.getElementById(name).style.display == \'none\') {\n\t\t\t\t\t\t\t\t\tdocument.getElementById(name).style.display\t= "";\n\t\t\t\t\t\t\t\t\timg.src = imgCollapse.src;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tdocument.getElementById(name).style.display\t= "none";\n\t\t\t\t\t\t\t\t\timg.src = imgExpand.src;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t</script><table border="0" cellpadding="0" cellspacing="0" style="margin:10px" role="presentation"><tr><td><img src="/ps/images/space.gif" alt="" width="30" height="30" border="0"></td><td class="formText">&nbsp;&nbsp;&nbsp;</td><td><table role="presentation"><tr><td class="formText" valign="bottom" nowrap><a href="javascript:toggleDynamicSection(\'errorPanel\')" role="main" id="maincontent">Details</a><a href="javascript:toggleDynamicSection(\'errorPanel\');"><img name="img_errorPanel" id="img_errorPanel" border="0" src="/skins/corporate/portal/images/prompt_option_expand.gif" alt="Expand" title="Expand"></a></td></tr><tr><td><div id="errorPanel" class="errorPanel" style="display:none">CAF-WRN-2082 An error has occurred. Please contact your administrator. The complete error has been logged by CAF with SecureErrorID:2018-07-31-14:20:57.218-#1664</div></td></tr></table></td></tr></table></td></tr></table><table role="presentation" class="dialogButtonBar" width="100%" cellpadding="0" cellspacing="0" style="margin-top:20px;height:50px;"><tr><td><input id="cmdOK" style="width:70px;" type="submit" class="cmdButton" onmouseover="this.className=\'cmdButtonOver\'" onmouseout="this.className=\'cmdButton\'" value="OK" onclick="javascript:processCommand(\'ok\'); return false;"></td><td width="100%"></td></tr></table></form></body></html>' }
batje commented 6 years ago

First your server url should be shorter: http://zcogwass1.boulder.ibm.com:9305/ suffices.

And our install does not have more than 1 namespace currently. That will change soon, and I will have your problem. I will probably fix that.