本文介绍了Bluemix - 对象存储 - node.js的 - pkgcloud - OpenStack的返回401的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用pkgc​​loud(node.js的)用的OpenStack对象bluemix存储,但是当我把所有的请求的参数官方页面上,它总是返回401.我想作为bluemix描述和它的作品使用邮递员。

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.

推荐答案

我创建了一个,这是能够授权的权利。这仅仅是一个pkgcloud的副本,有几个补丁。

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

编辑:这是工作!该v2支持被bluemix击落,它现在只有V3支持,但我再次找到问题。

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.

记住要使用最新版本(2.0.0)

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:你应该能够连接到这个服务bluemix之外,因此您可以在本地主机测试


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

下面的行是旧内容1.2.3版本,如果你想2016年1月前使用pkgc​​loud这与bluemix工作的V2版本只读

编辑:它看起来像bluemix关停V2 OpenStack的支持,只支持V3,它不受pkgcloud都支持。所以,这并不(至少对我来说)工作了。

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).

这个问题实际上是pkgcloud和bluemix授权过程之间。 Bluemix期待有点diffent授权。我创建了一个,这是能够授权的权利。这仅仅是一个pkgcloud的副本,有几个补丁。

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.

这就是你如何使用它:

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));
        }

    });

这篇关于Bluemix - 对象存储 - node.js的 - pkgcloud - OpenStack的返回401的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 11:05