Search in sources :

Example 1 with InteractiveBrowserCredentialBuilder

use of com.azure.identity.InteractiveBrowserCredentialBuilder in project msgraph-sdk-java-core by microsoftgraph.

the class InteractiveBrowserMain method main.

public static void main(String[] args) throws Exception {
    final InteractiveBrowserCredential interactiveBrowserCredential = new InteractiveBrowserCredentialBuilder().clientId(CLIENT_ID).redirectUrl("http://localhost:8765").build();
    final TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(SCOPES, interactiveBrowserCredential);
    final OkHttpClient httpClient = HttpClients.createDefault(tokenCredentialAuthProvider);
    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 : InteractiveBrowserCredential(com.azure.identity.InteractiveBrowserCredential) InteractiveBrowserCredentialBuilder(com.azure.identity.InteractiveBrowserCredentialBuilder) IOException(java.io.IOException) InteractiveBrowserCredentialBuilder(com.azure.identity.InteractiveBrowserCredentialBuilder)

Example 2 with InteractiveBrowserCredentialBuilder

use of com.azure.identity.InteractiveBrowserCredentialBuilder in project azure-maven-plugins by microsoft.

the class OAuthAccount method createCredential.

protected TokenCredential createCredential(AzureEnvironment env) {
    AzureEnvironmentUtils.setupAzureEnvironment(env);
    InteractiveBrowserCredentialBuilder builder = new InteractiveBrowserCredentialBuilder();
    if (isEnablePersistence()) {
        builder.tokenCachePersistenceOptions(new TokenCachePersistenceOptions().setName(TOOLKIT_TOKEN_CACHE_NAME));
    }
    return builder.redirectUrl("http://localhost:" + FreePortFinder.findFreeLocalPort()).build();
}
Also used : TokenCachePersistenceOptions(com.azure.identity.TokenCachePersistenceOptions) InteractiveBrowserCredentialBuilder(com.azure.identity.InteractiveBrowserCredentialBuilder)

Aggregations

InteractiveBrowserCredentialBuilder (com.azure.identity.InteractiveBrowserCredentialBuilder)2 InteractiveBrowserCredential (com.azure.identity.InteractiveBrowserCredential)1 TokenCachePersistenceOptions (com.azure.identity.TokenCachePersistenceOptions)1 IOException (java.io.IOException)1