Created
December 13, 2023 17:33
-
-
Save maisarissi/74e7ddf7a6c861379acc5f92f0f5f6f9 to your computer and use it in GitHub Desktop.
microsoftgraph-java-v6-sefl-serve-kiota
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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