Getting 401 when clicking Print -> PDF
Getting 401 when clicking Print -> PDF
Hello,
I have a angular viewer in Angular APP(v11), talking to DotNet core API 6. As per our requirements we authorise all transactions to backend using access token.
At initial load both initViewer and ViewerEvent gets called along with token and load the report okay.
Once loaded if I to try clicking Print -> PDF, it makes a call to ViewerEvent and fails with 401, as this request doesn't has access token to it.
We use HTTP interceptor to add token to all the calls made from the app.
Please help!
Ali
I have a angular viewer in Angular APP(v11), talking to DotNet core API 6. As per our requirements we authorise all transactions to backend using access token.
At initial load both initViewer and ViewerEvent gets called along with token and load the report okay.
Once loaded if I to try clicking Print -> PDF, it makes a call to ViewerEvent and fails with 401, as this request doesn't has access token to it.
We use HTTP interceptor to add token to all the calls made from the app.
Please help!
Ali
-
- Posts: 5245
- Joined: Tue Mar 20, 2018 5:34 am
Re: Getting 401 when clicking Print -> PDF
Hello,
Please send us a sample project that reproduces the issue for analysis.
Thank you.
Please send us a sample project that reproduces the issue for analysis.
Thank you.
Re: Getting 401 when clicking Print -> PDF
Please see attached sample, I have added a key authorization when make call to "ViewerEvent" endpoint.
The angular app has http interceptor code which add the key to each call being made to the server.
At initial load it works and key gets passed around.
But as soon as you click Pint -> PDF, it some how bypass the interceptor and I get 401.
Is there an event like 'onBeginTransaction' which I can hook in.
Thanks
The angular app has http interceptor code which add the key to each call being made to the server.
At initial load it works and key gets passed around.
But as soon as you click Pint -> PDF, it some how bypass the interceptor and I get 401.
Is there an event like 'onBeginTransaction' which I can hook in.
Thanks
- Attachments
-
- Samples-Angular-master.zip
- (28.4 MiB) Downloaded 56 times
-
- Posts: 5245
- Joined: Tue Mar 20, 2018 5:34 am
Re: Getting 401 when clicking Print -> PDF
Hello,
We need some additional time to investigate the issue, we will let you know about the result.
Thank you.
We need some additional time to investigate the issue, we will let you know about the result.
Thank you.
Re: Getting 401 when clicking Print -> PDF
Hello.
If PDF preview we use Form post functional, so using HTTP headers is not available here.
Please use next solution:
In add
In AppComponent add function:
In AuthorisationKeyHandler use Form parameters:
If PDF preview we use Form post functional, so using HTTP headers is not available here.
Please use next solution:
In
Code: Select all
<stimulsoft-viewer-angular
Code: Select all
[postParametersFunction]="getPostParameters"
Code: Select all
public getPostParameters(data): any {
return { 'ApiKey': `2ef25513-c765-4e62-8512-15e50d533db8` };
}
Code: Select all
private void SucceedRequirementIfAuthKeyPresentAndValid(AuthorizationHandlerContext context, AuthorisationKeyRequirement requirement)
{
var authKey = this.httpContextAccessor.HttpContext.Request.Form["ApiKey"].FirstOrDefault();
if (authKey != null && requirement.AuthorisationKeys.Any(requiredAuthKey => authKey == requiredAuthKey))
{
context.Succeed(requirement);
}
}
Re: Getting 401 when clicking Print -> PDF
That seems to be okay with above approach. I have another set of APIs which works with JWT Authorisation. Considering above I added following:
With above I mange to fix the 401, but now I am getting this at clientside. see attached image
Code: Select all
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
{
options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
if (context.Request.Path.StartsWithSegments("/reportviewer", StringComparison.OrdinalIgnoreCase))
{
if (context.Request.Form.TryGetValue("access_token", out var accessToken))
{
context.Token = accessToken;
}
}
return Task.CompletedTask;
},
};
});
- Attachments
-
- error.png (63.94 KiB) Viewed 757 times
Re: Getting 401 when clicking Print -> PDF
Hello.
You need to enable CORS, for example like:
You need to enable CORS, for example like:
Re: Getting 401 when clicking Print -> PDF
Thanks, I already have CORS settings enabled as per above and I am still getting the same error....
ERROR DOMException: Blocked a frame with origin "http://localhost:53422" from accessing a cross-origin frame.
ERROR DOMException: Blocked a frame with origin "http://localhost:53422" from accessing a cross-origin frame.
Re: Getting 401 when clicking Print -> PDF
Hello.
We don't exactly know your configuration, so we haven't common solution for it.
What you need to do is to enable CORS.
We don't exactly know your configuration, so we haven't common solution for it.
What you need to do is to enable CORS.
Re: Getting 401 when clicking Print -> PDF
I definitely have exact same CORS policy enabled as above. Could this is be an issue if you're debugging it locally.
I am going to host the site to see if it fixes the issue.
I am going to host the site to see if it fixes the issue.