-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
36 lines (33 loc) · 1.07 KB
/
index.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
import APIHelper from './lib/APIHelper';
import OAuth2API from './lib/OAuth2API';
import OAuth2Token from './lib/OAuth2Token';
import OAuth2SessionStore from './lib/OAuth2SessionStore';
import Dispatcher from './lib/Dispatcher';
function _onValidToken(callback) {
OAuth2SessionStore.addValidTokenListener(callback);
}
function _onNoValidToken(callback) {
OAuth2SessionStore.addNoValidTokenListener(callback);
}
module.exports = {
OAuth2API: OAuth2API,
OAuth2Token: OAuth2Token,
authenticate: (username, password) => {
return OAuth2API.obtainAccessTokenWithCredentials(username, password);
},
reset: () => {
Dispatcher.dispatch({actionType: 'no_valid_token'});
},
onValidToken: _onValidToken,
onNoValidToken: _onNoValidToken,
initializeConfig: (client_id, client_secret, token_uri) => {
OAuth2API.init(client_id, client_secret, token_uri);
},
setEncodingType: (type) => {
OAuth2API.setEncodingType(type);
},
initializeSession: (token) => {
OAuth2SessionStore.initFromStorage(token);
},
authenticatedRequest: APIHelper.authenticatedRequest,
};