Setting credentials for a Maven repository given Provider

Suppose I am configuring a repository via a RepositoryHandler that requires password credentials - something like

repositories {
    maven {
        name = "foobar"
        url = URI("...")

Now, suppose I have a Provider<PasswordCredential> that I want to use as the credentials for this repository. For example:

val credential = project.providers.credentials(, "baz")

How would I associate the credential to the repository? Looking at the API docs for AuthenticationSupported, I cannot do so without using a get() call of some kind, which doesn’t seem like a nice state of affairs, and I can’t use credentials(, since that would use the foobarUsername property and not the bazUsername property like intended.

(Aside: Sometimes, I feel that registering a repository should be more NamedDomainObjectContainer-like in its approach…)