Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[releases/24.0] Authentication failure when Get/Post request is sent …
…to Azure Function multiple times with the same authentication parameters (#1828) **Actions:** Run the code below: ``` local procedure SendRequestToAzureFunction() var AzureFunctionsAuthentication: Codeunit "Azure Functions Authentication"; AzureFunctions: Codeunit "Azure Functions"; AzureFunctionsAuth: Interface "Azure Functions Authentication"; ClientID, Scope, AuthURL, EndpointText : Text; RequestBody: Text; Cert: SecretText; i: Integer; begin GetAuthParameters(ClientID, Cert, AuthURL, EndpointText); Scope := 'api://abcdefff-1111-2222-3333-123456789fff/.default'; AzureFunctionsAuth := AzureFunctionsAuthentication.CreateOAuth2WithCert(EndpointText, '', ClientID, Cert, AuthURL, '', Scope); RequestBody := GetRequestBody(); for i := 1 to 200 do AzureFunctions.SendPostRequest(AzureFunctionsAuth, RequestBody, 'application/json'); end; ``` It sets Authentication parameters once and then sends POST request to Azure Function 200 times. **Expected result:** Request is sent 200 times without errors. **Actual result:** After about 128 executions of AzureFunctions.SendPostRequest() the function fails with the error "Authentication Failed". The telemetry logs right befoge the authentication failure show the error: _Microsoft.Dynamics.Nav.LicensingService.Model.Exceptions.LicenseServiceTransientException in AcquireApplicationTokenWithCertificate: LicenseServiceTransientException: Exception details : **RequestUriTooLong** - error returned._ The reason for this error is that every time the SendPostRequest is invoked, the scope is added to the global list of scopes that is used to authenticate in Azure Function. Therefore the list of scopes grows, and it seems that the list is used to build URI for authentication, so after multiple iterations the authentication function fails with RequestUriTooLong. Fixes [AB#544604](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/544604) Co-authored-by: Alexander Gladkov <[email protected]>
- Loading branch information