Since two days I’m getting the following error using Internet Identity canister locally (dev-build) from within my app:
Console logs:
index.js:331 Refused to connect to 'http://icp-api.io/api/v2/status' because it violates the following Content Security Policy directive: "connect-src 'self' https://identity.internetcomputer.org https://icp-api.io https://*.icp0.io https://*.ic0.app".
I’m quite sure that I did not change anything in the code related to II recently…
I tried release https://github.com/dfinity/internet-identity/releases/download/release-2023-02-12_2/internet_identity_dev.wasm but same result…
What really puzzles me is that using https://github.com/dfinity/internet-identity/tree/main/demos/using-dev-build as a demo application for local internet identity works fine, but the same approach from within our app fails…
Oh I was almost expecting that pinning the version would solve it .
I read the error message again and the issue is clear to me now.
index.js:331 Refused to connect to 'http://icp-api.io/api/v2/status' because it violates the following Content Security Policy directive: "connect-src 'self' https://identity.internetcomputer.org https://icp-api.io https://*.icp0.io https://*.ic0.app".
It says something tries to connect to http://icp-api.io/... but the CSP allows “only” https://icp-api.io
i.e. http vs https
That said, now sure where the call is made and why it goes through http instead of https
TL;DR: do you use 0.0.0.0 for deployment? If so, apologies, we’ll fix this soon.
We changed some of the logic for figuring out what endpoint to use for the IC, but it looks like we’ve broken something. Here’s the logic for local development:
if (
location.host === "127.0.0.1" ||
location.hostname.endsWith("localhost")
) {
// If this is a local deployment, then assume the api and assets are collocated
// and use this asset (page)'s URL.
return location.protocol + "//" + location.host;
}
Effectively this means “if the URL is 127.0.0.1 or ends with localhost then assume the API is a local replica served at that same URL”. In production, it should be using https://icp-api.io instead:
// In general, use the official IC HTTP domain.
return location.protocol + "//" + IC_API_DOMAIN;
See the source here. We tried to reuse some logic from agent-js but evidently we got something wrong.
@p_d what do you have in your address bar when the issue happens? I’m guessing you’re neither on localhost nor on 127.0.0.1? Maybe 0.0.0.0? I didn’t think of that.
Either way, you probably should pin your version of II as @peterparker suggested!
My local frontend app is running on http://127.0.0.1:8080 (webpack server) and http://127.0.0.1:4943/?canisterId=ryjl3-tyaaa-aaaaa-aaaba-cai (local replica). The corresponding redirect to local II is to http://127.0.0.1:4943/?canisterId=rkp4c-7iaaa-aaaaa-aaaca-cai#authorize.
So if my understanding is right this should work, isn’t it?
I’m using now release-2023-02-17 which works, I just had to ensure that the old canister was really deleted (dfx canister delete --all) when switching the II version…
Hmmm, after having deleted all my canisters (dfx canister delete --all) it seems to work now also with the latest release.
I’m feeling kind of stupid now, but I guess there was something wrong in my local replica and without deleting all canisters I couldn’t fix it, even with pinning a older release…
Anway, I think it should be all fine now, sorry for this issue!
Anywhere I can find a functioning II repo?
can not find any branch auth-client-demo that will give a local deployment.
Unable to find the doesn’t direct to a valid II endpoint.
have the ports changed?
Actually that’s where I am at rn. Thank you !
Build works.
But still haven’t checked the test cases and integration.
any idea why the above doesn’t work?
Hmmm, I facing the same issue now with my application when running it locally but found out that it only occurs in Chrome browser. In Safari it works fine!
What really puzzles me is that using https://github.com/dfinity/internet-identity/tree/main/demos/using-dev-build as a demo application for local internet identity works fine, but the same approach from within our app fails. I tried to clean the cache, delete all canisters, delete localStorage in the browser, etc., but no luck…