Skip to content

Commit 6d28cee

Browse files
authored
Revert "Revert "Solves #133: add client_name, logo_uri and contacts fields to client …""
1 parent c528f3c commit 6d28cee

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,31 @@ and emits the following events:
155155
- `logout ()` when a user logs out
156156
- `session (session: Session | null)` when a user logs in or out
157157

158+
### Client registration
159+
160+
`SolidAuthClient` automatically registers your OIDC client application if it is
161+
unknown to the authorization server, following
162+
[the registration request spec](https://openid.net/specs/openid-connect-registration-1_0.html#RegistrationRequest).
163+
164+
You can specify some fields of this registration request by passing them to the
165+
`loginSession` parameter of `solid.auth.login`.
166+
167+
Supported fields are:
168+
169+
* `client_name` and internationalized variants (`clientName` property)
170+
* `contacts` (`contacts` property)
171+
* `logo_uri` (`contacts` property)
172+
173+
**Example**:
174+
175+
```js
176+
solid.auth.login(idp, {
177+
clientName: 'My Example',
178+
'clientName#ja-Jpan-JP': 'クライアント名',
179+
logoUri: 'https://client.example.org/logo.png',
180+
contacts: ['ve7jtb@example.org', 'mary@example.org']
181+
})
182+
````
158183

159184
## Advanced usage
160185

src/__test__/solid-auth-client.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,36 @@ describe('login', () => {
195195
expect(location.searchParams.get('scope')).toEqual('openid')
196196
expect(location.searchParams.get('client_id')).toEqual('the-client-id')
197197
})
198+
199+
it('performs the client registration the the correct provided registration parameters', async () => {
200+
let requestBody = {}
201+
nock('https://localhost/')
202+
.get('/.well-known/openid-configuration')
203+
.reply(200, oidcConfiguration)
204+
.get('/jwks')
205+
.reply(200, jwks)
206+
.post('/register', body => {
207+
requestBody = body
208+
return true
209+
})
210+
.reply(200, oidcRegistration)
211+
212+
await instance.login('https://localhost', {
213+
clientName: 'My Example',
214+
'clientName#ja-Jpan-JP': 'クライアント名',
215+
logoUri: 'https://client.example.org/logo.png',
216+
contacts: ['ve7jtb@example.org', 'mary@example.org']
217+
})
218+
219+
expect(requestBody).toMatchObject({
220+
client_name: 'My Example',
221+
'client_name#ja-Jpan-JP': 'クライアント名',
222+
contacts: ['ve7jtb@example.org', 'mary@example.org'],
223+
logo_uri: 'https://client.example.org/logo.png'
224+
})
225+
226+
expect.assertions(1)
227+
})
198228
})
199229
})
200230

src/solid-auth-client.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const globalFetch = fetch
1515

1616
export type loginOptions = {
1717
callbackUri: string,
18+
clientName?: string,
19+
contacts?: Array<string>,
20+
logoUri?: string,
1821
popupUri: string,
1922
storage: AsyncStorage
2023
}

src/webid-oidc.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,34 @@ async function storeRp(
125125
return rp
126126
}
127127

128-
function registerRp(
129-
idp: string,
130-
{ storage, callbackUri }: loginOptions
131-
): Promise<RelyingParty> {
128+
function registerRp(idp: string, opts: loginOptions): Promise<RelyingParty> {
129+
const { storage, callbackUri } = opts
132130
const responseType = 'id_token token'
131+
132+
const clientNameI18n = {}
133+
Object.entries(opts)
134+
.filter(([key, _]) => key.startsWith('clientName#'))
135+
.forEach(
136+
([key, value]) =>
137+
(clientNameI18n[key.replace('clientName#', 'client_name#')] = value)
138+
)
139+
140+
const supplementaryOptions = {
141+
logo_uri: opts.logoUri,
142+
contacts: opts.contacts,
143+
client_name: opts.clientName
144+
}
145+
133146
const registration = {
134147
issuer: idp,
135148
grant_types: ['implicit'],
136149
redirect_uris: [callbackUri],
137150
response_types: [responseType],
138-
scope: 'openid profile'
151+
scope: 'openid profile',
152+
...clientNameI18n,
153+
...supplementaryOptions
139154
}
155+
140156
const options = {
141157
defaults: {
142158
authenticate: {
@@ -146,6 +162,7 @@ function registerRp(
146162
},
147163
store: storage
148164
}
165+
149166
return RelyingParty.register(idp, registration, options)
150167
}
151168

0 commit comments

Comments
 (0)