Skip to content

Commit 43eb95d

Browse files
MultiRpClient - initial commit, clientRegistrationConfig()
1 parent b9f211e commit 43eb95d

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict'
2+
3+
module.exports = {
4+
'ClientStore': require('./store'),
5+
'MultiRpClient': require('./multi-rp-client')
6+
}

src/multi-rp-client.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict'
2+
const ClientStore = require('./store')
3+
4+
class MultiRpClient {
5+
constructor (options = {}) {
6+
this.store = options.store || new ClientStore()
7+
this.localConfig = options.localConfig || {}
8+
}
9+
10+
/**
11+
* @method clientRegistrationConfig
12+
* @static
13+
* @param issuer {String} URL of the OIDC Provider / issuer.
14+
* @param redirectUris {Array<String>} List of allowed URIs to which the
15+
* provider will redirect users after login etc.
16+
* @param [postLogoutUris] {Array<String>}
17+
* @return {Object} OIDC Client registration config options
18+
*/
19+
static clientRegistrationConfig (issuer, redirectUris, postLogoutUris) {
20+
let clientName = `Solid OIDC Client for ${issuer}`
21+
let config = {
22+
client_name: clientName,
23+
// client_uri: 'https://github.com/solid/node-solid-server',
24+
// logo_uri: 'solid logo',
25+
// post_logout_redirect_uris: [ '...' ],
26+
default_max_age: 86400, // one day in seconds
27+
// trusted: true,
28+
// Type of token requests that this client is gonna make
29+
grant_types: ['authorization_code', 'implicit',
30+
'refresh_token', 'client_credentials'],
31+
issuer: issuer,
32+
redirect_uris: redirectUris,
33+
response_types: ['code', 'id_token token', 'code id_token token'],
34+
scope: 'openid profile'
35+
}
36+
if (postLogoutUris) {
37+
config.post_logout_redirect_uris = postLogoutUris
38+
}
39+
return config
40+
}
41+
42+
get localIssuer () {
43+
return this.localConfig.issuer
44+
}
45+
}
46+
module.exports = MultiRpClient

test/unit/client-store-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const test = require('tape')
4-
const ClientStore = require('../../src/store')
4+
const { ClientStore } = require('../../src/index')
55

66

77
test('client store and retrieve test', t => {

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict'
2+
3+
const test = require('tape')
4+
const { ClientStore, MultiRpClient } = require('../../src/index')
5+
6+
test('MultiRpClient constructor test', t => {
7+
let store = new ClientStore()
8+
let localIssuer = 'https://oidc.example.com'
9+
let localConfig = {
10+
issuer: localIssuer
11+
}
12+
let options = { store, localConfig }
13+
let multiClient = new MultiRpClient(options)
14+
t.equal(multiClient.store, store)
15+
t.equal(multiClient.localConfig, localConfig)
16+
t.equal(multiClient.localIssuer, localIssuer)
17+
t.end()
18+
})
19+
20+
test('MultiRpClient.clientRegistrationConfig() test', t => {
21+
let issuer = 'https://oidc.example.com'
22+
let redirectUris = [ 'https://localhost:8443/callback' ]
23+
let postLogoutUris = [ 'https://localhost:8443/signed_out.html' ]
24+
let regConfig =
25+
MultiRpClient.clientRegistrationConfig(issuer, redirectUris, postLogoutUris)
26+
t.ok(regConfig.client_name)
27+
// Check for other claims here...
28+
t.equal(regConfig.issuer, issuer)
29+
t.equal(regConfig.redirect_uris, redirectUris)
30+
t.equal(regConfig.post_logout_redirect_uris, postLogoutUris)
31+
t.end()
32+
})

0 commit comments

Comments
 (0)