Skip to content

Commit 2d0872a

Browse files
Add more error logging, bump oidc-rp dep to rc-002
1 parent a2dfcf8 commit 2d0872a

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"homepage": "https://github.com/solid/solid-multi-rp-client",
4040
"dependencies": {
4141
"kvplus-files": "0.0.4",
42-
"oidc-rp": "git://github.com/anvilresearch/oidc-rp.git#rc-001"
42+
"oidc-rp": "git://github.com/anvilresearch/oidc-rp.git#rc-002"
4343
},
4444
"devDependencies": {
4545
"sinon": "^1.17.7",

src/client-store.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ module.exports = class OIDCClientStore {
2323
})
2424

2525
this.backend.serialize = (client) => { return client.serialize() }
26-
this.backend.deserialize = (data) => { return JSON.parse(data) }
26+
this.backend.deserialize = (data) => {
27+
let result
28+
try {
29+
result = JSON.parse(data)
30+
} catch (error) {
31+
console.log(`Error parsing JSON at '${this.backend.path}', ` +
32+
`collection '${this.collectionName}': `, error)
33+
}
34+
return result
35+
}
2736
}
2837

2938
del (client) {
@@ -64,5 +73,9 @@ module.exports = class OIDCClientStore {
6473
}
6574
return result
6675
})
76+
.catch(error => {
77+
console.error('Error in clientStore.get() while loading a RelyingParty:',
78+
error)
79+
})
6780
}
6881
}

src/multi-rp-client.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,15 @@ class MultiRpClient {
7272
* @returns {Promise<string>}
7373
*/
7474
authUrlForIssuer (issuer, session, workflow = 'code') {
75+
let debug = this.debug
76+
7577
return this.clientForIssuer(issuer)
7678
.then((client) => {
7779
return this.authUrl(client, session, workflow)
7880
})
81+
.catch(error => {
82+
debug('Error in authUrlForIssuer(): ', error)
83+
})
7984
}
8085

8186
/**
@@ -87,18 +92,24 @@ class MultiRpClient {
8792
let debug = this.debug
8893
return this.loadClient(issuerUri)
8994
.then(client => {
90-
debug('Client fetched for issuer.')
9195
if (client) {
96+
debug(`Client fetched for issuer ${issuerUri}`)
9297
return client
9398
}
94-
debug('Client not present, initializing new client.')
99+
debug(`Client not present for issuer ${issuerUri}, initializing new client`)
95100
// client not already in store, create and register it
96101
let registrationConfig = this.registrationConfigFor(issuerUri)
97102
return this.registerClient(registrationConfig)
103+
.catch(error => {
104+
debug('Error registering a new client: ', error)
105+
})
98106
.then(registeredClient => {
99107
// Store and return the newly registered client
100108
return this.persistClient(registeredClient)
101109
})
110+
.catch(error => {
111+
debug('Error persisting registered client: ', error)
112+
})
102113
})
103114
}
104115

@@ -128,7 +139,10 @@ class MultiRpClient {
128139
* @method redirectUriForIssuer
129140
* @param issuer {string} Issuer URI
130141
* @param baseUri {string}
131-
* @returns {string}
142+
*
143+
* @throws {Error} If baseUri is missing.
144+
*
145+
* @return {string}
132146
*/
133147
redirectUriForIssuer (issuerUri, baseUri = this.localConfig.redirect_uri) {
134148
if (!baseUri) {
@@ -141,6 +155,8 @@ class MultiRpClient {
141155
registerClient (config) {
142156
// let debug = this.debug
143157
// debug('new OIDCRelyingParty.register()', config)
158+
this.debug('Registering new client for issuer ', config.issuer)
159+
144160
return OIDCRelyingParty.register(config.issuer, config, {})
145161
}
146162

@@ -150,6 +166,7 @@ class MultiRpClient {
150166
*/
151167
registrationConfigFor (issuer, config = {}) {
152168
let redirectUri = config.redirect_uri || this.redirectUriForIssuer(issuer)
169+
153170
let defaultClientName = `Solid OIDC RP for ${issuer}`
154171

155172
config.client_name = config.client_name || defaultClientName

0 commit comments

Comments
 (0)