• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Node.js 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.createV2SignedUrlSync(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

Number

Optional

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

Headers

Object

Optional

Headers in the temporarily authorized request

QueryParams

Object

Optional

Query parameters in the URL of the temporarily authorized request

Returned Result

Field

Type

Description

SignedUrl

String

Temporarily authorized URL

ActualSignedRequestHeaders

Object

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

Sample Code

// Generate a temporarily authorized URL for creating a bucket.
var createBucketResult = obsClient.createV2SignedUrlSync({Method : 'PUT', Bucket : 'bucketname'});
console.log('SignedUrl-->' + createBucketResult['SignedUrl']);
console.log('ActualSignedRequestHeaders-->' + JSON.stringify(createBucketResult['ActualSignedRequestHeaders']));

// Generate a temporarily authorized URL for uploading an object.
var putObjectResult = obsClient.createV2SignedUrlSync({Method : 'PUT', Bucket : 'bucketname', Key : 'objectkey', Headers : {'Content-Type' : 'text/plain'}});
console.log('SignedUrl-->' + putObjectResult['SignedUrl']);
console.log('ActualSignedRequestHeaders-->' + JSON.stringify(putObjectResult['ActualSignedRequestHeaders']));

// Generate a temporarily authorized URL for setting the ACL of an object.
var setObjectAclResult = obsClient.createV2SignedUrlSync({Method : 'PUT', Bucket : 'bucketname', Key : 'objectkey', SpecialParam: 'acl', Headers: {'x-amz-acl' : 'public-read'}});
console.log('SignedUrl-->' + setObjectAclResult['SignedUrl']);
console.log('ActualSignedRequestHeaders-->' + JSON.stringify(setObjectAclResult['ActualSignedRequestHeaders']));

// Generate a temporarily authorized URL for downloading an object.
var getObjectResult = obsClient.createV2SignedUrlSync({Method : 'GET', Bucket : 'bucketname', Key : 'objectkey'});
console.log('SignedUrl-->' + getObjectResult['SignedUrl']);
console.log('ActualSignedRequestHeaders-->' + JSON.stringify(getObjectResult['ActualSignedRequestHeaders']));

// Generate a temporarily authorized URL for deleting an object.
var deleteObjectResult = obsClient.createV2SignedUrlSync({Method : 'DELETE', Bucket : 'bucketname', Key : 'objectkey'});
console.log('SignedUrl-->' + deleteObjectResult['SignedUrl']);
console.log('ActualSignedRequestHeaders-->' + JSON.stringify(deleteObjectResult['ActualSignedRequestHeaders']));

// Generate a temporarily authorized URL for deleting a bucket.
var deleteBucketResult = obsClient.createV2SignedUrlSync({Method : 'DELETE', Bucket : 'bucketname'});
console.log('SignedUrl-->' + deleteBucketResult['SignedUrl']);
console.log('ActualSignedRequestHeaders-->' + JSON.stringify(deleteBucketResult['ActualSignedRequestHeaders']));