Search in sources :

Example 1 with DeviceCodeCredential

use of com.azure.identity.DeviceCodeCredential 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();
        }
    });
}
Also used : DeviceCodeCredential(com.azure.identity.DeviceCodeCredential) DeviceCodeCredentialBuilder(com.azure.identity.DeviceCodeCredentialBuilder) HttpClients(com.microsoft.graph.httpcore.HttpClients) Arrays(java.util.Arrays) List(java.util.List) okhttp3(okhttp3) IOException(java.io.IOException) TokenCredentialAuthProvider(com.microsoft.graph.authentication.TokenCredentialAuthProvider) DeviceCodeCredential(com.azure.identity.DeviceCodeCredential) TokenCredentialAuthProvider(com.microsoft.graph.authentication.TokenCredentialAuthProvider) DeviceCodeCredentialBuilder(com.azure.identity.DeviceCodeCredentialBuilder) IOException(java.io.IOException) DeviceCodeCredentialBuilder(com.azure.identity.DeviceCodeCredentialBuilder)

Aggregations

DeviceCodeCredential (com.azure.identity.DeviceCodeCredential)1 DeviceCodeCredentialBuilder (com.azure.identity.DeviceCodeCredentialBuilder)1 TokenCredentialAuthProvider (com.microsoft.graph.authentication.TokenCredentialAuthProvider)1 HttpClients (com.microsoft.graph.httpcore.HttpClients)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 List (java.util.List)1 okhttp3 (okhttp3)1