Skip to content

Instantly share code, notes, and snippets.

@maisarissi
Created December 13, 2023 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maisarissi/74e7ddf7a6c861379acc5f92f0f5f6f9 to your computer and use it in GitHub Desktop.
Save maisarissi/74e7ddf7a6c861379acc5f92f0f5f6f9 to your computer and use it in GitHub Desktop.
microsoftgraph-java-v6-sefl-serve-kiota
final String[] scopes = new String[] {"Mail.Read", "Mail.Send", "User.Read"};
final String[] allowedHosts = new String[] {"graph.microsoft.com"};
DeviceCodeCredential deviceCodeCredential = new DeviceCodeCredentialBuilder()
.clientId(appId)
.tenantId(tenantId)
.challengeConsumer(challenge -> {
System.out.println(challenge.getMessage());
})
.build();
//Create an authentication provider using the credential and scopes
AzureIdentityAuthenticationProvider authProvider = new AzureIdentityAuthenticationProvider(deviceCodeCredential, allowedHosts, scopes);
//Create a request adapter to use when instantiating the Graph client
BaseGraphRequestAdapter requestAdapter = new BaseGraphRequestAdapter(authProvider);
GraphBaseServiceClient graphClient = new GraphBaseServiceClient(requestAdapter, new InMemoryBackingStoreFactory());
User me = graphClient.me().get(requestConfiguration ->
requestConfiguration.queryParameters.select = new String[] {"displayName", "mail", "userPrincipalName"});
System.out.printf("DisplayName: %s\nMail: %s\nUserPrincipalName: %s",
me.getDisplayName(), me.getMail(), me.getUserPrincipalName());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment