Skip to content

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

Description

@dantart

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

Activity

  1. haphan commented on Dec 2, 2020

    @haphan
    Collaborator
  2. dantart commented on Dec 2, 2020

    @dantart
    Author

    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 :-(

  3. haphan commented on Dec 2, 2020

    @haphan
    Collaborator
  4. dantart commented on Dec 2, 2020

    @dantart
    Author

    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
    
  5. andreavizzari commented on Mar 6, 2021

    @andreavizzari

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions