Bluemix - object storage - node.js - pkgcloud - openstack returns 401

末鹿安然 提交于 2019-12-08 04:05:13

问题


I am trying to use pkgcloud (node.js) openstack with bluemix object storage, but when I put all the requested parameters as on official page, it always returns 401. I tried using postman as described on bluemix and it works.


回答1:


I created a package, which is able to to authorize it right. It is just a copy of pkgcloud, with a few fixes.

EDIT: IT IS WORKING! The V2 supports was shot down by bluemix and it has only V3 support now, but I once again find the issues.

Remember to use newest version (2.0.0)

So this is how you can use it now :

var pkgcloud = require('pkgcloud-bluemix-objectstorage');

// Create a config object
    var config = {};

// Specify Openstack as the provider
    config.provider = "openstack";

// Authentication url
    config.authUrl = 'https://identity.open.softlayer.com/';
    config.region= 'dallas';

// Use the service catalog
    config.useServiceCatalog = true;

// true for applications running inside Bluemix, otherwise false
    config.useInternal = false;

// projectId as provided in your Service Credentials
    config.tenantId = 'xxx';

// userId as provided in your Service Credentials
    config.userId = 'xxx';

// username as provided in your Service Credentials
    config.username = 'xxx';

// password as provided in your Service Credentials
    config.password = 'xxx';

// This is part which is NOT in original pkgcloud. This is how it works with newest version of bluemix and pkgcloud at 22.12.2015. 
//In reality, anything you put in this config.auth will be send in body to server, so if you need change anything to make it work, you can. PS : Yes, these are the same credentials as you put to config before. 
//I do not fill this automatically to make it transparent.

config.auth = {
    forceUri  : "https://identity.open.softlayer.com/v3/auth/tokens", //force uri to v3, usually you take the baseurl for authentication and add this to it /v3/auth/tokens (at least in bluemix)    
    interfaceName : "public", //use public for apps outside bluemix and internal for apps inside bluemix. There is also admin interface, I personally do not know, what it is for.
    "identity": {
        "methods": [
            "password"
        ],
        "password": {
            "user": {
                "id": "***", //userId
                "password": "***" //userPassword
            }
        }
    },
    "scope": {
        "project": {
            "id": "***" //projectId
        }
    }
};

    console.log("config: " + JSON.stringify(config));

// Create a pkgcloud storage client
    var storageClient = pkgcloud.storage.createClient(config);

// Authenticate to OpenStack
     storageClient.auth(function (error) {
        if (error) {
            console.error("storageClient.auth() : error creating storage client: ", error);
        }
        else {
            // Print the identity object which contains your Keystone token.
            console.log("storageClient.auth() : created storage client: " + JSON.stringify(storageClient._identity));
        }

    });

PS : You should be able to connect to this service outside of bluemix, therefore you can test it on your localhost.


Lines below are for old content for version 1.2.3, read only if you want to use v2 version of pkgcloud which was working with bluemix before January 2016

EDIT: It looks like that bluemix shut down support for v2 openstack and only supports v3, which is not supported by pkgcloud at all. So this does not work anymore (at least for me).


The problem is actually between pkgcloud and bluemix authorization process. Bluemix is expecting a little diffent authorization. I created a package, which is able to to authorize it right. It is just a copy of pkgcloud, with a few fixes.

And this is how you can use it :

var pkgcloud = require('pkgcloud-bluemix-objectstorage');

// Create a config object
    var config = {};

// Specify Openstack as the provider
    config.provider = "openstack";

// Authentication url
    config.authUrl = 'https://identity.open.softlayer.com/';
    config.region= 'dallas';

// Use the service catalog
    config.useServiceCatalog = true;

// true for applications running inside Bluemix, otherwise false
    config.useInternal = false;

// projectId as provided in your Service Credentials
    config.tenantId = 'xxx';

// userId as provided in your Service Credentials
    config.userId = 'xxx';

// username as provided in your Service Credentials
    config.username = 'xxx';

// password as provided in your Service Credentials
    config.password = 'xxx';

// This is part which is NOT in original pkgcloud. This is how it works with newest version of bluemix and pkgcloud at 22.12.2015. 
//In reality, anything you put in this config.auth will be send in body to server, so if you need change anything to make it work, you can. PS : Yes, these are the same credentials as you put to config before. 
//I do not fill this automatically to make it transparent.

    config.auth = {
        tenantId: "xxx", //projectId
        passwordCredentials: {
            userId: "xxx", //userId
            password: "xxx" //password
        }
    };

    console.log("config: " + JSON.stringify(config));

// Create a pkgcloud storage client
    var storageClient = pkgcloud.storage.createClient(config);

// Authenticate to OpenStack
     storageClient.auth(function (error) {
        if (error) {
            console.error("storageClient.auth() : error creating storage client: ", error);
        }
        else {
            // Print the identity object which contains your Keystone token.
            console.log("storageClient.auth() : created storage client: " + JSON.stringify(storageClient._identity));
        }

    });


来源:https://stackoverflow.com/questions/34415631/bluemix-object-storage-node-js-pkgcloud-openstack-returns-401

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!