Problem with SSL invoking user service with Angular 4
I am using Box API for Nodejs using Angular 4, my app is deployed with Angular CLI embedded HTTP server.
OS:
Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.43-2+deb8u1 (2017-06-18) x86_64 GNU/Linux
Having installed npm and Angular CLI, the server starts with the command:
ng serve
So far so good, login is ok, now I'm trying to obtaing user info:
Relevant code:
let client = boxSDK.getBasicClient(userToken); client.users.get(client.CURRENT_USER_ID).map(user => { console.log('user ' + user.name); });
just as in the guide, but the query launches an error in chrome console:
Unhandled rejection Error: SSL Error: https://api.box.com/2.0/users/me does not support SSL
in the file:
bluebird.js:1542
Stacktrace:
bluebird.js:1542 Unhandled rejection Error: SSL Error: https://api.box.com/2.0/users/me does not support SSL at Request.webpackJsonp.../../../../request/request.js.Request.onRequestResponse (https://localhost:4200/vendor.bundle.js:61027:24) at webpackJsonp.../../../../stream-http/lib/request.js.module.exports.webpackJsonp.../../../../events/events.js.EventEmitter.emit (https://localhost:4200/vendor.bundle.js:23478:17) at webpackJsonp.../../../../stream-http/lib/request.js.module.exports.webpackJsonp.../../../../stream-http/lib/request.js.ClientRequest._connect (https://localhost:4200/vendor.bundle.js:76880:7) at https://localhost:4200/vendor.bundle.js:76773:9 at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (https://localhost:4200/polyfills.bundle.js:2806:26) at Object.onInvoke (https://localhost:4200/vendor.bundle.js:120533:33) at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (https://localhost:4200/polyfills.bundle.js:2805:32) at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.run (https://localhost:4200/polyfills.bundle.js:2556:43) at https://localhost:4200/polyfills.bundle.js:3246:57 at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (https://localhost:4200/polyfills.bundle.js:2839:31) at Object.onInvokeTask (https://localhost:4200/vendor.bundle.js:120524:33) at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (https://localhost:4200/polyfills.bundle.js:2838:36) at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (https://localhost:4200/polyfills.bundle.js:2606:47) at drainMicroTaskQueue (https://localhost:4200/polyfills.bundle.js:3010:35) at From previous event: at BoxClient.webpackJsonp.../../../../box-node-sdk/lib/box-client.js.BoxClient._makeRequest (https://localhost:4200/vendor.bundle.js:9321:25) at BoxClient.webpackJsonp.../../../../box-node-sdk/lib/box-client.js.BoxClient.get (https://localhost:4200/vendor.bundle.js:9555:14) at wrappedClientMethod (https://localhost:4200/vendor.bundle.js:9719:20) at Users.webpackJsonp.../../../../box-node-sdk/lib/managers/users.js.Users.get (https://localhost:4200/vendor.bundle.js:15746:60) at SafeSubscriber._next (https://localhost:4200/main.bundle.js:561:26) at SafeSubscriber.webpackJsonp.../../../../rxjs/Subscriber.js.SafeSubscriber.__tryOrUnsub (https://localhost:4200/vendor.bundle.js:62700:16) at SafeSubscriber.webpackJsonp.../../../../rxjs/Subscriber.js.SafeSubscriber.next (https://localhost:4200/vendor.bundle.js:62647:22) at Subscriber.webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber._next (https://localhost:4200/vendor.bundle.js:62587:26) at Subscriber.webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber.next (https://localhost:4200/vendor.bundle.js:62551:18) at CatchSubscriber.webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber._next (https://localhost:4200/vendor.bundle.js:62587:26) at CatchSubscriber.webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber.next (https://localhost:4200/vendor.bundle.js:62551:18) at MapSubscriber.webpackJsonp.../../../../rxjs/operator/map.js.MapSubscriber._next (https://localhost:4200/vendor.bundle.js:65016:26) at MapSubscriber.webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber.next (https://localhost:4200/vendor.bundle.js:62551:18) at XMLHttpRequest.onLoad (https://localhost:4200/vendor.bundle.js:138810:38) at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (https://localhost:4200/polyfills.bundle.js:2839:31) at Object.onInvokeTask (https://localhost:4200/vendor.bundle.js:120524:33) at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (https://localhost:4200/polyfills.bundle.js:2838:36) at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (https://localhost:4200/polyfills.bundle.js:2606:47) printWarning @ bluebird.js:1542 formatAndLogError @ bluebird.js:1258 fireRejectionEvent @ bluebird.js:1283 Promise._notifyUnhandledRejection @ bluebird.js:729 (anonymous) @ bluebird.js:154 webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:424 onInvokeTask @ core.es5.js:3881 webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:423 webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask @ zone.js:191 webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:498 ZoneTask.invoke @ zone.js:487 timer @ zone.js:1823
I have found nothing about this error. If I click the address in the console it works OK and bring back the user data, but from the API, I get the error described.
Any help is welcome. Thanks
-
Well, if anyone is facing this problem, I'll explain my solution
i reviewed the code at the point of failure
Unhandled rejection Error: SSL Error: https://api.box.com/2.0/users/me does not support SSL at Request.webpackJsonp.../../../../request/request.js.Request.onRequestResponse (http://localhost:4200/vendor.bundle.js:61027:24)
vendor.bundle.js block:
// XXX This is different on 0.10, because SSL is strict by default if (self.httpModule === https && self.strictSSL && (!response.hasOwnProperty('socket') || !response.socket.authorized)) { debug('strict ssl error', self.uri.href) var sslErr = response.hasOwnProperty('socket') ? response.socket.authorizationError : self.uri.href + ' does not support SSL' self.emit('error', new Error('SSL Error: ' + sslErr)) return }
The call to Rest Service fails because strictSSL is set to true
I tried setting the config in npm with the command:
npm config set strict-ssl false
but that doesn't solve the problem.
The solution I found is modifying the configuration file in the Box NodeJS API (I was searching in the code where the value of strictSSL is determined).
In my configuration the file is:
/node_modules/box-node-sdk/lib/util/config.js
Change this section:
request: { // By default, require API SSL cert to be valid strictSSL: true, // Use an agent with keep-alive enabled to avoid performing SSL handshake per connection agentClass: https.Agent, agentOptions: { keepAlive: true }, // Encode requests as JSON. Encode the response as well if JSON is returned. json: true, // Do not encode the response as a string, since the response could be a file. return Buffers instead. encoding: null, // A redirect is usually information we want to handle, so don't automatically follow followRedirect: false, // By default, we attach a version-specific user-agent string to SDK requests headers: { 'User-Agent': 'Box Node.js SDK v' + version } }
to this:
request: { // By default, require API SSL cert to be valid strictSSL: false, // Use an agent with keep-alive enabled to avoid performing SSL handshake per connection agentClass: https.Agent, agentOptions: { keepAlive: true }, // Encode requests as JSON. Encode the response as well if JSON is returned. json: true, // Do not encode the response as a string, since the response could be a file. return Buffers instead. encoding: null, // A redirect is usually information we want to handle, so don't automatically follow followRedirect: false, // By default, we attach a version-specific user-agent string to SDK requests headers: { 'User-Agent': 'Box Node.js SDK v' + version } }
that is, switch strictSSL value from true to false
Now it works 🙂
サインインしてコメントを残してください。
コメント
2件のコメント