fiwarefiware-cosmos

Problems with cosmos auth and Identity manager integration


I want to integrate cosmos-auth with Idm GE. Config for node.js application is:

{
"host": "192.168.4.180",
"port": 13000,
"private_key_file": "key.pem",
"certificate_file": "cert.pem",
"idm": {
  "host": "192.168.4.33",
  "port": "443",
  "path": "/oauth2/token"
},
"cosmos_app": {
  "client_id": "0434fdf60897479588c3c31cfc957b6d",
  "client_secret": "a7c3540aa5de4de3a0b1c52a606b82df"
},
"log": {
  "file_name": "/var/log/cosmos/cosmos-auth/cosmos-auth.log",
  "date_pattern": ".dd-MM-yyyy"
 }
}

When i send HTTP POST request directly to IDM GE to url

https://192.168.4.33:443/oauth2/token

with required parameters i get ok results:

{
 access_token: "LyZT5DRGSn0F8IKqYU8EmRFTLo1iPJ"
 token_type: "Bearer"
 expires_in: 3600
 refresh_token: "XiyfKCHrIVyludabjaCyGqVsTkx8Sf"
}

But when i curl the cosmos-auth node.js application

curl -X POST "https://192.168.4.180:13000/cosmos-auth/v1/token" -H 
"Content-Type: application/x-www-form-urlencoded" -d   
"grant_type=password&username=idm&password=idm" -k

I get next result:

{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred"}

Has anyone encountered something similar? What could be the problem?


Solution

  • The error i made was using unsigned certificate.How clumsy of me. So either sign the certificate or insert additional element in options object (rejectUnauthorized: false)

    var options = {
        host : host,
        port : port,
        path : path,
        method : method,
        headers: headers,
        rejectUnauthorized: false
    };
    

    or in the beginning of the file insert:

    process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
    

    Ofcourse this is only temporary solution until we use fully signed cert. Anyways error handling and logs in cosmos-auth node.js app should show a little bit more.