forked from t1msh/node-oauth20-provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
86 lines (78 loc) · 2.33 KB
/
code.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
var
error = require('./../error');
/**
* Typical code schema:
* userId: { type: "object", required: true },
* clientId: { type: "object", required: true },
* code: { type: "string", required: true, unique: true },
* scope: { type: "array", required: false,
* items: { type: "string", enum: ["possible", "scope", "values"] },
* }
*
* Primary key: code
* Unique key: userId + clientId pair should be unique
*/
/**
* Get userId parameter
*
* @param code {Object} Code object
*/
module.exports.getUserId = function(code) {
throw new error.serverError('Code model method "getUserId" is not implemented');
};
/**
* Get clientId parameter
*
* @param code {Object} Code object
*/
module.exports.getClientId = function(code) {
throw new error.serverError('Code model method "getClientId" is not implemented');
};
/**
* Get scope parameter
*
* @param code {Object} Code object
*/
module.exports.getScope = function(code) {
throw new error.serverError('Code model method "getScope" 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 code {String} Unique identifier
* @param cb {Function} Function callback ->(error, object)
*/
module.exports.fetchByCode = function(code, cb) {
throw new error.serverError('Code model method "fetchByCode" is not implemented');
};
/**
* Create code 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, code{String})
*/
module.exports.create = function(userId, clientId, scope, ttl, cb) {
throw new error.serverError('Code model method "create" is not implemented');
};
/**
* Remove code object (already used)
* Should be implemented with server logic
*
* @param code {String} Generated code string
* @param cb {Function} Function callback ->(error)
*/
module.exports.removeByCode = function(code, cb) {
throw new error.serverError('Code model method "removeByCode" is not implemented');
};
/**
* Access token time to live
* @type {Number} Seconds
*/
module.exports.ttl = 300;