I am developing an application. The user flow is that a user logged in to MS teams selects a message and clicks on my messaging extension. This sends information to my app. The headers contain an Authorization header with a Bearer token and I am trying to use this token to get delegated permissions for microsoft graph api. The error i get is:
ERROR .identity.OnBehalfOfCredential - Azure Identity => ERROR in getToken() call for scopes [api://.../default] Assertion failed signature validation. [Reason - The key was not found. <...>]
and my code is
String accessToken = exchange.getIn().getHeader("Authorization", String.class);
if (accessToken != null && accessToken.startsWith("Bearer ")) {
accessToken = accessToken.split(" ")[1]
}
List<String> scopes = Arrays.asList("api://" + clientId + "/default");
final OnBehalfOfCredential onBehalfOfCredential = new OnBehalfOfCredentialBuilder()
.clientId(clientId)
.clientSecret(clientSecret)
.userAssertion(accessToken)
.tenantId(tenantId)
.build();
final TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(scopes, onBehalfOfCredential);
final GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(tokenCredentialAuthProvider).buildClient();
final User me = graphClient.me().buildRequest().get()
I am unsure what the problem could be, as the token i get comes directly from ms teams. Not sure what my code is missing as it was taken directy from the documentation