sausin / laravel-ovh

Wrapper for OVH Object Storage integration with laravel
MIT License
37 stars 12 forks source link

401 Unauthorized - Project ID is sent instead of project NAME in the request body #91

Closed playinglife closed 1 year ago

playinglife commented 1 year ago

Hello I have laravel-ovh - version 7.0.1.

I have the following ENV variables in the .env file:

OS_AUTH_URL = https://auth.cloud.ovh.net/v3/
OS_PROJECT_ID = MY-PROJECT-ID
OS_REGION_NAME = MY-REGION
OS_USER_DOMAIN_NAME = default
OS_USERNAME = MY-USER-NAME
OS_PASSWORD = MY-PASSWORD
OS_CONTAINER_NAME = test
OS_CUSTOM_ENDPOINT = MY_ENDPOINT

Then in filesystems.php:

    'ovh' => [
        'driver' => 'ovh',
        'authUrl' => env('OS_AUTH_URL', 'https://auth.cloud.ovh.net/v3/'),
        'projectId' => env('OS_PROJECT_ID'),
        'region' => env('OS_REGION_NAME'),
        'userDomain' => env('OS_USER_DOMAIN_NAME', 'Default'),
        'username' => env('OS_USERNAME'),
        'password' => env('OS_PASSWORD'),
        'containerName' => env('OS_CONTAINER_NAME'),

        // Since v1.2
        // Optional variable and only if you are using temporary signed urls.
        // You can also set a new key using the command 'php artisan ovh:set-temp-url-key'.
        'tempUrlKey' => env('OS_TEMP_URL_KEY'),

        // Since v2.1
        // Optional variable and only if you have setup a custom endpoint.
        'endpoint' => env('OS_CUSTOM_ENDPOINT'),

        // Optional variables for handling large objects.
        // Defaults below are 300MB threshold & 100MB segments.
        'swiftLargeObjectThreshold' => env('OS_LARGE_OBJECT_THRESHOLD', 300 * 1024 * 1024),
        'swiftSegmentSize' => env('OS_SEGMENT_SIZE', 100 * 1024 * 1024),
        'swiftSegmentContainer' => env('OS_SEGMENT_CONTAINER', null),

        // Optional variable and only if you would like to DELETE all uploaded object by DEFAULT.
        // This allows you to set an 'expiration' time for every new uploaded object to
        // your container. This will not affect objects already in your container.
        //
        // If you're not willing to DELETE uploaded objects by DEFAULT, leave it empty.
        // Really, if you don't know what you're doing, you should leave this empty as well.
        'deleteAfter' => env('OS_DEFAULT_DELETE_AFTER', null),

        // Optional variable to cache your storage objects in memory
        // You must require league/flysystem-cached-adapter to enable caching
        // This option is not available on laravel-ovh >= 7.0
        'cache' => true, // Defaults to false

        // Optional variable to set a prefix on all paths
        'prefix' => null,
    ],   

If I send a POST request from POSTMAN with this body I get authorized:

{
   "auth":{
      "identity":{
         "methods":[
            "password"
         ],
         "password":{
            "user":{
               "name":"MY_USER-NAME",
               "domain":{
                  "name":"default"
               },
               "password":"MY-PASSWORD"
            }
         }
      },
      "scope":{
         "project":{
            "name":"OS-PROJECT-NAME",
            "domain":{
               "id":"default"
            }
         }
      }
   }
}

But in Laravel 9 I get an error 401 unauthorized. When I check the error message I can see that the body of the request has instead of "scope" -> "project" -> "name" I have "scope" -> "project" -> "id". (ID instead of NAME). Below is error message from Laravel 9:

HTTP Error ~~ The remote server returned a "401 UNAUTHORIZED" error for the following transaction: Request ~~~ POST /v3/auth/tokens HTTP/1.1 User-Agent: GuzzleHttp/7 Content-Type: application/json Host: auth.cloud.ovh.net {"auth":{"identity":{"password":{"user":{"name":"MY-NAME","password":"MY-PASSWORD","domain":{"name":"default"}}},"methods":["password"]},"scope":{"project":{"id":"OS-PROJECT-NAME"}}}} Response ~~ HTTP/1.1 401 UNAUTHORIZED date: Fri, 24 Mar 2023 18:56:23 GMT content-type: application/json content-length: 109 www-authenticate: Keystone uri="https://auth.cloud.ovh.net/v3" vary: X-Auth-Token x-openstack-request-id: req-267cc0f3-3838-42fc-aeab-58d156319aad strict-transport-security: max-age=15724800; includeSubDomains x-iplb-request-id: 567D3B34:DA1D_334441F7:01BB_641DF257_EA6C8C:27ADF x-iplb-instance: 47017 {"error":{"code":401,"message":"The request you have made requires authentication.","title":"Unauthorized"}} Further information ~~~~~ Please ensure that your authentication credentials are valid. Visit http://docs.php-opencloud.com/en/latest/http-codes for more information about debugging HTTP status codes, or file a support issue on https://github.com/php-opencloud/openstack/issues.

sausin commented 1 year ago

Please check the docs again, the description of OS_PROJECT_ID is specified.

sausin commented 1 year ago

Closing issue as no update