Currently, if one wanted to do a dynamic client registration, it would look like this:
const settings = new OidcClientSettingsStore({
authority,
redirect_uri,
client_id: '', // Not known yet, but this is needed to make the type checker happy
});
const metadataService = new MetadataService(settings);
// Fetch the metadata and signing keys here, so that we can pass them in the OidcClient later and avoid loading twice
const metadata = await metadataService.getMetadata();
const signingKeys = (await metadataService.getSigningKeys()) ?? undefined;
// Check that there is a registration_endpoint advertised by the server
const registrationEndpoint = metadata['registration_endpoint'];
if (!registrationEndpoint) {
throw new Error('Issuer does not support dynamic client registration');
}
// Do the client registration
const response = await fetch(registrationEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
client_name: 'Some client name',
client_uri: window.location.origin,
contacts: ['a-contact@email'],
application_type: 'web',
redirect_uris: [redirect_uri],
grant_types: ['authorization_code', 'refresh_token'],
response_types: ['code'],
token_endpoint_auth_method: 'none',
}),
});
const registration = await response.json();
// Extract the returned client_id
const client_id = response.body['client_id'];
if (!client_id) {
throw new Error('Invalid client ID');
}
// And construct an OidcClient with it
return new OidcClient({
authority,
client_id,
scope: 'openid',
redirect_uri,
response_type: 'code',
response_mode: 'fragment',
signingKeys,
metadata,
});
There should be a better, more ergonomic way to do, like a UnregisteredOidcClient, with a register method which would do a dynamic client registration and return an OidcClient
There is no builtin way to do client registration as defined in OpenID Connect Dynamic Client Registration 1.0.
Currently, if one wanted to do a dynamic client registration, it would look like this:
There should be a better, more ergonomic way to do, like a
UnregisteredOidcClient
, with aregister
method which would do a dynamic client registration and return anOidcClient