Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it necessary to create a token each time you do things in OpenStack? #320

Open
dantart opened this issue Dec 2, 2020 · 5 comments
Open

Comments

@dantart
Copy link

dantart commented Dec 2, 2020

This is my code to, for example, list objects in a storage:

// Get Token
$client = new \GuzzleHttp\Client(['base_uri' => 'https://auth.cloud.ovh.net/v3/']);
$token = new \OpenStack\Identity\v3\Models\Token($client, new \OpenStack\Identity\v3\Api());
$token->create([ 'user' => [ 'name' => $userId, 'domain' => [ 'name' => 'Default' ], 'password' => $password ] ]);
$mytoken = $token->export();

// Get Storage info
$openstack = new \OpenStack\OpenStack([
    'authUrl' => $authUrl,
    'region'  => $region,
    'user'    => [ 'name'       => $userId, 'password' => $password, 'domain' => [ 'name' => 'Default' ] ],
    'scope'   => [
        'project' => [ 'id' => $projectId, 'domain' => [ 'name' => 'Default' ] ]
    ],
    'cachedToken' => $mytoken,
]);
$container = $openstack->objectStoreV1() ->getContainer($containerName);

If I don't use the "cachedToken" in the command, got from previously "get token" section, it does not work, although I use credentials (user, password...). Do I have to use "cachedToken" attribute always?

The error without using the cachedToken is:

HTTP Error
~~~~~~~~~~
The remote server returned a "401 Unauthorized" error for the following transaction:

Request
~~~~~~~
POST /v1/AUTH_********************************/auth/tokens HTTP/1.1
User-Agent: GuzzleHttp/7
Content-Type: application/json
Host: storage.gra.cloud.ovh.net

I've seen it has an expiration of 24 hours ... I know I can "save" it to a file and use it at least 24 hours ... the question is, is there a way to use, for example, the objectStoreV1 method, without using token and using the real credentials (user, password should be enough, right?)

Thank you

@haphan
Copy link
Collaborator

haphan commented Dec 2, 2020 via email

@dantart
Copy link
Author

dantart commented Dec 2, 2020

Then why in all documentation examples is not the cachedToken parameter?
https://php-openstack-sdk.readthedocs.io/en/latest/services/object-store/v1/objects.html#create-an-object
I spent a lot of time figuring out how to use it :-(

@haphan
Copy link
Collaborator

haphan commented Dec 2, 2020 via email

@dantart
Copy link
Author

dantart commented Dec 2, 2020

Well, that's my point !
I want to use CREDENTIALS, and just credentials. Your point 1 ;-)

If I use the command with credentials and without the cachedToken , it does not work:

// Get Storage info
$openstack = new \OpenStack\OpenStack([
    'authUrl' => $authUrl,
    'region'  => $region,
    'user'    => [ 'name'       => $userId, 'password' => $password, 'domain' => [ 'name' => 'Default' ] ],
    'scope'   => [
        'project' => [ 'id' => $projectId, 'domain' => [ 'name' => 'Default' ] ]
    ],
]);
$container = $openstack->objectStoreV1() ->getContainer($containerName);

The error is shown above, the error without using the cachedToken is:

HTTP Error

The remote server returned a "401 Unauthorized" error for the following transaction:

Request
~~~~~~~
POST /v1/AUTH_********************************/auth/tokens HTTP/1.1
User-Agent: GuzzleHttp/7
Content-Type: application/json
Host: storage.gra.cloud.ovh.net

@fmfgroup
Copy link

fmfgroup commented Mar 6, 2021

Well, that's my point !
I want to use CREDENTIALS, and just credentials. Your point 1 ;-)

If I use the command with credentials and without the cachedToken , it does not work:

// Get Storage info
$openstack = new \OpenStack\OpenStack([
    'authUrl' => $authUrl,
    'region'  => $region,
    'user'    => [ 'name'       => $userId, 'password' => $password, 'domain' => [ 'name' => 'Default' ] ],
    'scope'   => [
        'project' => [ 'id' => $projectId, 'domain' => [ 'name' => 'Default' ] ]
    ],
]);
$container = $openstack->objectStoreV1() ->getContainer($containerName);

The error is shown above, the error without using the cachedToken is:

HTTP Error

The remote server returned a "401 Unauthorized" error for the following transaction:

Request
~~~~~~~
POST /v1/AUTH_********************************/auth/tokens HTTP/1.1
User-Agent: GuzzleHttp/7
Content-Type: application/json
Host: storage.gra.cloud.ovh.net

Same issue. @dantart did you resolve? I can comment out the user field in $openstack object, but $token is required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants