-
Notifications
You must be signed in to change notification settings - Fork 145
/
accessToken.js
89 lines (81 loc) · 2.67 KB
/
accessToken.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
var
error = require('./../error');
/**
* Typical accessToken schema:
* userId: { type: "object", required: true },
* clientId: { type: "object", required: true },
* token: { type: "string", required: true, unique: true },
* scope: { type: "array", required: false,
* items: { type: "string", enum: ["possible", "scope", "values"] },
* }
*
* Primary key: token
* @todo: CHECK IT, seems no need to be unique
* Unique key: userId + clientId pair should be unique
*/
/**
* Gets token of the accessToken
*
* @param accessToken {Object} accessToken object
*/
module.exports.getToken = function(accessToken) {
throw new error.serverError('accessToken model method "getToken" is not implemented');
};
/**
* Fetches accessToken object by token
* Should be implemented with server logic
*
* Remember to check ttl if ttl is saved in object (if ttl is not valid return null)
*
* @param token {String} Unique identifier
* @param cb {Function} Function callback ->(error, object)
*/
module.exports.fetchByToken = function(token, cb) {
throw new error.serverError('accessToken model method "fetchByToken" is not implemented');
};
/**
* Fetches accessToken object by userId-clientId pair
* Should be implemented with server logic
*
* @param userId {String} Unique identifier
* @param clientId {String} Unique identifier
* @param cb {Function} Function callback ->(error, object)
*/
module.exports.fetchByUserIdClientId = function(userId, clientId, cb) {
throw new error.serverError('accessToken model method "fetchByUserIdClientId" is not implemented');
};
/**
* Check if accessToken is valid and not expired
*
* @param accessToken
*/
module.exports.checkTTL = function(accessToken) {
throw new error.serverError('accessToken model method "checkTTL" is not implemented');
};
/**
* Get TTL from accessToken to deliver it to the client
* when this does the refresh token flow and the access token is not expired
*
* @param accessToken
*/
module.exports.getTTL = function(accessToken, cb) {
throw new error.serverError('accessToken model method "getTTL" is not implemented');
};
/**
* Create accessToken object (generate + save)
* Should be implemented with server logic
*
* @param userId {String} Unique identifier
* @param clientId {String} Unique identifier
* @param scope {Array|null} Scope values
* @param ttl {Number} Time to live in seconds
* @param cb {Function} Function callback ->(error, token{String})
*/
module.exports.create = function(userId, clientId, scope, ttl, cb) {
throw new error.serverError('accessToken model method "create" is not implemented');
};
/**
* Access token time to live
* @type {Number} Seconds
*/
module.exports.ttl = 3600;