forked from DuendeArchive/identity-model-oidc-client-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInfoService.js
More file actions
35 lines (29 loc) · 1.28 KB
/
Copy pathUserInfoService.js
File metadata and controls
35 lines (29 loc) · 1.28 KB
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
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
import { JsonService } from './JsonService';
import { MetadataService } from './MetadataService';
import { Log } from './Log';
export class UserInfoService {
constructor(settings, JsonServiceCtor = JsonService, MetadataServiceCtor = MetadataService) {
if (!settings) {
Log.error("UserInfoService.ctor: No settings passed");
throw new Error("settings");
}
this._settings = settings;
this._jsonService = new JsonServiceCtor();
this._metadataService = new MetadataServiceCtor(this._settings);
}
getClaims(token) {
if (!token) {
Log.error("UserInfoService.getClaims: No token passed");
return Promise.reject(new Error("A token is required"));
}
return this._metadataService.getUserInfoEndpoint().then(url => {
Log.debug("UserInfoService.getClaims: received userinfo url", url);
return this._jsonService.getJson(url, token).then(claims => {
Log.debug("UserInfoService.getClaims: claims received", claims);
return claims;
});
});
}
}