I am using gSoap to interact with Exchange Online using EWS APIs. Lately I have seen that gSoap request soap->fpost is truncating value of bearer token and that is resulting in access denied error. The bearer token is fetched using Azure AD OAuth authentication and has length exceeding 2048.
The token gets truncated exactly at 2040 characters.
To solve this, I tried to set SOAP_BUFLEN to 32K in stdsoap2.h and have also verified that soap->buf is of size 64K. But still soap->fpost is returning failure.
Pasting below sample auth token (with some lines deleted for safety) and SOAP request.
Bearer token received:
eyJ0eXAiOiJKV1QiLCJub25jZSI6InpSMk1VMnFQXzVFV3AtaVNYQ0doR3NzTGNKdVhVVUJTNjlpdGNBNjBXV2siLCJhbGciOiJSUzI1NiIsIng1dCI6Il9qTndqZVNudlRUSzhYRWRyNVFVUGtCUkxMbyIsImtpZCI6Il9qTndqZVNudlRUSzhYRWRyNVFVUGtCUkxMbyJ9.eyJhdWQiOiJodHRwczovL291dGxvb2sub2ZmaWNlLmNvbSIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0L2FhNmM1M2IyLWI2YTUtNDlhNi1iNDY4LWZiZTczMGZmOTU0Yy8iLCJpYXQiOjE3NTI5MTg4NTEsIm5iZiI6MTc1MjkxODg1MSwiZXhwIjoxNzUyOTIyNzUxLCJhaW8iOiJrMlJnWUh
9.CkPN_fC6kxGH-oFex2zTqic6bCv2RyQba2hzsjl10JGngfprIaUY3jB3DfEK5VDL3d7ni_gdmsMjsBrHgCugW22H58wnyKnaBXi-GvBGbR8lNgFPn0Q6wZefwsVL7P1V25v2X4rdsOLh23GiYuycYiuGuWBHaeMgYMDyxx9fQd0U8QQI1IQLN1OJFbxjLOhrmen7qeQKTxGMElBONom1Liyrly275Tpg7uWVbr9_I8ZIHoVSV2y6PdRTwFsniy0kQqEW0OoaTzEDoqCQgWqDO8GU8e9gRNDywGeZKfaH4JDT2IwIhzxsweH7HVg03sQM_MC-RladSvC8rgOb81ce2Q
Soap request created in soap->fpost call (pasting value of soap->buf where soap is the first parameter passed to soap->fpost call):
POST /EWS/Exchange.asmx HTTP/1.1
Host: outlook.office365.com
User-Agent: gSOAP/2.8E
Content-Type: text/xml; charset=utf-8
Content-Length: 1348
X-AnchorMailbox: Adams@M365x70736779.OnMicrosoft.com
X-PreferServerAffinity: true
client-request-id: 99d33fef-721f-4c13-9820-889146292102
return-client-request-id: true
Connection: close
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6InpSMk1VMnFQXzVFV3AtaVNYQ0doR3NzTGNKdVhVVUJTNjlpdGNBNjBXV2siLCJhbGciOiJSUzI1NiIsIng1dCI6Il9qTndqZVNudlRUSzhYRWRyNVFVUGtCUkxMbyIsImtpZCI6Il9qTndqZVNudlRUSzhYRWRyNVFVUGtCUkxMbyJ9.eyJhdWQiOiJodHRwczovL291dGxvb2sub2ZmaWNlLmNvbSIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0L2FhNmM1M2IyLWI2YTUtNDlhNi1iNDY4LWZiZTczMGZmOTU0Yy8iLCJpYXQiOjE3NTI5MTg4NTEsIm5iZiI6MTc1MjkxODg1MSwiZXhwIjoxNzUyOTIyNzUxLCJhaW8iOiJrMlJnWUh
9.CkPN_fC6kxGH-oFex2zTqic6bCv2RyQba2hzsjl10JGngfprIaUY3jB3DfEK5VDL3d7ni_gdmsMjsBrHgCugW22H58wnyKnaBXi-GvBGbR8lNgFPn0Q6wZefwsVL7P1V25v2X4rdsOLh23GiYuycYiuGuWBHaeMgYMDyxx9fQd0U8QQI1IQLN1OJFbxjLOhrmen7qeQKTxGMElBONom1Liyrly275Tpg7uWVbr9_I8ZIHoVSV2y6PdRTwFsniy0kQqEW0OoaTzEDoqCQgWqDO8GU8e9gRNDywGeZKfaH4JDT2IwIhzxswe
SOAPAction: "http://schemas.microsoft.com/exchange/services/2006/messages/GetFolder"
As you can see above soap->buf has truncated value of bearer token (last few characters are missing). (Here soap is the first paramter passed to soap->fpost call)
Let me know if there are any other size paramters I need to set or if there is any solution to this.
Could narrow down the issue to SOAP_TMPLEN
buffer used in stdsoap2.h file. Increasing value of this buffer solved the issue.