• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Python 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(method, bucketName, objectKey, specialParam, expires, headers, queryParams)

Request Parameter

Field

Type

Optional or Mandatory

Description

method

str

Mandatory

HTTP method. Possible values are:

  • GET
  • POST
  • PUT
  • DELETE
  • HEAD

bucketName

str

Optional

Bucket name

objectKey

str

Optional

Object name

specialParam

str

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

int

Optional

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

headers

dict

Optional

Headers in the temporarily authorized request

queryParams

dict

Optional

Query parameters in the URL of the temporarily authorized request

Returned Result

Field

Type

Description

signedUrl

str

Temporarily authorized URL

actualSignedRequestHeaders

dict

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

Sample Code

try:
    # Generate a temporarily authorized URL for creating a bucket.
    res = obsClient.createV2SignedUrl('PUT', 'bucketname', expires= 3600) 
    print('signedUrl:', res.signedUrl) 
    print('actualSignedRequestHeaders:', res.actualSignedRequestHeaders) 
     
    # Generate a temporarily authorized URL for uploading an object.
    res = obsClient.createV2SignedUrl('PUT', 'bucketname', 'objectkey', expires= 3600, headers={'Content-Type' : 'text/plain'}) 
    print('signedUrl:', res.signedUrl) 
    print('actualSignedRequestHeaders:', res.actualSignedRequestHeaders) 
     
    # Generate a temporarily authorized URL for setting the ACL of an object.
    res = obsClient.createV2SignedUrl('PUT', 'bucketname', 'objectkey', 'acl', expires= 3600, headers={'x-amz-acl' : 'public-read'}) 
    print('signedUrl:', res.signedUrl) 
    print('actualSignedRequestHeaders:', res.actualSignedRequestHeaders) 
     
    # Generate a temporarily authorized URL for downloading an object.
    res = obsClient.createV2SignedUrl('GET', 'bucketname', 'objectkey', expires= 3600) 
    print('signedUrl:', res.signedUrl) 
    print('actualSignedRequestHeaders:', res.actualSignedRequestHeaders) 
     
    # Generate a temporarily authorized URL for deleting an object.
    res = obsClient.createV2SignedUrl('DELETE', 'bucketname', 'objectkey', expires= 3600) 
    print('signedUrl:', res.signedUrl) 
    print('actualSignedRequestHeaders:', res.actualSignedRequestHeaders) 
     
    # Generate a temporarily authorized URL for deleting a bucket.
    res = obsClient.createV2SignedUrl('DELETE', 'bucketname', expires= 3600) 
    print('signedUrl:', res.signedUrl) 
    print('actualSignedRequestHeaders:', res.actualSignedRequestHeaders) 
except:
    import traceback
    print(traceback.format_exc())