use of com.azure.identity.DeviceCodeCredentialBuilder in project azure-maven-plugins by microsoft.
the class DeviceCodeAccount method createCredential.
private TokenCredential createCredential(AzureEnvironment env) {
if (executorService.isShutdown()) {
throw new AzureToolkitAuthenticationException("device login twice is forbidden.");
}
AzureEnvironmentUtils.setupAzureEnvironment(env);
DeviceCodeCredentialBuilder builder = new DeviceCodeCredentialBuilder();
if (isEnablePersistence()) {
builder.tokenCachePersistenceOptions(new TokenCachePersistenceOptions().setName(TOOLKIT_TOKEN_CACHE_NAME));
}
return builder.clientId(IdentityConstants.DEVELOPER_SINGLE_SIGN_ON_ID).executorService(executorService).challengeConsumer(deviceCodeFuture::complete).build();
}
use of com.azure.identity.DeviceCodeCredentialBuilder in project msgraph-sdk-java-core by microsoftgraph.
the class DeviceCodeFlowMain method main.
public static void main(String[] args) throws Exception {
final DeviceCodeCredential deviceCodeCred = new DeviceCodeCredentialBuilder().clientId(CLIENT_ID).challengeConsumer(challenge -> System.out.println(challenge.getMessage())).build();
final TokenCredentialAuthProvider tokenCredAuthProvider = new TokenCredentialAuthProvider(SCOPES, deviceCodeCred);
final OkHttpClient httpClient = HttpClients.createDefault(tokenCredAuthProvider);
final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/me/").build();
httpClient.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
System.out.println(response.body().string());
}
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
});
}
Aggregations