How to handle Authorization for Remote RestAPI in Data Sources

Posted by: cibarra on 16 April 2025, 1:34 pm EST

  • Posted 16 April 2025, 1:34 pm EST

    Hi,

    I have a question about how the library (ReportViewer & ReportDesigner) handles the revalidation of a bearer token when happens to expire if the data source Remote Source requires Authorization?.

    I have a Remote RestAPI that is protected by an AccessToken strategy with expiration. I have read already the documentation about Data Binding https://developer.mescius.com/activereportsjs/docs/ReportAuthorGuide/Databinding and also the post on how to add dynamic data binding with a data source that requires Authorization https://developer.mescius.com/blogs/how-to-add-dynamic-data-binding-to-a-javascript-reporting-app and its ok for a first implementation on a happy path, but I couldn’t find any information on how the library will react if for some reason (timing) the library request the data sources with an expired access token and what would be the process as a User to make the component revalidates the access token or at least a screenshot if it will appear some kind of error in the UI.

    Will I have to refresh the page so that the the report get and bind the new AccessToken as parameter again (based on the example in the post)? If so, will this be the approach to take whenever that happens?

    Hope someone can help me answering this questions.

    Regards

  • Posted 23 April 2025, 12:28 am EST

    Hi,

    If the token expires, the Viewer will throw an error and display the corresponding error code returned by your API (likely Error Code 500).

    You can handle this error by implementing the Viewer’s errorHandler to display a custom error message or perform custom actions, such as updating the token in your report and reloading it in the Viewer.

    For more information on error handling, please refer to the following documentation page:

    https://developer.mescius.com/activereportsjs/api/classes/ReportViewer.Viewer#errorhandler

    Sample Code:

    <Viewer 
      report={{ Uri: 'Report.rdlx-json' }} 
      errorHandler={(e) => { 
        console.log(e); 
        return true; 
      }} 
    />
    
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels