Skip to content

Commit d92fd84

Browse files
committed
- Fix error handling in authentication
- Readme changes - ObjectApi - change getSesionId signature
1 parent db39a8c commit d92fd84

13 files changed

+118
-111
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ and 3-legged tokens for calling different Data Management endpoints.
3232
#### 2-Legged Token
3333

3434
This type of token is given directly to the application.
35-
To get a 2-legged token run the following code:
35+
To get a 2-legged token run the following code. Note that you need to replace `your-client-id` and `your-client-secret` with your [app](https://developer.autodesk.com/myapps)'s client ID and client secret.
3636

3737
``` JavaScript
3838
var ForgeSDK = require('forge-apis');
@@ -59,11 +59,15 @@ oAuth2TwoLegged.authenticate().then(function(credentials){
5959
##### Generate an Authentication URL
6060

6161
To ask for permissions from a user to retrieve an access token, you
62-
redirect the user to a consent page. Run this code to create a consent page URL:
62+
redirect the user to a consent page.
63+
64+
Replace `your-client-id`, `your-client-secret`, and `your-redirect-url` with your [app](https://developer.autodesk.com/myapps)'s client ID, client secret, and redirect URL, and run the code to create a consent page URL.
65+
66+
Note that the redirect URL must match the pattern of the callback URL field of the app’s registration in the My Apps section. The pattern may include wildcards after the hostname, allowing different redirect URL values to be specified in different parts of your app.
6367

6468
``` JavaScript
6569
var ForgeSDK = require('forge-apis');
66-
var CLIENT_ID = '' , CLIENT_SECRET = '', REDIRECT_URL = '';
70+
var CLIENT_ID = '<your-client-id>', CLIENT_SECRET = '<your-client-secret>', REDIRECT_URL = '<your-redirect-url>';
6771

6872
// Initialize the 3-legged OAuth2 client, set specific scopes and optionally set the `autoRefresh` parameter to true
6973
// if you want the token to auto refresh
@@ -198,8 +202,8 @@ Class | Method | HTTP request | Description
198202
*ForgeSdk.ObjectsApi* | [**getObject**](docs/ObjectsApi.md#getObject) | **GET** /oss/v2/buckets/{bucketKey}/objects/{objectName} |
199203
*ForgeSdk.ObjectsApi* | [**getObjectDetails**](docs/ObjectsApi.md#getObjectDetails) | **GET** /oss/v2/buckets/{bucketKey}/objects/{objectName}/details |
200204
*ForgeSdk.ObjectsApi* | [**getObjects**](docs/ObjectsApi.md#getObjects) | **GET** /oss/v2/buckets/{bucketKey}/objects |
201-
*ForgeSdk.ObjectsApi* | [**getSessionid**](docs/ObjectsApi.md#getSessionid) | **GET** /oss/v2/buckets/{bucketKey}/objects/{objectName}/status/{sessionId} |
202205
*ForgeSdk.ObjectsApi* | [**getSignedResource**](docs/ObjectsApi.md#getSignedResource) | **GET** /oss/v2/signedresources/{id} |
206+
*ForgeSdk.ObjectsApi* | [**getStatusBySessionId**](docs/ObjectsApi.md#getStatusBySessionId) | **GET** /oss/v2/buckets/{bucketKey}/objects/{objectName}/status/{sessionId} |
203207
*ForgeSdk.ObjectsApi* | [**uploadChunk**](docs/ObjectsApi.md#uploadChunk) | **PUT** /oss/v2/buckets/{bucketKey}/objects/{objectName}/resumable |
204208
*ForgeSdk.ObjectsApi* | [**uploadObject**](docs/ObjectsApi.md#uploadObject) | **PUT** /oss/v2/buckets/{bucketKey}/objects/{objectName} |
205209
*ForgeSdk.ObjectsApi* | [**uploadSignedResource**](docs/ObjectsApi.md#uploadSignedResource) | **PUT** /oss/v2/signedresources/{id} |

docs/DerivativesApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Name | Type | Description | Notes
3939

4040
### HTTP request headers
4141

42-
- **Content-Type**: Not defined
42+
- **Content-Type**: application/x-www-form-urlencoded
4343
- **Accept**: application/vnd.api+json, application/json
4444

4545
<a name="getDerivativeManifest"></a>

docs/MetadataObject.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
66
**objectid** | **Integer** | Unique ID for the object |
77
**name** | **String** | Name of the object |
8-
**objects** | **[String]** | Optional collection of “children” objects within the hierarchy | [optional]
8+
**objects** | [**[MetadataObject]**](MetadataObject.md) | Optional collection of “children” objects within the hierarchy | [optional]
99

1010

docs/ObjectsApi.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Method | HTTP request | Description
1111
[**getObject**](ObjectsApi.md#getObject) | **GET** /oss/v2/buckets/{bucketKey}/objects/{objectName} |
1212
[**getObjectDetails**](ObjectsApi.md#getObjectDetails) | **GET** /oss/v2/buckets/{bucketKey}/objects/{objectName}/details |
1313
[**getObjects**](ObjectsApi.md#getObjects) | **GET** /oss/v2/buckets/{bucketKey}/objects |
14-
[**getSessionid**](ObjectsApi.md#getSessionid) | **GET** /oss/v2/buckets/{bucketKey}/objects/{objectName}/status/{sessionId} |
1514
[**getSignedResource**](ObjectsApi.md#getSignedResource) | **GET** /oss/v2/signedresources/{id} |
15+
[**getStatusBySessionId**](ObjectsApi.md#getStatusBySessionId) | **GET** /oss/v2/buckets/{bucketKey}/objects/{objectName}/status/{sessionId} |
1616
[**uploadChunk**](ObjectsApi.md#uploadChunk) | **PUT** /oss/v2/buckets/{bucketKey}/objects/{objectName}/resumable |
1717
[**uploadObject**](ObjectsApi.md#uploadObject) | **PUT** /oss/v2/buckets/{bucketKey}/objects/{objectName} |
1818
[**uploadSignedResource**](ObjectsApi.md#uploadSignedResource) | **PUT** /oss/v2/signedresources/{id} |
@@ -226,25 +226,28 @@ Name | Type | Description | Notes
226226
- **Content-Type**: application/json
227227
- **Accept**: application/vnd.api+json, application/json
228228

229-
<a name="getSessionid"></a>
230-
# **getSessionid**
231-
> Result getSessionid(bucketKey, objectName, sessionId, oauth2client, credentials)
229+
<a name="getSignedResource"></a>
230+
# **getSignedResource**
231+
> Object getSignedResource(id, opts, oauth2client, credentials)
232232
233233

234234

235-
This endpoint returns status information about a resumable upload.
235+
Download an object using a signed URL.
236236

237237
### Parameters
238238

239239
Name | Type | Description | Notes
240240
------------- | ------------- | ------------- | -------------
241-
**bucketKey** | **String**| URL-encoded bucket key |
242-
**objectName** | **String**| URL-encoded object name |
243-
**sessionId** | **String**| Unique identifier of a session of a file being uploaded |
241+
**id** | **String**| Id of signed resource |
242+
**range** | **String**| A range of bytes to download from the specified object. | [optional]
243+
**ifNoneMatch** | **String**| The value of this header is compared to the ETAG of the object. If they match, the body will not be included in the response. Only the object information will be included. | [optional]
244+
**ifModifiedSince** | **Date**| If the requested object has not been modified since the time specified in this field, an entity will not be returned from the server; instead, a 304 (not modified) response will be returned without any message body. | [optional]
245+
**acceptEncoding** | **String**| When gzip is specified, a gzip compressed stream of the object’s bytes will be returned in the response. Cannot use “Accept-Encoding:gzip” with Range header containing an end byte range. End byte range will not be honored if “Accept-Encoding: gzip” header is used. | [optional]
246+
**region** | **String**| The region where the bucket resides Acceptable values: &#x60;US&#x60;, &#x60;EMEA&#x60; Default is &#x60;US&#x60; | [optional] [default to US]
244247

245248
### Return type
246249

247-
[**Result**](Result.md)
250+
**Object**
248251

249252
### Authorization
250253

@@ -253,30 +256,27 @@ Name | Type | Description | Notes
253256
### HTTP request headers
254257

255258
- **Content-Type**: application/json
256-
- **Accept**: application/vnd.api+json, application/json
259+
- **Accept**: application/octet-stream
257260

258-
<a name="getSignedResource"></a>
259-
# **getSignedResource**
260-
> Object getSignedResource(id, opts, oauth2client, credentials)
261+
<a name="getStatusBySessionId"></a>
262+
# **getStatusBySessionId**
263+
> getStatusBySessionId(bucketKey, objectName, sessionId, oauth2client, credentials)
261264
262265

263266

264-
Download an object using a signed URL.
267+
This endpoint returns status information about a resumable upload.
265268

266269
### Parameters
267270

268271
Name | Type | Description | Notes
269272
------------- | ------------- | ------------- | -------------
270-
**id** | **String**| Id of signed resource |
271-
**range** | **String**| A range of bytes to download from the specified object. | [optional]
272-
**ifNoneMatch** | **String**| The value of this header is compared to the ETAG of the object. If they match, the body will not be included in the response. Only the object information will be included. | [optional]
273-
**ifModifiedSince** | **Date**| If the requested object has not been modified since the time specified in this field, an entity will not be returned from the server; instead, a 304 (not modified) response will be returned without any message body. | [optional]
274-
**acceptEncoding** | **String**| When gzip is specified, a gzip compressed stream of the object’s bytes will be returned in the response. Cannot use “Accept-Encoding:gzip” with Range header containing an end byte range. End byte range will not be honored if “Accept-Encoding: gzip” header is used. | [optional]
275-
**region** | **String**| The region where the bucket resides Acceptable values: &#x60;US&#x60;, &#x60;EMEA&#x60; Default is &#x60;US&#x60; | [optional] [default to US]
273+
**bucketKey** | **String**| URL-encoded bucket key |
274+
**objectName** | **String**| URL-encoded object name |
275+
**sessionId** | **String**| Unique identifier of a session of a file being uploaded |
276276

277277
### Return type
278278

279-
**Object**
279+
null (empty response body)
280280

281281
### Authorization
282282

@@ -285,7 +285,7 @@ Name | Type | Description | Notes
285285
### HTTP request headers
286286

287287
- **Content-Type**: application/json
288-
- **Accept**: application/octet-stream
288+
- **Accept**: application/vnd.api+json, application/json
289289

290290
<a name="uploadChunk"></a>
291291
# **uploadChunk**

docs/PostObjectSigned.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
66
**signedUrl** | **String** | URL created for downloading the object |
7-
**expiration** | **Date** | Value for expiration in minutes |
7+
**expiration** | **Integer** | Value for expiration in minutes |
88

99

src/api/DerivativesApi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module.exports = (function() {
7979
var formParams = {
8080
};
8181

82-
var contentTypes = [];
82+
var contentTypes = ['application/x-www-form-urlencoded'];
8383
var accepts = ['application/vnd.api+json', 'application/json'];
8484
var returnType = Result;
8585

src/api/ObjectsApi.js

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -398,101 +398,100 @@ module.exports = (function() {
398398

399399

400400
/**
401-
* This endpoint returns status information about a resumable upload.
402-
* @param {String} bucketKey URL-encoded bucket key
403-
* @param {String} objectName URL-encoded object name
404-
* @param {String} sessionId Unique identifier of a session of a file being uploaded
405-
* data is of type: {module:model/Result}
401+
* Download an object using a signed URL.
402+
* @param {String} id Id of signed resource
403+
* @param {Object} opts Optional parameters
404+
* @param {String} opts.range A range of bytes to download from the specified object.
405+
* @param {String} opts.ifNoneMatch The value of this header is compared to the ETAG of the object. If they match, the body will not be included in the response. Only the object information will be included.
406+
* @param {Date} opts.ifModifiedSince If the requested object has not been modified since the time specified in this field, an entity will not be returned from the server; instead, a 304 (not modified) response will be returned without any message body.
407+
* @param {String} opts.acceptEncoding When gzip is specified, a gzip compressed stream of the object’s bytes will be returned in the response. Cannot use “Accept-Encoding:gzip” with Range header containing an end byte range. End byte range will not be honored if “Accept-Encoding: gzip” header is used.
408+
* @param {module:model/String} opts.region The region where the bucket resides Acceptable values: `US`, `EMEA` Default is `US` (default to US)
409+
* data is of type: {Object}
406410
* @param {Object} oauth2client oauth2client for the call
407411
* @param {Object} credentials credentials for the call
408412
*/
409-
this.getSessionid = function(bucketKey, objectName, sessionId, oauth2client, credentials) {
413+
this.getSignedResource = function(id, opts, oauth2client, credentials) {
414+
opts = opts || {};
410415
var postBody = null;
411416

412-
// verify the required parameter 'bucketKey' is set
413-
if (bucketKey == undefined || bucketKey == null) {
414-
return Promise.reject("Missing the required parameter 'bucketKey' when calling getSessionid");
415-
}
416-
417-
// verify the required parameter 'objectName' is set
418-
if (objectName == undefined || objectName == null) {
419-
return Promise.reject("Missing the required parameter 'objectName' when calling getSessionid");
420-
}
421-
422-
// verify the required parameter 'sessionId' is set
423-
if (sessionId == undefined || sessionId == null) {
424-
return Promise.reject("Missing the required parameter 'sessionId' when calling getSessionid");
417+
// verify the required parameter 'id' is set
418+
if (id == undefined || id == null) {
419+
return Promise.reject("Missing the required parameter 'id' when calling getSignedResource");
425420
}
426421

427422

428423
var pathParams = {
429-
'bucketKey': bucketKey,
430-
'objectName': objectName,
431-
'sessionId': sessionId
424+
'id': id
432425
};
433426
var queryParams = {
427+
'region': opts['region']
434428
};
435429
var headerParams = {
430+
'Range': opts['range'],
431+
'If-None-Match': opts['ifNoneMatch'],
432+
'If-Modified-Since': opts['ifModifiedSince'],
433+
'Accept-Encoding': opts['acceptEncoding']
436434
};
437435
var formParams = {
438436
};
439437

440438
var contentTypes = ['application/json'];
441-
var accepts = ['application/vnd.api+json', 'application/json'];
442-
var returnType = Result;
439+
var accepts = ['application/octet-stream'];
440+
var returnType = Object;
443441

444442
return this.apiClient.callApi(
445-
'/oss/v2/buckets/{bucketKey}/objects/{objectName}/status/{sessionId}', 'GET',
443+
'/oss/v2/signedresources/{id}', 'GET',
446444
pathParams, queryParams, headerParams, formParams, postBody,
447445
contentTypes, accepts, returnType, oauth2client, credentials
448446
);
449447
};
450448

451449

452450
/**
453-
* Download an object using a signed URL.
454-
* @param {String} id Id of signed resource
455-
* @param {Object} opts Optional parameters
456-
* @param {String} opts.range A range of bytes to download from the specified object.
457-
* @param {String} opts.ifNoneMatch The value of this header is compared to the ETAG of the object. If they match, the body will not be included in the response. Only the object information will be included.
458-
* @param {Date} opts.ifModifiedSince If the requested object has not been modified since the time specified in this field, an entity will not be returned from the server; instead, a 304 (not modified) response will be returned without any message body.
459-
* @param {String} opts.acceptEncoding When gzip is specified, a gzip compressed stream of the object’s bytes will be returned in the response. Cannot use “Accept-Encoding:gzip” with Range header containing an end byte range. End byte range will not be honored if “Accept-Encoding: gzip” header is used.
460-
* @param {module:model/String} opts.region The region where the bucket resides Acceptable values: `US`, `EMEA` Default is `US` (default to US)
461-
* data is of type: {Object}
451+
* This endpoint returns status information about a resumable upload.
452+
* @param {String} bucketKey URL-encoded bucket key
453+
* @param {String} objectName URL-encoded object name
454+
* @param {String} sessionId Unique identifier of a session of a file being uploaded
462455
* @param {Object} oauth2client oauth2client for the call
463456
* @param {Object} credentials credentials for the call
464457
*/
465-
this.getSignedResource = function(id, opts, oauth2client, credentials) {
466-
opts = opts || {};
458+
this.getStatusBySessionId = function(bucketKey, objectName, sessionId, oauth2client, credentials) {
467459
var postBody = null;
468460

469-
// verify the required parameter 'id' is set
470-
if (id == undefined || id == null) {
471-
return Promise.reject("Missing the required parameter 'id' when calling getSignedResource");
461+
// verify the required parameter 'bucketKey' is set
462+
if (bucketKey == undefined || bucketKey == null) {
463+
return Promise.reject("Missing the required parameter 'bucketKey' when calling getStatusBySessionId");
464+
}
465+
466+
// verify the required parameter 'objectName' is set
467+
if (objectName == undefined || objectName == null) {
468+
return Promise.reject("Missing the required parameter 'objectName' when calling getStatusBySessionId");
469+
}
470+
471+
// verify the required parameter 'sessionId' is set
472+
if (sessionId == undefined || sessionId == null) {
473+
return Promise.reject("Missing the required parameter 'sessionId' when calling getStatusBySessionId");
472474
}
473475

474476

475477
var pathParams = {
476-
'id': id
478+
'bucketKey': bucketKey,
479+
'objectName': objectName,
480+
'sessionId': sessionId
477481
};
478482
var queryParams = {
479-
'region': opts['region']
480483
};
481484
var headerParams = {
482-
'Range': opts['range'],
483-
'If-None-Match': opts['ifNoneMatch'],
484-
'If-Modified-Since': opts['ifModifiedSince'],
485-
'Accept-Encoding': opts['acceptEncoding']
486485
};
487486
var formParams = {
488487
};
489488

490489
var contentTypes = ['application/json'];
491-
var accepts = ['application/octet-stream'];
492-
var returnType = Object;
490+
var accepts = ['application/vnd.api+json', 'application/json'];
491+
var returnType = null;
493492

494493
return this.apiClient.callApi(
495-
'/oss/v2/signedresources/{id}', 'GET',
494+
'/oss/v2/buckets/{bucketKey}/objects/{objectName}/status/{sessionId}', 'GET',
496495
pathParams, queryParams, headerParams, formParams, postBody,
497496
contentTypes, accepts, returnType, oauth2client, credentials
498497
);

src/auth/OAuth2ThreeLegged.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
module.exports = (function () {
2626
'use strict';
2727

28-
var OAuth2 = require('./OAuth2');
28+
var OAuth2 = require('./OAuth2'),
2929
var ApiClient = require('../ApiClient').instance;
3030

3131
/**
@@ -123,6 +123,7 @@ module.exports = (function () {
123123
reject(errResponse);
124124
});
125125
} else {
126+
ApiClient.debug('tokenUrl is not defined in the authentication object');
126127
reject(new Error('tokenUrl is not defined in the authentication object'));
127128
}
128129
});
@@ -155,14 +156,15 @@ module.exports = (function () {
155156
{expires_at: new Date(Date.now() + response.expires_in * 1000)});
156157
resolve(credentials);
157158
} else {
159+
ApiClient.debug('refreshToken error', response);
158160
reject(response);
159161
}
160162
}, function(errResponse){
161163
ApiClient.debug('refreshToken error', errResponse);
162164
reject(errResponse);
163165
});
164166
} else {
165-
ApiClient.debug('refreshToken error', errResponse);
167+
ApiClient.debug('No refresh token present');
166168
reject(new Error('No refresh token present'));
167169
}
168170
} else {

src/model/MetadataObject.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
module.exports = (function() {
2626
'use strict';
2727

28-
var ApiClient = require('../ApiClient');
28+
var ApiClient = require('../ApiClient'),
29+
MetadataObject = require('./MetadataObject');
2930

3031

3132

@@ -53,7 +54,7 @@ module.exports = (function() {
5354
obj['name'] = ApiClient.convertToType(data['name'], 'String');
5455
}
5556
if (data.hasOwnProperty('objects')) {
56-
obj['objects'] = ApiClient.convertToType(data['objects'], ['String']);
57+
obj['objects'] = ApiClient.convertToType(data['objects'], [MetadataObject]);
5758
}
5859
}
5960
return obj;
@@ -100,7 +101,7 @@ module.exports = (function() {
100101
exports.prototype['name'] = undefined;
101102
/**
102103
* Optional collection of “children” objects within the hierarchy
103-
* @member {Array.<String>} objects
104+
* @member {Array.<module:model/MetadataObject>} objects
104105
*/
105106
exports.prototype['objects'] = undefined;
106107

0 commit comments

Comments
 (0)