Im using client credential approach to fetch data using Microsoft Graph api. As mentioned in documentation, we can customize it.
Below is the code snippet i tried:
final ClientCredentialProvider authProvider = new ClientCredentialProvider(this.clientId, this.scopes, this.clientSecret, this.tenantId, NationalCloud.Global);
final OkHttpClient httpClient = HttpClients.createDefault(authProvider).newBuilder().build();
final IHttpProvider httpProvider = DefaultClientConfig.createWithAuthenticationProvider(authProvider).getHttpProvider(httpClient);
final IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(authProvider).buildClient();
However im getting below errors:
2021-03-12T22:10:39,340 ERROR [restartedMain] c.m.g.l.DefaultLogger: CoreHttpProvider[send] - 220Graph service exception Error code: InvalidAuthenticationToken
2021-03-12T22:10:39,340 ERROR [restartedMain] c.m.g.l.DefaultLogger: CoreHttpProvider[send] - 220Error message: CompactToken parsing failed with error code: 80049217
2021-03-12T22:10:39,340 ERROR [restartedMain] c.m.g.l.DefaultLogger: CoreHttpProvider[send] - 220
2021-03-12T22:10:39,341 ERROR [restartedMain] c.m.g.l.DefaultLogger: CoreHttpProvider[send] - 220GET https://graph.microsoft.com/v1.0/users?%24select=Id%2CDisplayName%2CMail%2CUserPrincipalName%2CEmployeeId&%24expand=registeredDevices
2021-03-12T22:10:39,341 ERROR [restartedMain] c.m.g.l.DefaultLogger: CoreHttpProvider[send] - 220SdkVersion : graph-java/v2.6.0
2021-03-12T22:10:39,341 ERROR [restartedMain] c.m.g.l.DefaultLogger: CoreHttpProvider[send] - 220Authorization : [PII_REDACTED]
2021-03-12T22:10:39,341 ERROR [restartedMain] c.m.g.l.DefaultLogger: CoreHttpProvider[send] - 220
2021-03-12T22:10:39,342 ERROR [restartedMain] c.m.g.l.DefaultLogger: CoreHttpProvider[send] - 220
2021-03-12T22:10:39,342 ERROR [restartedMain] c.m.g.l.DefaultLogger: CoreHttpProvider[send] - 220401 : Unauthorized
2021-03-12T22:10:39,342 ERROR [restartedMain] c.m.g.l.DefaultLogger: CoreHttpProvider[send] - 220[...]
2021-03-12T22:10:39,342 ERROR [restartedMain] c.m.g.l.DefaultLogger: CoreHttpProvider[send] - 220
2021-03-12T22:10:39,343 ERROR [restartedMain] c.m.g.l.DefaultLogger: CoreHttpProvider[send] - 220[Some information was truncated for brevity, enable debug logging for more details]
2021-03-12T22:10:39,343 ERROR [restartedMain] c.m.g.l.DefaultLogger: Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: InvalidAuthenticationToken
Error message: CompactToken parsing failed with error code: 80049217
GET https://graph.microsoft.com/v1.0/users?%24select=Id%2CDisplayName%2CMail%2CUserPrincipalName%2CEmployeeId&%24expand=registeredDevices
SdkVersion : graph-java/v2.6.0
Authorization : [PII_REDACTED]
401 : Unauthorized
[...]
If i remove the client customization code it works. Below code is working:
final ClientCredentialProvider authProvider = new ClientCredentialProvider(this.clientId, this.scopes, this.clientSecret, this.tenantId, NationalCloud.Global);
final IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(authProvider).buildClient();
Im unable to find what is causing issues when trying to customize the Client.
Any help will be greatly appreciated.