How to have multiple dynamic redirect uri for oAuth2 authentication

Hi,
I am created a Tauri Desktop Application along with JMIX Rest API. As i want to do PKCE oAuth2 authentication with JMIX2. So, i want to have multiple redirect URI. As i see we can add multiple URI in the configuration,

spring.security.oauth2.authorizationserver.client.myclient.registration.redirect-uris=http://127.0.0.1:9133/callback

But i will have thousands of dynamic Redirect URIs (each for a desktop application instance).

So, How to configure and use the Redirect URI from the oAuth2 request as like in the oauthdebugger example.

image

It redirect only if we specify the URI in the spring configuration file(application.properties). If this Redirect URI is not specified in the spring configuration, i am getting BadRequest error with status=400 while doing authentication.

Thanks in advance.

Hi,

The client registration functionality is taken from the Spring Authorization Server framework.

It looks like you cannot change the list of redirect URIs once the client is registered in the application.

However, in case you can somehow evaluate all possible redirect URIs when starting your Jmix application, then you may consider registering the client not using application properties, but by defining the RegisteredClientRepository bean, see [this example] in Spring Authorization Server documentation.

You can also register multiple clients dynamically. Each client will have its own redirect URI. Something like this should work:


    @Autowired
    private RegisteredClientRepository registeredClientRepository;

    RegisteredClient newClient = RegisteredClient.withId("newclient")
                    .clientId("newclient")
                    .clientSecret("newsecret")
                    .redirectUri("https://your-new-uri.com")
                    .authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
                    .build();
    registeredClientRepository.save(newClient);

You may also look at this How-to guide.