Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
import com.azure.identity.UsernamePasswordCredential;
import com.azure.identity.UsernamePasswordCredentialBuilder;
import com.microsoft.graph.authentication.TokenCredentialAuthProvider;
import com.microsoft.graph.requests.GraphServiceClient;
import com.microsoft.graph.requests.UserCollectionPage;
import java.util.Arrays;
public class TestConnectionAzureAD {
public static void main(String[] args) {
UsernamePasswordCredential usernamePasswordCredential = new UsernamePasswordCredentialBuilder()
.clientId("Client_Id")
.username("User_Name")
.password("Password")
.build();
final TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(Arrays.asList("https://graph.microsoft.com/.default"), usernamePasswordCredential);
final GraphServiceClient graphClient = GraphServiceClient
.builder()
.authenticationProvider(tokenCredentialAuthProvider)
.buildClient();
UserCollectionPage userCollectionpage = graphClient.users().buildRequest().get();
System.out.println("--");
I am using -
kotlin-stdlib-1.6.20.jar, microsoft-graph-5.31.0.jar, microsoft-graph-core-2.0.13.jar, okhttp-4.0.1.jar -- these jars...
I am getting this error -
Exception in thread "main" java.lang.NoSuchFieldError: Companion
at okhttp3.internal.Util.<clinit>(Util.kt:69)
at okhttp3.internal.connection.RealConnectionPool.<clinit>(RealConnectionPool.kt:261)
at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:37)
at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:39)
at okhttp3.OkHttpClient$Builder.<init>(OkHttpClient.kt:430)
at com.microsoft.graph.httpcore.HttpClients.custom(HttpClients.java:28)
at com.microsoft.graph.httpcore.HttpClients.createDefault(HttpClients.java:44)
at com.microsoft.graph.core.BaseClient$Builder.getHttpClient(BaseClient.java:180)
at com.microsoft.graph.core.BaseClient$Builder.getHttpProvider(BaseClient.java:188)
at com.microsoft.graph.core.BaseClient$Builder.buildClient(BaseClient.java:276)
at com.microsoft.graph.requests.GraphServiceClient$Builder.buildClient(GraphServiceClient.java:258)
solution ?
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.