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
37 lines (30 loc) · 1.25 KB
/
UserInfoService.js
File metadata and controls
37 lines (30 loc) · 1.25 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
36
37
// 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 default class UserInfoService {
constructor(settings, JsonServiceCtor = JsonService, MetadataServiceCtor = MetadataService) {
if (!settings) {
Log.error("No settings passed to UserInfoService");
throw new Error("settings");
}
this._settings = settings;
this._jsonService = new JsonServiceCtor();
this._metadataService = new MetadataServiceCtor(this._settings);
}
getClaims(token) {
Log.debug("UserInfoService.getClaims");
if (!token) {
Log.error("No token passed");
return Promise.reject(new Error("A token is required"));
}
return this._metadataService.getUserInfoEndpoint().then(url => {
Log.debug("received userinfo url", url);
return this._jsonService.getJson(url, token).then(claims => {
Log.debug("claims received", claims);
return claims;
});
});
}
}