-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
Copy pathAuthAdapter.js
118 lines (107 loc) · 4.2 KB
/
AuthAdapter.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
/*eslint no-unused-vars: "off"*/
/**
* @interface ParseAuthResponse
* @property {Boolean} [doNotSave] If true, Parse Server will not save provided authData.
* @property {Object} [response] If set, Parse Server will send the provided response to the client under authDataResponse
* @property {Object} [save] If set, Parse Server will save the object provided into this key, instead of client provided authData
*/
/**
* AuthPolicy
* default: can be combined with ONE additional auth provider if additional configured on user
* additional: could be only used with a default policy auth provider
* solo: Will ignore ALL additional providers if additional configured on user
* @typedef {"default" | "additional" | "solo"} AuthPolicy
*/
export class AuthAdapter {
constructor() {
/**
* Usage policy
* @type {AuthPolicy}
*/
if (!this.policy) {
this.policy = 'default';
}
}
/**
* @param appIds The specified app IDs in the configuration
* @param {Object} authData The client provided authData
* @param {Object} options additional adapter options
* @param {Parse.Cloud.TriggerRequest} request
* @returns {(Promise<undefined|void>|void|undefined)} resolves or returns if the applicationId is valid
*/
validateAppId(appIds, authData, options, request) {
return Promise.resolve({});
}
/**
* Legacy usage, if provided it will be triggered when authData related to this provider is touched (signup/update/login)
* otherwise you should implement validateSetup, validateLogin and validateUpdate
* @param {Object} authData The client provided authData
* @param {Parse.Cloud.TriggerRequest} request
* @param {Object} options additional adapter options
* @returns {Promise<ParseAuthResponse|void|undefined>}
*/
validateAuthData(authData, request, options) {
return Promise.resolve({});
}
/**
* Triggered when user provide for the first time this auth provider
* could be a register or the user adding a new auth service
* @param {Object} authData The client provided authData
* @param {Parse.Cloud.TriggerRequest} request
* @param {Object} options additional adapter options
* @returns {Promise<ParseAuthResponse|void|undefined>}
*/
validateSetUp(authData, req, options) {
return Promise.resolve({});
}
/**
* Triggered when user provide authData related to this provider
* The user is not logged in and has already set this provider before
* @param {Object} authData The client provided authData
* @param {Parse.Cloud.TriggerRequest} request
* @param {Object} options additional adapter options
* @returns {Promise<ParseAuthResponse|void|undefined>}
*/
validateLogin(authData, req, options) {
return Promise.resolve({});
}
/**
* Triggered when user provide authData related to this provider
* the user is logged in and has already set this provider before
* @param {Object} authData The client provided authData
* @param {Object} options additional adapter options
* @param {Parse.Cloud.TriggerRequest} request
* @returns {Promise<ParseAuthResponse|void|undefined>}
*/
validateUpdate(authData, req, options) {
return Promise.resolve({});
}
/**
* Triggered in pre authentication process if needed (like webauthn, SMS OTP)
* @param {Object} challengeData Data provided by the client
* @param {(Object|undefined)} authData Auth data provided by the client, can be used for validation
* @param {Object} options additional adapter options
* @param {Parse.Cloud.TriggerRequest} request
* @returns {Promise<Object>} A promise that resolves, resolved value will be added to challenge response under challenge key
*/
challenge(challengeData, authData, options, request) {
return Promise.resolve({});
}
/**
* Triggered when auth data is fetched
* @param {Object} authData authData
* @param {Object} options additional adapter options
* @returns {Promise<Object>} Any overrides required to authData
*/
afterFind(authData, options) {
return Promise.resolve({});
}
/**
* Triggered when the adapter is first attached to Parse Server
* @param {Object} options Adapter Options
*/
validateOptions(options) {
/* */
}
}
export default AuthAdapter;