首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bluemix对象存储- node.js - pkgcloud - openstack返回401

Bluemix对象存储- node.js - pkgcloud - openstack返回401
EN

Stack Overflow用户
提问于 2015-12-22 12:09:18
回答 1查看 1.7K关注 0票数 1

我尝试使用pkgcloud (node.js) openstack来存储bluemix存储,但是当我将所有请求的参数都放在官方页面上时,它总是返回401。我试着用布卢米克斯描述的邮递员,它起作用了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-22 12:09:18

我创建了一个套餐,它能够正确地授权它。它只是一个pkgcloud的副本,有一些修正。

编辑: IT正在工作!V2支持被bluemix击落,现在它只有V3支持,但我再次发现了问题。

记住使用最新版本(2.0.0)

所以,现在您可以这样使用它:

代码语言:javascript
复制
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之外的服务,因此您可以在本地主机上测试它。

下面的行用于1.2.3版本的旧内容,如果您希望使用v2版本的pkgcloud,则只需阅读该版本,该版本在2016年1月之前使用

编辑:看起来像是v2 openstack的关闭支持,只支持v3,而v3完全不受pkgcloud的支持。所以这已经不起作用了(至少对我来说)。

问题实际上是在pkgcloud和bluemix授权过程之间。布卢米克斯希望得到一些不同的授权。我创建了一个套餐,它能够正确地授权它。它只是一个pkgcloud的副本,有一些修正。

这就是你可以使用的方法:

代码语言:javascript
复制
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));
        }

    });
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34415631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档