Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search doesn't work with basic auth. #87

Closed
StephaneRob opened this issue Jan 5, 2017 · 9 comments
Closed

Search doesn't work with basic auth. #87

StephaneRob opened this issue Jan 5, 2017 · 9 comments
Assignees
Labels
bug Issue reports a bug
Milestone

Comments

@StephaneRob
Copy link

Description

Search doesn't work if basic auth required.

Expected behavior

Fetch search_index.json return a 200

Actual behavior

Fetch search_index.json return a 401

Steps to reproduce the bug

  1. Set basic auth
  2. Build site
  3. Search in docs

Package versions

  • Material: 1.0.0.rc
@squidfunk
Copy link
Owner

Well, this is not a problem of the Material theme but a general problem with XHR on hosts with basic auth. Any suggestions?

@StephaneRob
Copy link
Author

StephaneRob commented Jan 6, 2017

@squidfunk thanks for all your work, mkdocs-material 0.2.4 is great, 1.0.0 is even more !

I looked at the original mkdocs theme and the search_index.json is loaded with requirejs, and it works with basic auth.

https://github.com/mkdocs/mkdocs/blob/master/mkdocs/assets/search/mkdocs/js/search.js#L5

@StephaneRob
Copy link
Author

I made it works again by adding the following code in base.html (before application.js):

      <script type="text/javascript">
        var require = {
            baseUrl: './mkdocs/js',
            paths: {
                text: 'text'
            }
        }
      </script>
      <script src="./mkdocs/js/require.js"></script>
      <script type="text/javascript">
        require(['text!../search_index.json']);
      </script>

search_index.json is loaded with Authorization header.

@squidfunk
Copy link
Owner

Did you use Chrome? I think we just need to set some header and it should work - no need for require.js

@StephaneRob
Copy link
Author

Yes

@StephaneRob
Copy link
Author

StephaneRob commented Jan 6, 2017

The solution may be to include credentials in fetch :

- return fetch(_this.config_.url.base + "/mkdocs/search_index.json").then(function (response) {
+ return fetch(_this.config_.url.base + "/mkdocs/search_index.json", {credentials: 'include'}).then(function (response) {

https://github.com/squidfunk/mkdocs-material/blob/rework/src/assets/javascripts/application.js#L144

@squidfunk
Copy link
Owner

Should be fixed in rework with b273c42. Can you please check out the rework branch and confirm? I added the credentials flag, so the auth cookie should be sent by fetch.

@squidfunk squidfunk self-assigned this Jan 6, 2017
@squidfunk squidfunk added the bug Issue reports a bug label Jan 6, 2017
@squidfunk squidfunk added this to the 1.0.0 milestone Jan 6, 2017
@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Jan 6, 2017
@StephaneRob
Copy link
Author

@squidfunk Tested and it works good !
Thanks.

@squidfunk
Copy link
Owner

Awesome, thanks!

@squidfunk squidfunk removed the resolved Issue is resolved, yet unreleased if open label Jan 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug
Projects
None yet
Development

No branches or pull requests

2 participants