forked from node-oauth/node-oauth2-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbearer-token-type.js
64 lines (50 loc) · 1.26 KB
/
bearer-token-type.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
'use strict';
/**
* Module dependencies.
*/
const InvalidArgumentError = require('../errors/invalid-argument-error');
/**
* Constructor.
*/
class BearerTokenType {
constructor(accessToken, accessTokenLifetime, refreshToken, scope, customAttributes) {
if (!accessToken) {
throw new InvalidArgumentError('Missing parameter: `accessToken`');
}
this.accessToken = accessToken;
this.accessTokenLifetime = accessTokenLifetime;
this.refreshToken = refreshToken;
this.scope = scope;
if (customAttributes) {
this.customAttributes = customAttributes;
}
}
/**
* Retrieve the value representation.
*/
valueOf () {
const object = {
access_token: this.accessToken,
token_type: 'Bearer'
};
if (this.accessTokenLifetime) {
object.expires_in = this.accessTokenLifetime;
}
if (this.refreshToken) {
object.refresh_token = this.refreshToken;
}
if (this.scope) {
object.scope = this.scope;
}
for (const key in this.customAttributes) {
if ( Object.prototype.hasOwnProperty.call(this.customAttributes, key) ) {
object[key] = this.customAttributes[key];
}
}
return object;
}
}
/**
* Export constructor.
*/
module.exports = BearerTokenType;