AhmedAli7O1 / arch

:tada: a Tool to Manage & Automate your Node.js Server :tada:
https://www.npmjs.com/package/nodearch
MIT License
14 stars 0 forks source link

Trying to use bell #4

Closed alberttwong closed 5 years ago

alberttwong commented 5 years ago
Debug: internal, implementation, error
    Error: Failed to encode cookie (bell-linkedin) value: B64.base64urlEncode is not a function
    at Object.exports.prepareValue (/Users/alwong/sandbox/trust/node_modules/statehood/lib/index.js:428:20)
    at <anonymous>

for simplity, I just added what I needed into index.js and got the follow above error.

  await server.register(hapiPlugins);

  server.auth.strategy('linkedin', 'bell', {
    provider: 'linkedin',
    password: 'cookie_encryption_password_secure',
    isSecure: false,
    clientId: 'xxx',
    clientSecret: 'yyyy',
    providerParams: {
        redirect_uri: server.info.uri + '/bell/door'
    }
  });

  // serve static files from view folder
  /*
  server.route({
    method: 'GET',
    path: '/{param*}',
    handler: {
      directory: {
        path: path.join(__dirname, 'public'),
        redirectToSlash: true,
        index: true
      }
    }
  });
  */

  const routes = arch.getList('module', 'routes');
  routes.add
  server.route(routes);

  server.route({
    method: '*',
    path: '/bell/door',
    options: {
        auth: 'linkedin',
        handler: function (request, h) {

            return '<pre>' + JSON.stringify(request.auth.credentials, null, 4) + '</pre>';
        }
    }
  });
alberttwong commented 5 years ago
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bell": "^9.4.0",
    "hapi": "^17.4.0",
    "hapi-swagger": "^9.1.1",
    "inert": "^5.1.0",
    "lodash": "^4.17.10",
    "mocha": "^5.1.1",
    "mongoose": "^5.0.16",
    "nodearch": "^1.0.7",
    "vision": "^5.3.2"
  },
  "devDependencies": {
    "chai": "^4.1.2"
  }
alberttwong commented 5 years ago

When i don't use nodearch and just use straight hapijs, I dont' get this error.

AhmedAli7O1 commented 5 years ago

@alberttwong I just tried it and it seems to work just fine, so did you added bell into thirdParties.js? example:

'use strict';

const Inert = require('inert');
const Vision = require('vision');
const HapiSwagger = require('hapi-swagger');
const Pack = require('./package.json');
const Bell = require("bell");

module.exports = [
  Inert,
  Vision,
  Bell, // <<<<<<<<<<============  here
  {
    plugin: HapiSwagger,
    options: {
      info: {
        title: 'HapiArch Example Documentation',
        version: Pack.version,
        description: Pack.description,
        contact: {
          name: 'NodeArch Team',
          url: 'http://nodearch.io',
          email: 'support@nodearch.io'
        }
      },
      securityDefinitions: {
        apiKey: {
          type: 'apiKey',
          name: 'api_key',
          in: 'header',
          description: 'client api key'
        }
      },
      jsonEditor: false
    }
  }
];
AhmedAli7O1 commented 5 years ago

here is a working example that will also answers your question here #3

with node_modules hapi-arch-auth.zip

without node_modules hapi-arch-auth-no-modules.zip

alberttwong commented 5 years ago

I added to thirdparty already or else I’d get a bell not found error. I’ll check out your zip.

alberttwong commented 5 years ago

Hmm.. your code works and mine doesn't. I cut and pasted your edits into my project and I get the same error. I'll try to do a diff.

AhmedAli7O1 commented 5 years ago

have you tried my code with node_modules or you ran npm install on it? because I believe it's a problem with one of the bell dependencies.

alberttwong commented 5 years ago

Tried your code and worked great. Not sure what you meant by dependancy. My package.json matches yours.

Also which bell dependencies had the issue? How did you find out?

alberttwong commented 5 years ago

Mine

albertredhatcom-MacBook-Pro-2:trust alwong$ npm install
npm WARN hapi-arch@1.0.0 No repository field.

added 355 packages from 708 contributors and audited 832 packages in 7.648s
found 0 vulnerabilities

Yours

albertredhatcom-MacBook-Pro-2:hapi-arch-auth alwong$ npm install
npm WARN hapi-arch-auth@1.0.0 No repository field.

audited 820 packages in 2.361s
found 0 vulnerabilities
AhmedAli7O1 commented 5 years ago

if the package.json matches still the actual packages inside node_modules might still be different, anyway it worked with me for the first time, I guess you just have different package version in your node_modules that is not compatible with bell, because nodearch doesn't modify any node/hapi.js behaviors it's just a microservices tool kit.

one thing you could try is to copy/paste the node_modules folder attached in the previous comment, and put it directly in your project and see if it works.

alberttwong commented 5 years ago

copied working node_modules to my project. Had a mongoose error so I rpm install mongoose --save and ran node index.js.

2019-01-19T01:05:56.647Z [ARCH] info: Node.js Server/Architecture Manager v1.1.5
2019-01-19T01:05:56.651Z [ARCH] info: http://www.nodearch.io
2019-01-19T01:05:56.651Z [ARCH] info: Environment >> development
2019-01-19T01:05:56.651Z [ARCH] info: Started In /Users/alwong/sandbox/trust
2019-01-19T01:05:56.652Z [ARCH] info: Started At >> Fri Jan 18 2019 17:05:56 GMT-0800 (Pacific Standard Time)
(node:27282) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2019-01-19T01:05:56.937Z [ARCH] info: Connected To MongoDB
2019-01-19T01:05:57.051Z [ARCH] info: Server running on: http://0.0.0.0:3000
Debug: internal, implementation, error
    Error: Failed to encode cookie (bell-linkedin) value: B64.base64urlEncode is not a function
    at Object.exports.prepareValue (/Users/alwong/sandbox/trust/node_modules/statehood/lib/index.js:428:20)
alberttwong commented 5 years ago

just ran npm update instead of just npm install. The npm update fixed the issue.

AhmedAli7O1 commented 5 years ago

Great, thanks for your input, will close the issue, and feel free to open other issues if encountered any obstacles.