Skip to content

Order of annotator plugins is important when using Auth plugin #259

@jmiranda

Description

@jmiranda

I was running into an issue today in which my basic annotator client was sending "search" requests to my annotator store implementation, but without a token so the response was always a 401 unauthorized error. I've implemented the /auth/token endpoint on the client and it's working fine (I'm able to create/update/delete annotations after the page loads), but for some reason the Auth plugin was not adding the token to the headers for the initial search request on page load.

After hours of staring at the Network tab in Chrome I realized that the search request was happening BEFORE the token request was being made, which made me realize that the Auth plugin was not adding the token to the search request for the simple fact that it was happening before the token was available.

Anyway, I'm not sure if this is a bug or just something that should be added to the documentation, but just wanted to give you guys a heads up in case other people run into the same issue.

In short, the following code does not work:

var content = $('#content'));
content.annotator('addPlugin', 'Store', {
   // removed for brevity
});
content.annotator('addPlugin', 'Auth', {
  tokenUrl: '/auth/token'
});

annotator-store-before-auth-leads-to-401
But this does:

var content = $('#content'));
content.annotator('addPlugin', 'Auth', {
  tokenUrl: '/auth/token'
});
content.annotator('addPlugin', 'Store', {
   // removed for brevity
});

annotator-auth-before-store-leads-to-200

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions