-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathProvider.js
125 lines (111 loc) · 3.24 KB
/
Provider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const { MAX_AGE_24H } = require('../helpers/jwt')
/**
* Provider interface defines the specifications of any provider implementation
*/
class Provider {
/**
*
* @param {{providerName: string, allowLocalUrls: boolean, providerGrantConfig?: object, secret: string}} options
*/
constructor ({ allowLocalUrls, providerGrantConfig, secret }) {
// Some providers might need cookie auth for the thumbnails fetched via companion
this.needsCookieAuth = false
this.allowLocalUrls = allowLocalUrls
this.providerGrantConfig = providerGrantConfig
this.secret = secret
return this
}
/**
* config to extend the grant config
*/
static getExtraGrantConfig () {
return {}
}
/**
* list the files and folders in the provider account
*
* @param {object} options
* @returns {Promise}
*/
// eslint-disable-next-line class-methods-use-this,no-unused-vars
async list (options) {
throw new Error('method not implemented')
}
/**
* download a certain file from the provider account
*
* @param {object} options
* @returns {Promise}
*/
// eslint-disable-next-line class-methods-use-this,no-unused-vars
async download (options) {
throw new Error('method not implemented')
}
/**
* return a thumbnail for a provider file
*
* @param {object} options
* @returns {Promise}
*/
// eslint-disable-next-line class-methods-use-this,no-unused-vars
async thumbnail (options) {
throw new Error('method not implemented')
}
/**
* get the size of a certain file in the provider account
*
* @param {object} options
* @returns {Promise}
*/
// eslint-disable-next-line class-methods-use-this,no-unused-vars
async size (options) {
throw new Error('method not implemented')
}
/**
* handle deauthorization notification from oauth providers
*
* @param {object} options
* @returns {Promise}
*/
// eslint-disable-next-line class-methods-use-this,no-unused-vars
async deauthorizationCallback (options) {
// @todo consider doing something like throw new NotImplementedError() instead
throw new Error('method not implemented')
}
/**
* Generate a new access token based on the refresh token
*/
// eslint-disable-next-line class-methods-use-this,no-unused-vars
async refreshToken (options) {
throw new Error('method not implemented')
}
/**
* @param {any} param0
* @returns {Promise<any>}
*/
// eslint-disable-next-line no-unused-vars, class-methods-use-this
async simpleAuth ({ requestBody }) {
throw new Error('method not implemented')
}
/**
* Name of the OAuth provider (passed to Grant). Return empty string if no OAuth provider is needed.
*
* @returns {string}
*/
static get oauthProvider () {
return undefined
}
// eslint-disable-next-line no-unused-vars
static grantDynamicToUserSession ({ grantDynamic }) {
return {}
}
static get hasSimpleAuth () {
return false
}
static get authStateExpiry () {
return MAX_AGE_24H
}
}
module.exports = Provider
// OAuth providers are those that have an `oauthProvider` set. It means they require OAuth authentication to work
module.exports.isOAuthProvider = (oauthProvider) => typeof oauthProvider === 'string' && oauthProvider.length > 0