tauri-apps / plugins-workspace

All of the official Tauri plugins in one place!
https://tauri.app
Apache License 2.0
814 stars 224 forks source link

[http][v2] url not allowed on the configured scope #1559

Open ktecho opened 1 month ago

ktecho commented 1 month ago

I get this when using latest version of "HTTP client" plugin. I also tested the git version of both parts (rust and js), with the same result:

[Error] Unhandled Promise Rejection: url not allowed on the configured scope: http://127.0.0.1:9740/getbalance

+page.svelte

<script>
     async function do_request() {
        const headers = new Headers();
        headers.append(
            'Authorization',
            "Basic ${btoa(':71ec453e388cdddff03f2dd31bb26230e09af625e922ecc4923a9b9561a27197')}"
        );

        const response = await fetch('http://127.0.0.1:9740/getbalance', {
            method: 'GET',
            headers: headers
        });
     }
</script>

Cargo.toml

[dependencies]
tauri = { version = "2.0.0-beta.24", features = [] }
tauri-plugin-http = "2.0.0-beta.12"

package.json

"dependencies": {
    "@tauri-apps/api": "^2.0.0-beta.15",
    "@tauri-apps/plugin-http": "^2.0.0-beta.8"
}

base.json

{
    "identifier": "http:default",
    "permissions": [
      {
        "identifier": "http:default",
        "allow": [
          {
            "url": "http://127.0.0.1:9740"
          },
          {
            "url": "http://127.0.0.1:9740/*"
          }
        ]
      }
    ]
  }

Full tauri info output

[✔] Environment
    - OS: Ubuntu 24.04 X64
    ✔ webkit2gtk-4.1: 2.44.2
    ✔ rsvg2: 2.58.0
    ✔ rustc: 1.79.0 (129f3b996 2024-06-10)
    ✔ cargo: 1.79.0 (ffa9cf99a 2024-06-03)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
    - node: 20.15.1
    - yarn: 1.22.22
    - npm: 10.7.0

[-] Packages
    - tauri [RUST]: 2.0.0-beta.24
    - tauri-build [RUST]: 2.0.0-beta.19
    - wry [RUST]: 0.41.0
    - tao [RUST]: 0.28.1
    - @tauri-apps/api [NPM]: 2.0.0-beta.15
    - @tauri-apps/cli [NPM]: 2.0.0-beta.21

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../public
    - devUrl: http://localhost:5173/
    - framework: Svelte
    - bundler: Vite
ktecho commented 1 month ago

Also, the documentation is not updated, because if I copy the base.json from here https://beta.tauri.app/plugin/http-client/ or here https://v2.tauri.app/reference/javascript/http/, it will complain that "identifier" is not found. That's why I put "identifier" twice in my "base.json".

amrbashir commented 1 month ago

Also, the documentation is not updated, because if I copy the base.json from here beta.tauri.app/plugin/http-client or here v2.tauri.app/reference/javascript/http, it will complain that "identifier" is not found. That's why I put "identifier" twice in my "base.json".

the first identifier is the identifier of the capability file, not the permission to be used

ktecho commented 1 month ago

Also, the documentation is not updated, because if I copy the base.json from here beta.tauri.app/plugin/http-client or here v2.tauri.app/reference/javascript/http, it will complain that "identifier" is not found. That's why I put "identifier" twice in my "base.json".

the first identifier is the identifier of the capability file, not the permission to be used

What would be the identifier for the base.json file? I tried with base, but it doesn't work.

ktecho commented 1 month ago

I changed base.json to this:

{
    "identifier": "http.phoenix",
    "permissions": [
      {
        "identifier": "http:default",
        "local": true,
        "windows": ["*"],
        "allow": [
          {
            "url": "http://localhost:9740/*"
          },
          {
            "url": "http://**/"
          }
        ]
      }
    ]
  }

and added this to tauri.conf.json:

    "security": {
      "csp": null,
      "capabilities": ["http.phoenix"]
    }
  }

and now I get this:

Unhandled Promise Rejection: http.fetch not allowed on window main, webview main, allowed windows: , allowed webviews: , referenced by capability: http.phoenix, permission: default

I've tried with "windows": ["*"], and "windows": ["main"],, but it doesn't work.

ktecho commented 1 month ago

I recommend using this steps to create your app so your http plugin is configured and working in v2: https://github.com/tauri-apps/plugins-workspace/issues/1484#issuecomment-2222169301