All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.identity.credential.DeviceCodeCredentialBuilder Maven / Gradle / Ivy

There is a newer version: 1.15.0
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.identity.credential;

import com.azure.identity.DeviceCodeChallenge;
import com.azure.identity.implementation.util.ValidationUtil;

import java.util.HashMap;
import java.util.function.Consumer;

/**
 * Fluent credential builder for instantiating a {@link DeviceCodeCredential}.
 *
 * @see DeviceCodeCredential
 */
public class DeviceCodeCredentialBuilder extends AadCredentialBuilderBase {
    private Consumer deviceCodeChallengeConsumer;

    /**
     * Sets the port for the local HTTP server, for which {@code http://localhost:{port}} must be
     * registered as a valid reply URL on the application.
     *
     * @param deviceCodeChallengeConsumer a method allowing the user to meet the device code challenge
     * @return the InteractiveBrowserCredentialBuilder itself
     */
    public DeviceCodeCredentialBuilder deviceCodeChallengeConsumer(
        Consumer deviceCodeChallengeConsumer) {
        this.deviceCodeChallengeConsumer = deviceCodeChallengeConsumer;
        return this;
    }

    /**
     * @return a {@link DeviceCodeCredential} with the current configurations.
     */
    public DeviceCodeCredential build() {
        ValidationUtil.validate(getClass().getSimpleName(), new HashMap() {{
                put("clientId", clientId);
                put("deviceCodeChallengeConsumer", deviceCodeChallengeConsumer);
            }});
        return new DeviceCodeCredential(clientId, tenantId, deviceCodeChallengeConsumer, identityClientOptions);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy