-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccount.js
73 lines (67 loc) · 2.77 KB
/
account.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
const store = new Map();
const logins = new Map();
const uuid = require('uuid/v4');
const issuer = process.env.ISSUER || 'http://localhost:9090';
class Account {
constructor(id, principalName, email, password, creationTime, identifier = uuid()) {
this.accountId = id;
this.accountUuid = identifier;
this.principalName = principalName;
this.email = email;
this.creationTime = creationTime;
this.lastLoginTime = creationTime;
store.set(this.accountId, this);
logins.set(this.accountId + "-" + password, this)
}
/**
* @param use - can either be "id_token" or "userinfo", depending on
* where the specific claims are intended to be put in.
* @param scope - the intended scope, while oidc-provider will mask
* claims depending on the scope automatically you might want to skip
* loading some claims from external resources etc. based on this detail
* or not return them in id tokens but only userinfo and so on.
*/
async claims(use, scope) { // eslint-disable-line no-unused-vars
return {
sub: this.accountId,
pid: this.accountUuid,
email: this.email,
email_verified: true,
name: this.principalName,
locale: 'en',
"bas:roles": [ "Administrator", "User" ],
jti: this.principalName + ':' + this.accountUuid,
"bas:userInfoVersion": "1.1",
"bas:transition:lastLoginTime": this.lastLoginTime,
"bas:transition:credentialCreatedDate": this.creationTime,
"bas:gg-legacy:registrationCategory": "Agent",
"bas:gg-legacy:agentId": "An agent ID",
"bas:gg-legacy:agentCode": "RANDOM12345",
"bas:gg-legacy:agentFriendlyName": "Test Friendly Name",
"bas:groupId": "9F9416A1-3977-4FC1-AB5E-0352417FD5A8",
"profile": issuer + "/account/your-details/ayp/tbf/" + this.accountUuid,
"bas:groupProfile": "somelink",
"bas:gg-legacy:description": "This is the description for the test user name"
};
}
static findByLogin(id, password) {
let account = logins.get(id + "-" + password);
if (account != null) {
account.lastLoginTime = Date.now();
store.set(account.accountId, account);
logins.set(account.accountId + "-" + password, account);
}
return Promise.resolve(account);
}
static async findById(ctx, id, token) { // eslint-disable-line no-unused-vars
// token is a reference to the token used for which a given account is being loaded,
// it is undefined in scenarios where account claims are returned from authorization endpoint
// ctx is the koa request context
return store.get(parseInt(id));
}
static async findByUuid(uuid) {
const arr = Array.from(store.values());
return arr.filter((e) => e.accountUuid === uuid)[0];
}
}
module.exports = Account;