private Object buildManagedIdentityCredential()

in azure-functions-java-sdktypes/src/main/java/com/microsoft/azure/functions/sdktype/blob/BlobContainerHydrator.java [92:108]


    private Object buildManagedIdentityCredential(String clientId) throws Exception {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();

        Class<?> builderClass = cl.loadClass("com.azure.identity.DefaultAzureCredentialBuilder");

        Object builder = builderClass.getDeclaredConstructor().newInstance();
        if (clientId != null && !clientId.isEmpty()) {
            LOGGER.info("Using user-assigned managed identity: " + clientId);
            Method micidMethod = builderClass.getMethod("managedIdentityClientId", String.class);
            micidMethod.invoke(builder, clientId);
        } else {
            LOGGER.info("Using system-assigned managed identity (no clientId).");
        }

        Method buildMethod = builderClass.getMethod("build");
        return buildMethod.invoke(builder);
    }