Skip to content

Commit d38b75c

Browse files
refactored bearer-token-type
1 parent cc99be5 commit d38b75c

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

lib/token-types/bearer-token-type.js

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,52 @@ const InvalidArgumentError = require('../errors/invalid-argument-error');
1010
* Constructor.
1111
*/
1212

13-
function BearerTokenType(accessToken, accessTokenLifetime, refreshToken, scope, customAttributes) {
14-
if (!accessToken) {
15-
throw new InvalidArgumentError('Missing parameter: `accessToken`');
16-
}
13+
class BearerTokenType {
14+
constructor(accessToken, accessTokenLifetime, refreshToken, scope, customAttributes) {
15+
if (!accessToken) {
16+
throw new InvalidArgumentError('Missing parameter: `accessToken`');
17+
}
1718

18-
this.accessToken = accessToken;
19-
this.accessTokenLifetime = accessTokenLifetime;
20-
this.refreshToken = refreshToken;
21-
this.scope = scope;
19+
this.accessToken = accessToken;
20+
this.accessTokenLifetime = accessTokenLifetime;
21+
this.refreshToken = refreshToken;
22+
this.scope = scope;
2223

23-
if (customAttributes) {
24-
this.customAttributes = customAttributes;
24+
if (customAttributes) {
25+
this.customAttributes = customAttributes;
26+
}
2527
}
26-
}
2728

28-
/**
29+
/**
2930
* Retrieve the value representation.
3031
*/
3132

32-
BearerTokenType.prototype.valueOf = function() {
33-
const object = {
34-
access_token: this.accessToken,
35-
token_type: 'Bearer'
36-
};
33+
valueOf () {
34+
const object = {
35+
access_token: this.accessToken,
36+
token_type: 'Bearer'
37+
};
3738

38-
if (this.accessTokenLifetime) {
39-
object.expires_in = this.accessTokenLifetime;
40-
}
39+
if (this.accessTokenLifetime) {
40+
object.expires_in = this.accessTokenLifetime;
41+
}
4142

42-
if (this.refreshToken) {
43-
object.refresh_token = this.refreshToken;
44-
}
43+
if (this.refreshToken) {
44+
object.refresh_token = this.refreshToken;
45+
}
4546

46-
if (this.scope) {
47-
object.scope = this.scope;
48-
}
47+
if (this.scope) {
48+
object.scope = this.scope;
49+
}
4950

50-
for (const key in this.customAttributes) {
51-
if ( Object.prototype.hasOwnProperty.call(this.customAttributes, key) ) {
52-
object[key] = this.customAttributes[key];
51+
for (const key in this.customAttributes) {
52+
if ( Object.prototype.hasOwnProperty.call(this.customAttributes, key) ) {
53+
object[key] = this.customAttributes[key];
54+
}
5355
}
56+
return object;
5457
}
55-
return object;
56-
};
58+
}
5759

5860
/**
5961
* Export constructor.

0 commit comments

Comments
 (0)