Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Add methods for getting token infos #1126

Merged
merged 3 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-token-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Add token info endpoint support

We've added support for the new token info endpoint.

https://github.com/owncloud/owncloud-sdk/pull/1126
https://github.com/owncloud/web/issues/7304
9 changes: 6 additions & 3 deletions src/helperFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class helpers {
this.OCS_BASEPATH = 'ocs/v1.php/'
this.OCS_BASEPATH_V2 = 'ocs/v2.php/'
this.OCS_SERVICE_SHARE = 'apps/files_sharing/api/v1'
this.OCS_PROTECTED_TOKEN_INFO = 'tokeninfo/protected'
this.OCS_UNPROTECTED_TOKEN_INFO = 'tokeninfo/unprotected'
this.OCS_SERVICE_CLOUD = 'cloud'

// constants from lib/public/constants.php
Expand Down Expand Up @@ -206,22 +208,23 @@ class helpers {
* @param {string} service service (cloud, privatedata etc.)
* @param {string} action action (apps?filter=enabled, capabilities etc.)
* @param {string} [data] formData for POST and PUT requests
* @param {boolean} authRequired use an auth header for the request
* @returns {Promise.<data>} object: {response: response, body: request body}
* @returns {Promise.<error>} string: error message, if any.
*/
_makeOCSrequest (method, service, action, data) {
_makeOCSrequest (method, service, action, data, authRequired = true) {
const self = this

if (!self.instance) {
return Promise.reject('Please specify a server URL first')
}

if (!self._authHeader) {
if (authRequired && !self._authHeader) {
return Promise.reject('Please specify an authorization first.')
}

// Set the headers
const headers = this.buildHeaders()
const headers = this.buildHeaders(authRequired)
let slash = ''

if (service) {
Expand Down
36 changes: 36 additions & 0 deletions src/shareManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,42 @@ class Shares {
})
}

/**
* Gets the protected token info for a public link
* @param {string} token token of the public link
* @returns {Promise.<ShareInfo>} instance of class ShareInfo
* @returns {Promise.<error>} string: error message, if any.
*/
getProtectedTokenInfo (token) {
return new Promise((resolve, reject) => {
this.helpers._makeOCSrequest('GET', this.helpers.OCS_SERVICE_SHARE, this.helpers.OCS_PROTECTED_TOKEN_INFO + '/' + token)
.then(data => {
const tokenInfo = data.data.ocs.data
resolve(tokenInfo)
}).catch(error => {
reject(error)
})
})
}

/**
* Gets the unprotected token info for a public link
* @param {string} token token of the public link
* @returns {Promise.<ShareInfo>} instance of class ShareInfo
* @returns {Promise.<error>} string: error message, if any.
*/
getUnprotectedTokenInfo (token) {
return new Promise((resolve, reject) => {
this.helpers._makeOCSrequest('GET', this.helpers.OCS_SERVICE_SHARE, this.helpers.OCS_UNPROTECTED_TOKEN_INFO + '/' + token, null, false)
.then(data => {
const tokenInfo = data.data.ocs.data
resolve(tokenInfo)
}).catch(error => {
reject(error)
})
})
}

/**
* @param {object} optionalParams
* @returns {object}
Expand Down