Skip to content

Allow the WebUI to connect to an authenticated API #2243

Open

Description

@hazae41

Checklist

  • My issue is specific & actionable.
  • I am not suggesting a protocol enhancement.
  • I have searched on the issue tracker for my issue.

Description

ipfs/kubo#2389

Is there a way to connect to an authenticated API from the WebUI?

It seems the WebUI only accepts an URL or a Multiaddress without any possibility to customize the Authorization header

Maybe there should be a way to put the authorization into the URL via path or query parameters?

Thanks

Activity

  1. added
    kind/enhancementA net-new feature or improvement to an existing feature
    on Jul 7, 2024
  2. hazae41 commented on Jul 8, 2024

    @hazae41
    Author

    I managed to get it to work by putting the secret token in a cookie and by using a Nginx reverse proxy to pass the cookie into an authorization header

    server {
        listen       80;
    
        location / {
            proxy_http_version    1.1;
            proxy_pass            https://ipfs.example.com/;
            proxy_ssl_server_name on;
            proxy_set_header      Authorization      "Bearer $cookie_token";
            proxy_pass_header     Authorization;
            client_max_body_size  100M;
        }
    }

    Then go to your proxy url /webui and execute the following JavaScript in the web console

    document.cookie="token=YOUR_IPFS_TOKEN"

    Reload the page and voila

    https://github.com/hazae41/safe-ipfs

  3. transferred this issue fromipfs/kuboon Jul 9, 2024
  4. lidel commented on Jul 9, 2024

    @lidel
    Contributor

    I think there is an old code that support Basic Auth (#836, #1586), but afaik there is no support for Bearer tokens.

    The basic auth credentials are passed in URL form:

    image

    @hazae41 does Basic Auth work for you (then we can close this), or do you need ability to pass custom Authorization header (then we should turn this into feature request).

  5. hazae41 commented on Jul 9, 2024

    @hazae41
    Author

    Thanks, I will try

    Yet Bearer should be good to add at some point if you have time

  6. hazae41 commented on Jul 10, 2024

    @hazae41
    Author

    When the WebUI is same-origin, I can successfully go to /webui and enter the user:pass in URL and it works

    But when the WebUI is cross-origin, its requests don't pass CORS, because it sends an OPTIONS preflight request without Authorization header, so the API then replies a Forbidden 403 since there is no header, which fails the CORS preflight test

    The solution would be to always reply to OPTIONS requests with HTTP 200

    I also noticed it can work with Bearer if we enter this JSON into the URL input

    {"url":"https://ipfs.example.com","headers":{"authorization":"Bearer YOUR_TOKEN"}}
  7. github-actions commented on Jul 17, 2024

    @github-actions
    Contributor

    Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days.

  8. github-actions commented on Jul 25, 2024

    @github-actions
    Contributor

    This issue was closed because it is missing author input.

  9. hazae41 commented on Sep 14, 2024

    @hazae41
    Author

    It's still an issue when connecting from a third-party, it's blocked by CORS

    The solution would be to always reply to OPTIONS requests with HTTP 200

  10. reopened this on Sep 16, 2024
  11. added
    exp/intermediatePrior experience is likely helpful
    P3Low: Not priority right now
    effort/hoursEstimated to take one or several hours
    and removed
    need/author-inputNeeds input from the original author
    on Sep 16, 2024
  12. vpavlin commented on Sep 20, 2024

    @vpavlin

    Can't you just set Allow-Origin and Allow-Methods in IPFS config?

    ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST", "OPTIONS"]'
    ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["'${IPFS_EXTERNAL_URL}'"]'
    

    Or is the problem that you don't control the node?

  13. 2color commented on Feb 25, 2025

    @2color
    Member

    In case someone comes across this issue, see the new guide covering how to configure IPFS Web UI with a remote Kubo node that is secured with Basic HTTP Auth: ipfs/ipfs-docs#2000.

    The guide also covers how to configure CORS and handle OPTIONS requests. It uses Caddy as the reverse proxy, so that you get a TLS cert too, which is needed in any real-world deployment.

    I'm not sure if there's anything else to do in this issue, since it's not the WebUI that needs changing, it's just CORS that needs to be configured correctly. I suppose the only thing that might be relevant is enabling CORS preflight handling in Kubo, but that would be an issue for the Kubo repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low: Not priority right noweffort/hoursEstimated to take one or several hoursexp/intermediatePrior experience is likely helpfulkind/enhancementA net-new feature or improvement to an existing feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions