I am trying to create an App for Outlook in OWA. Inside my app, I am using the function call getUserIdentityTokenAsync of the Mail Apps API. When I try to make an EWS request with the token, it is returning an Application Exception saying that the token is expired or not valid.
How do I get the unexpired and valid token from the Mail Apps API so that I can successfully make the EWS request?
From your comment above:
I am trying to avoid EWS calls from javascript
I am going under the assumption that you are trying to avoid calling makeEwsRequestAsync from the Javascript as that requires heightened requirements (ReadWriteMailbox) and you want to avoid that.
The token request you want to use is getCallbackTokenAsync, not getIdentityTokenAsync. You can pass the token to your App's backend and use it as the Bearer token to make EWS requests.
Resources: