Skip to content

Commit 76aec13

Browse files
Add clientForIssuer() test
1 parent 43eb95d commit 76aec13

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
"url": "https://github.com/solid/solid-multi-rp-client/issues"
3838
},
3939
"homepage": "https://github.com/solid/solid-multi-rp-client",
40-
"dependencies": {},
40+
"dependencies": {
41+
"anvil-connect-express": "^0.3.2"
42+
},
4143
"devDependencies": {
4244
"standard": "^5.4.1",
4345
"tape": "^4.6.2"

src/multi-rp-client.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class MultiRpClient {
55
constructor (options = {}) {
66
this.store = options.store || new ClientStore()
77
this.localConfig = options.localConfig || {}
8+
this.debug = options.debug || console.log.bind(console)
89
}
910

1011
/**
@@ -39,6 +40,29 @@ class MultiRpClient {
3940
return config
4041
}
4142

43+
clientForIssuer (issuer) {
44+
let debug = this.debug
45+
// var trustedClient = this.trustedClient.client
46+
// var baseRedirectUri = trustedClient.redirect_uri
47+
// var isTrustedClient = issuer === trustedClient.issuer
48+
return this.store.get(issuer)
49+
.then((client) => {
50+
debug('Client fetched for issuer.')
51+
if (client) {
52+
return client
53+
}
54+
debug('Client not present, initializing new client.')
55+
// client not already in store, create and register it
56+
// let redirectUri = this.redirectUriForIssuer(issuer,
57+
// baseRedirectUri, isTrustedClient)
58+
// let clientConfig = {
59+
// issuer: issuer,
60+
// redirect_uri: redirectUri
61+
// }
62+
// return this.initClient(clientConfig, isTrustedClient)
63+
})
64+
}
65+
4266
get localIssuer () {
4367
return this.localConfig.issuer
4468
}

test/unit/multi-rp-client-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const test = require('tape')
4+
const OIDCExpressClient = require('anvil-connect-express')
45
const { ClientStore, MultiRpClient } = require('../../src/index')
56

67
test('MultiRpClient constructor test', t => {
@@ -30,3 +31,21 @@ test('MultiRpClient.clientRegistrationConfig() test', t => {
3031
t.equal(regConfig.post_logout_redirect_uris, postLogoutUris)
3132
t.end()
3233
})
34+
35+
test('MultiRpClient.clientForIssuer() - client exists in store test', t => {
36+
let issuer = 'https://oidc.example.com'
37+
let store = new ClientStore()
38+
let expressClient = new OIDCExpressClient({ issuer })
39+
let multiClient
40+
store.put(expressClient)
41+
.then(() => {
42+
multiClient = new MultiRpClient({ store })
43+
return multiClient.clientForIssuer(issuer)
44+
})
45+
.then(retrievedClient => {
46+
t.equal(retrievedClient, expressClient,
47+
'If client exists in store, clientForIssuer() should retrieve it')
48+
t.end()
49+
})
50+
.catch(err => { t.fail(err) })
51+
})

0 commit comments

Comments
 (0)