Skip to content

Commit

Permalink
Merge pull request #134 from christophehenry/133
Browse files Browse the repository at this point in the history
Solves #133: add client_name, logo_uri and contacts fields to client …
  • Loading branch information
jaxoncreed committed Oct 21, 2019
2 parents 54d729f + 1e589f4 commit 2009db9
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
25 changes: 25 additions & 0 deletions README.md
Expand Up @@ -155,6 +155,31 @@ and emits the following events:
- `logout ()` when a user logs out
- `session (session: Session | null)` when a user logs in or out

### Client registration

`SolidAuthClient` automatically registers your OIDC client application if it is
unknown to the authorization server, following
[the registration request spec](https://openid.net/specs/openid-connect-registration-1_0.html#RegistrationRequest).

You can specify some fields of this registration request by passing them to the
`loginSession` parameter of `solid.auth.login`.

Supported fields are:

* `client_name` and internationalized variants (`clientName` property)
* `contacts` (`contacts` property)
* `logo_uri` (`contacts` property)

**Example**:

```js
solid.auth.login(idp, {
clientName: 'My Example',
'clientName#ja-Jpan-JP': 'クライアント名',
logoUri: 'https://client.example.org/logo.png',
contacts: ['ve7jtb@example.org', 'mary@example.org']
})
````

## Advanced usage

Expand Down
30 changes: 30 additions & 0 deletions src/__test__/solid-auth-client.spec.js
Expand Up @@ -195,6 +195,36 @@ describe('login', () => {
expect(location.searchParams.get('scope')).toEqual('openid')
expect(location.searchParams.get('client_id')).toEqual('the-client-id')
})

it('performs the client registration the the correct provided registration parameters', async () => {
let requestBody = {}
nock('https://localhost/')
.get('/.well-known/openid-configuration')
.reply(200, oidcConfiguration)
.get('/jwks')
.reply(200, jwks)
.post('/register', body => {
requestBody = body
return true
})
.reply(200, oidcRegistration)

await instance.login('https://localhost', {
clientName: 'My Example',
'clientName#ja-Jpan-JP': 'クライアント名',
logoUri: 'https://client.example.org/logo.png',
contacts: ['ve7jtb@example.org', 'mary@example.org']
})

expect(requestBody).toMatchObject({
client_name: 'My Example',
'client_name#ja-Jpan-JP': 'クライアント名',
contacts: ['ve7jtb@example.org', 'mary@example.org'],
logo_uri: 'https://client.example.org/logo.png'
})

expect.assertions(1)
})
})
})

Expand Down
3 changes: 3 additions & 0 deletions src/solid-auth-client.js
Expand Up @@ -15,6 +15,9 @@ const globalFetch = fetch

export type loginOptions = {
callbackUri: string,
clientName?: string,
contacts?: Array<string>,
logoUri?: string,
popupUri: string,
storage: AsyncStorage
}
Expand Down
27 changes: 22 additions & 5 deletions src/webid-oidc.js
Expand Up @@ -125,18 +125,34 @@ async function storeRp(
return rp
}

function registerRp(
idp: string,
{ storage, callbackUri }: loginOptions
): Promise<RelyingParty> {
function registerRp(idp: string, opts: loginOptions): Promise<RelyingParty> {
const { storage, callbackUri } = opts
const responseType = 'id_token token'

const clientNameI18n = {}
Object.entries(opts)
.filter(([key, _]) => key.startsWith('clientName#'))
.forEach(
([key, value]) =>
(clientNameI18n[key.replace('clientName#', 'client_name#')] = value)
)

const supplementaryOptions = {
logo_uri: opts.logoUri,
contacts: opts.contacts,
client_name: opts.clientName
}

const registration = {
issuer: idp,
grant_types: ['implicit'],
redirect_uris: [callbackUri],
response_types: [responseType],
scope: 'openid profile'
scope: 'openid profile',
...clientNameI18n,
...supplementaryOptions
}

const options = {
defaults: {
authenticate: {
Expand All @@ -146,6 +162,7 @@ function registerRp(
},
store: storage
}

return RelyingParty.register(idp, registration, options)
}

Expand Down

0 comments on commit 2009db9

Please sign in to comment.