• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (PHP SDK)
  4. Other APIs
  5. Temporary Authentication

Temporary Authentication

API Description

You can use this API to generate a temporarily authorized URL. This URL can be used to perform specific operations on OBS in temporary authentication mode.

Method Definition

ObsClient->createV2SignedUrl(array $parameter)

Request Parameter

Field

Type

Optional or Mandatory

Description

Method

string

Mandatory

HTTP method. Possible values are:

  • GET
  • POST
  • PUT
  • DELETE
  • HEAD

Bucket

string

Optional

Bucket name

Key

string

Optional

Object name

SpecialParam

string

Optional

Special operator, which indicates the sub-resource to be operated. Possible values are:

  • versions
  • uploads
  • location
  • storageinfo
  • quota
  • storagePolicy
  • acl
  • logging
  • policy
  • lifecycle
  • website
  • versioning
  • cors
  • notification
  • tagging
  • delete
  • restore

Expires

integer

Optional

Validity period of the temporarily authorized URL, in seconds. The default value is 300.

Headers

associative array

Optional

Headers in the temporarily authorized request

QueryParams

associative array

Optional

Query parameters in the URL of the temporarily authorized request

Returned Result

Field

Type

Description

SignedUrl

string

Temporarily authorized URL

ActualSignedRequestHeaders

associative array

Actual headers in the request initiated by using the temporarily authorized URL

Sample Code

try {
       // Generate a temporarily authorized URL for creating a bucket.
       $resp = $obsClient->createV2SignedUrl( [ 
              'Method' => 'PUT',
              'Bucket' => 'bucketname',
              'Expires' => 3600,
       ] );
       printf ( "SignedUrl:%s\n", $resp ['SignedUrl'] );
       printf ( "ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true) );
       
       // Generate a temporarily authorized URL for uploading an object.
       $resp = $obsClient->createV2SignedUrl( [
                     'Method' => 'PUT',
                     'Bucket' => 'bucketname',
                     'Key' => 'objectkey',
                     'Expires' => 3600,
                     'Headers' => ['content-type' => 'text/plain']
       ] );
       printf ( "SignedUrl:%s\n", $resp ['SignedUrl'] );
       printf ( "ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true) );

       // Generate a temporarily authorized URL for setting the ACL of an object.
       $resp = $obsClient->createV2SignedUrl( [
                     'Method' => 'PUT',
                     'Bucket' => 'bucketname',
                     'Key' => 'objectkey',
                     'Expires' => 3600,
                     'SpecialParam' => 'acl',
                     'Headers' => ['x-amz-acl' => 'public-read']
       ] );
       printf ( "SignedUrl:%s\n", $resp ['SignedUrl'] );
       printf ( "ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true) );
       
       // Generate a temporarily authorized URL for downloading an object.
       $resp = $obsClient->createV2SignedUrl( [
                     'Method' => 'GET',
                     'Bucket' => 'bucketname',
                     'Key' => 'objectkey',
                     'Expires' => 3600
       ] );
       printf ( "SignedUrl:%s\n", $resp ['SignedUrl'] );
       printf ( "ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true) );

       // Generate a temporarily authorized URL for deleting an object.
       $resp = $obsClient->createV2SignedUrl( [
                     'Method' => 'DELETE',
                     'Bucket' => 'bucketname',
                     'Key' => 'objectkey',
                     'Expires' => 3600
       ] );
       printf ( "SignedUrl:%s\n", $resp ['SignedUrl'] );
       printf ( "ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true) );
       
       // Generate a temporarily authorized URL for deleting a bucket.
       $resp = $obsClient->createV2SignedUrl( [
                     'Method' => 'DELETE',
                     'Bucket' => 'bucketname',
                     'Expires' => 3600
       ] );
       printf ( "SignedUrl:%s\n", $resp ['SignedUrl'] );
       printf ( "ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true) );
} catch ( Obs\Common\ObsException $obsException ) {
       printf ( "ExceptionCode:%s\n", $obsException->getExceptionCode () );
       printf ( "ExceptionMessage:%s\n", $obsException->getExceptionMessage () );
}