forked from MauriceButler/simple-oauth-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (32 loc) · 1.33 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
37
38
39
40
var lib = require('./lib');
function AuthServer(clientService, tokenService, authorizationService, membershipService, expiresIn, supportedScopes) {
var authServer = this;
if(!(authServer instanceof AuthServer)) {
return new AuthServer(clientService, tokenService, authorizationService, membershipService, expiresIn, supportedScopes);
}
authServer.clientService = clientService;
authServer.tokenService = tokenService;
authServer.authorizationService = authorizationService;
authServer.membershipService = membershipService;
authServer.expiresIn = expiresIn || 3600;
authServer.supportedScopes = supportedScopes ? supportedScopes : [];
}
AuthServer.prototype.getExpiresDate = function () {
return new Date(Date.now() + this.expiresIn * 60000);
};
AuthServer.prototype.isSupportedScope = function (scopes) {
if(!Array.isArray(scopes)){
scopes = [scopes];
}
for(var i = 0; i < scopes.length; i++){
if(!~this.supportedScopes.indexOf(scopes[i])){
return false;
}
}
return true;
};
AuthServer.prototype.authorizeRequest = lib.authorizeRequest;
AuthServer.prototype.getTokenData = lib.getTokenData;
AuthServer.prototype.grantAccessToken = lib.grantAccessToken;
AuthServer.prototype.validateAccessToken = lib.validateAccessToken;
module.exports = AuthServer;