Skip to content

Commit c82a931

Browse files
authored
Merge branch 'main' into sea-snake/verified-email
2 parents a01a9c9 + 38c745c commit c82a931

File tree

8 files changed

+71
-102
lines changed

8 files changed

+71
-102
lines changed

.github/workflows/canister-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ jobs:
528528
# NOTE: dfx install will run the postinstall scripts from dfx.json
529529
dfx canister install internet_identity --wasm internet_identity_test.wasm.gz --argument "(opt record { captcha_config = opt record { max_unsolved_captchas= 50:nat64; captcha_trigger = variant {Static = variant { CaptchaDisabled }}}; related_origins = opt vec { \"https://id.ai\"; \"https://identity.ic0.app\"; \"https://identity.internetcomputer.org\" }; new_flow_origins = opt vec { \"https://id.ai\" }; dummy_auth = opt opt record { prompt_for_index = true }; openid_configs = opt vec { ${{ steps.openid-configs.outputs.OPENID_CONFIGS }} } })"
530530
if [ "${{ matrix.canister == 'split' }}" = "true" ]; then
531-
dfx canister install internet_identity_frontend --wasm internet_identity_frontend_test.wasm.gz
531+
II_CANISTER_ID=$(dfx canister id internet_identity)
532+
dfx canister install internet_identity_frontend --wasm internet_identity_frontend_test.wasm.gz --argument "(record { backend_canister_id = principal \"$II_CANISTER_ID\"; backend_origin = \"https://backend.id.ai\"; related_origins = opt vec { \"https://id.ai\"; \"https://identity.ic0.app\"; \"https://identity.internetcomputer.org\" }; dummy_auth = opt opt record { prompt_for_index = true } })"
532533
fi
533534
dfx canister install test_app --wasm demos/test-app/test_app.wasm
534535

dfx.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"candid": "src/internet_identity_frontend/internet_identity_frontend.did",
66
"wasm": "internet_identity_frontend.wasm.gz",
77
"build": "bash -c 'II_DEV_CSP=1 II_FETCH_ROOT_KEY=1 II_DUMMY_CAPTCHA=${II_DUMMY_CAPTCHA:-1} scripts/build --frontend'",
8+
"init_arg_file": "src/internet_identity_frontend/local_test_arg.did",
89
"shrink": false
910
},
1011
"internet_identity": {
@@ -27,9 +28,7 @@
2728
"wasm": "demos/vc_issuer/vc_demo_issuer.wasm.gz",
2829
"build": "demos/vc_issuer/build.sh",
2930
"post_install": "bash -c 'demos/vc_issuer/provision'",
30-
"dependencies": [
31-
"internet_identity"
32-
]
31+
"dependencies": ["internet_identity"]
3332
}
3433
},
3534
"defaults": {
@@ -39,4 +38,4 @@
3938
},
4039
"dfx": "0.29.0",
4140
"version": 1
42-
}
41+
}

src/frontend/src/lib/legacy/flows/dappsExplorer/dapps.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,13 @@
631631
"name": "Demo App",
632632
"oneLiner": "Experience next-gen decentralized authentication.",
633633
"website": "https://try.id.ai",
634-
"logo": "try-id-ai.svg"
634+
"authOrigins": [
635+
"https://try.id.ai",
636+
"https://vt36r-2qaaa-aaaad-aad5a-cai.icp0.io",
637+
"https://4mteh-mqaaa-aaaad-adnaa-cai.icp0.io"
638+
],
639+
"logo": "try-id-ai.svg",
640+
"certified_attributes": true
635641
},
636642
{
637643
"name": "Caffeine",
@@ -645,12 +651,5 @@
645651
"logo": "caffeine_logo.svg",
646652
"logoDark": "caffeine_logo_dark.svg",
647653
"certified_attributes": true
648-
},
649-
{
650-
"name": "Direct OpenID Sign-In",
651-
"oneLiner": "Direct OpenID sign-in test app",
652-
"website": "https://4mteh-mqaaa-aaaad-adnaa-cai.icp0.io",
653-
"logo": "try-id-ai.svg",
654-
"certified_attributes": true
655654
}
656655
]

src/internet_identity_frontend/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internet_identity_interface.workspace = true
99
serde_bytes.workspace = true
1010

1111
# IC canister dependencies
12-
candid.workspace = true
12+
candid = { workspace = true, features = ["value"] }
1313
ic-cdk.workspace = true
1414
ic-cdk-macros.workspace = true
1515

src/internet_identity_frontend/internet_identity_frontend.did

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,15 @@ type DummyAuthConfig = record {
4747
prompt_for_index : bool;
4848
};
4949

50-
type OpenIdConfig = record {
51-
name : text;
52-
logo : text;
53-
issuer : text;
54-
client_id : text;
55-
jwks_uri : text;
56-
auth_uri : text;
57-
auth_scope : vec text;
58-
fedcm_uri : opt text;
59-
};
60-
6150
type InternetIdentityFrontendInit = record {
62-
backend_canister_id : opt principal;
63-
backend_origin : opt text;
51+
backend_canister_id : principal;
52+
backend_origin : text;
6453
related_origins : opt vec text;
6554
fetch_root_key : opt bool;
6655
analytics_config : opt opt AnalyticsConfig;
6756
dummy_auth : opt opt DummyAuthConfig;
68-
openid_configs : opt vec OpenIdConfig;
6957
};
7058

71-
service : (opt InternetIdentityFrontendInit) -> {
59+
service : (InternetIdentityFrontendInit) -> {
7260
http_request : (request : HttpRequest) -> (HttpResponse) query;
7361
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(
2+
record {
3+
backend_canister_id = principal "uxrrr-q7777-77774-qaaaq-cai";
4+
backend_origin = "http://uxrrr-q7777-77774-qaaaq-cai.localhost:4943";
5+
related_origins = opt vec {
6+
"http://u6s2n-gx777-77774-qaaba-cai.localhost:4943";
7+
};
8+
fetch_root_key = null;
9+
analytics_config = null;
10+
dummy_auth = null;
11+
},
12+
)

src/internet_identity_frontend/src/main.rs

Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
use asset_util::{collect_assets, Asset as AssetUtilAsset, ContentEncoding, ContentType};
22
use base64::engine::general_purpose::STANDARD as BASE64;
33
use base64::Engine;
4-
use candid::{Encode, Principal};
4+
use candid::{Encode, IDLValue};
55
use flate2::read::GzDecoder;
66
use ic_asset_certification::{Asset, AssetConfig, AssetEncoding, AssetRouter};
77
use ic_cdk::{init, post_upgrade};
88
use ic_cdk_macros::query;
99
use ic_http_certification::{HeaderField, HttpCertificationTree, HttpRequest, HttpResponse};
1010
use include_dir::{include_dir, Dir};
1111
use internet_identity_interface::internet_identity::types::{
12-
DummyAuthConfig, InternetIdentityFrontendInit, InternetIdentityInit,
12+
InternetIdentityFrontendArgs, InternetIdentityInit,
1313
};
14-
use lazy_static::lazy_static;
1514
use serde_json::json;
1615
use sha2::Digest;
1716
use std::io::Read;
@@ -25,56 +24,19 @@ thread_local! {
2524
static ASSETS_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/../../dist");
2625
const IMMUTABLE_ASSET_CACHE_CONTROL: &str = "public, max-age=31536000, immutable";
2726
const NO_CACHE_ASSET_CACHE_CONTROL: &str = "public, no-cache, no-store";
28-
const MISSING_MANDATORY_INTERNET_IDENTITY_FRONTEND_INSTALL_ARGS_HTML_ERROR: &str =
29-
"<!doctype html>\
30-
<html>\
31-
<head><title>Internet Identity Frontend Initialization Error</title></head>\
32-
<body><h1>Internet Identity Frontend Initialization Error</h1>\
33-
<p>
34-
Please initialize this canister with the following required install args:
35-
<ul>
36-
<li>backend_canister_id</li>
37-
<li>backend_origin</li>
38-
</ul>
39-
</p>\
40-
</body></html>";
41-
42-
// Default configuration for the frontend canister
43-
lazy_static! {
44-
// TODO: Change this to the mainnet value `rdmx6-jaaaa-aaaaa-aaadq-cai` before deploying to mainnet.
45-
static ref DEFAULT_INTERNET_IDENTITY_BACKEND_CANISTER_ID: Principal =
46-
Principal::from_text("uxrrr-q7777-77774-qaaaq-cai").unwrap();
47-
48-
static ref DEFAULT_CONFIG: InternetIdentityFrontendInit = InternetIdentityFrontendInit {
49-
backend_canister_id: Some(*DEFAULT_INTERNET_IDENTITY_BACKEND_CANISTER_ID),
50-
backend_origin: Some("https://backend.id.ai".to_string()),
51-
related_origins: Some(vec![
52-
"https://id.ai".to_string(),
53-
"https://identity.internetcomputer.org".to_string(),
54-
"https://identity.ic0.app".to_string(),
55-
]),
56-
openid_configs: None,
57-
dummy_auth: Some(Some(DummyAuthConfig {
58-
prompt_for_index: true
59-
})),
60-
fetch_root_key: None,
61-
analytics_config: None,
62-
};
63-
}
6427

6528
#[init]
66-
fn init(init_arg: Option<InternetIdentityFrontendInit>) {
67-
let config = init_arg.unwrap_or_else(|| DEFAULT_CONFIG.clone());
68-
certify_all_assets(config);
29+
fn init(args: InternetIdentityFrontendArgs) {
30+
certify_all_assets(args);
6931
}
7032

7133
#[post_upgrade]
72-
fn post_upgrade() {
73-
init(None);
34+
fn post_upgrade(args: InternetIdentityFrontendArgs) {
35+
certify_all_assets(args);
7436
}
7537

76-
fn certify_all_assets(init: InternetIdentityFrontendInit) {
77-
let static_assets = get_static_assets(&init);
38+
fn certify_all_assets(args: InternetIdentityFrontendArgs) {
39+
let static_assets = get_static_assets(&args);
7840

7941
// 2. Extract integrity hashes for inline scripts from HTML files
8042
let integrity_hashes = static_assets
@@ -137,7 +99,7 @@ fn certify_all_assets(init: InternetIdentityFrontendInit) {
13799
vec![AssetEncoding::Identity.default_config()]
138100
};
139101

140-
let headers = if path.starts_with("_app/immutable") {
102+
let headers = if path.starts_with("/_app/immutable") {
141103
(
142104
"cache-control".to_string(),
143105
IMMUTABLE_ASSET_CACHE_CONTROL.to_string(),
@@ -333,7 +295,7 @@ fn get_content_security_policy(integrity_hashes: Vec<String>) -> String {
333295
}
334296

335297
/// Gets the static assets with HTML fixup and well-known endpoints
336-
fn get_static_assets(config: &InternetIdentityFrontendInit) -> Vec<AssetUtilAsset> {
298+
fn get_static_assets(config: &InternetIdentityFrontendArgs) -> Vec<AssetUtilAsset> {
337299
// Collect assets and fix up HTML files
338300
let mut assets: Vec<AssetUtilAsset> = collect_assets(&ASSETS_DIR, None)
339301
.into_iter()
@@ -347,6 +309,18 @@ fn get_static_assets(config: &InternetIdentityFrontendInit) -> Vec<AssetUtilAsse
347309
})
348310
.collect();
349311

312+
// Serve the initialization argument of this canister as a Candid file
313+
assets.push(AssetUtilAsset {
314+
url_path: "/.config".to_string(),
315+
content: IDLValue::try_from_candid_type(config)
316+
.unwrap()
317+
.to_string()
318+
.as_bytes()
319+
.to_vec(),
320+
encoding: ContentEncoding::Identity,
321+
content_type: ContentType::TXT,
322+
});
323+
350324
// Add .well-known/ic-domains for custom domain support
351325
let ic_domains_content = b"identity.internetcomputer.org\nbeta.identity.ic0.app\nbeta.identity.internetcomputer.org\nid.ai\nbeta.id.ai\nwww.id.ai".to_vec();
352326
assets.push(AssetUtilAsset {
@@ -375,18 +349,14 @@ fn get_static_assets(config: &InternetIdentityFrontendInit) -> Vec<AssetUtilAsse
375349
}
376350

377351
/// Fix up HTML pages by injecting canister ID and canister config
378-
fn fixup_html(html: &str, config: &InternetIdentityFrontendInit) -> String {
379-
// The backend canister ID is now included in the config, but we also set data-canister-id for backward compatibility.
380-
let (Some(backend_canister_id), Some(backend_origin)) =
381-
(&config.backend_canister_id, &config.backend_origin)
382-
else {
383-
return MISSING_MANDATORY_INTERNET_IDENTITY_FRONTEND_INSTALL_ARGS_HTML_ERROR.to_string();
384-
};
352+
fn fixup_html(html: &str, config: &InternetIdentityFrontendArgs) -> String {
353+
let backend_canister_id = config.backend_canister_id;
354+
let backend_origin = config.backend_origin.clone();
385355

386356
let html = html.replace(
387357
"</head>",
388358
&format!(
389-
r#"<link rel="preload" href="{backend_origin}/.config.did.bin" as="fetch"></head>"#,
359+
r#"<link rel="preload" href="{backend_origin}/.config.did.bin" crossorigin="anonymous" fetchpriority="high" as="fetch"></head>"#,
390360
),
391361
);
392362

@@ -395,10 +365,11 @@ fn fixup_html(html: &str, config: &InternetIdentityFrontendInit) -> String {
395365
let config = InternetIdentityInit::from(config.clone());
396366
let encoded_config = BASE64.encode(Encode!(&config).unwrap());
397367

368+
// The backend canister ID is now included in the config, but we also set data-canister-id for backward compatibility.
398369
let html = html.replace(
399370
r#"<body "#,
400371
&format!(
401-
r#"<body data-canister-id="{backend_canister_id}" data-canister-config="{encoded_config}" "#
372+
r#"<body data-canister-id="{backend_canister_id}" data-canister-config="{encoded_config}" "#,
402373
),
403374
);
404375

src/internet_identity_interface/src/internet_identity/types.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,41 +207,40 @@ pub struct AnchorCredentials {
207207
///
208208
/// Some fields, like `analytics_config`, have an additional nested `Option<>`, this indicates
209209
/// enable/disable status (e.g. `Some(None)` disables a feature while `None` leaves it untouched).
210-
#[derive(Clone, Debug, CandidType, Deserialize, Default, Eq, PartialEq)]
211-
pub struct InternetIdentityFrontendInit {
212-
pub backend_canister_id: Option<Principal>,
210+
#[derive(Clone, Debug, CandidType, Serialize, Deserialize, Eq, PartialEq)]
211+
pub struct InternetIdentityFrontendArgs {
212+
pub backend_canister_id: Principal,
213213
/// For example, "https://backend.id.ai" (no trailing slash)
214-
pub backend_origin: Option<String>,
214+
pub backend_origin: String,
215+
215216
pub related_origins: Option<Vec<String>>,
216-
pub openid_configs: Option<Vec<OpenIdConfig>>,
217217
pub fetch_root_key: Option<bool>,
218218
pub analytics_config: Option<Option<AnalyticsConfig>>,
219219
pub dummy_auth: Option<Option<DummyAuthConfig>>,
220220
}
221221

222-
impl From<InternetIdentityFrontendInit> for InternetIdentityInit {
223-
fn from(value: InternetIdentityFrontendInit) -> Self {
224-
let InternetIdentityFrontendInit {
222+
impl From<InternetIdentityFrontendArgs> for InternetIdentityInit {
223+
fn from(value: InternetIdentityFrontendArgs) -> Self {
224+
let InternetIdentityFrontendArgs {
225225
backend_canister_id,
226226
backend_origin,
227227
fetch_root_key,
228228
analytics_config,
229229
dummy_auth,
230230
related_origins,
231-
openid_configs,
232231
} = value;
233232

234233
Self {
235-
backend_canister_id,
236-
backend_origin,
234+
backend_canister_id: Some(backend_canister_id),
235+
backend_origin: Some(backend_origin),
237236

238237
fetch_root_key,
239238
analytics_config,
240239
dummy_auth,
241240
related_origins,
242241

243-
// TODO: pull this config field from the backend and set it to None here.
244-
openid_configs,
242+
// This config field is pulled in the frontend from the backend
243+
openid_configs: None,
245244

246245
// Config fields not used by the frontend
247246
canister_creation_cycles_cost: None,
@@ -340,7 +339,7 @@ pub struct CaptchaConfig {
340339
pub captcha_trigger: CaptchaTrigger,
341340
}
342341

343-
#[derive(Clone, Debug, CandidType, Deserialize, Eq, PartialEq)]
342+
#[derive(Clone, Debug, CandidType, Serialize, Deserialize, Eq, PartialEq)]
344343
pub enum AnalyticsConfig {
345344
Plausible {
346345
// Config params from Plausible NPM package
@@ -398,7 +397,7 @@ pub enum OpenIdEmailVerification {
398397
Microsoft,
399398
}
400399

401-
#[derive(Clone, Debug, CandidType, Deserialize, Default, Eq, PartialEq)]
400+
#[derive(Clone, Debug, CandidType, Serialize, Deserialize, Default, Eq, PartialEq)]
402401
pub struct OpenIdConfig {
403402
pub name: String,
404403
pub logo: String,
@@ -512,7 +511,7 @@ pub enum AccountNameValidationError {
512511
NameTooLong,
513512
}
514513

515-
#[derive(Clone, Debug, CandidType, Deserialize, Default, Eq, PartialEq)]
514+
#[derive(Clone, Debug, CandidType, Serialize, Deserialize, Default, Eq, PartialEq)]
516515
pub struct DummyAuthConfig {
517516
pub prompt_for_index: bool,
518517
}

0 commit comments

Comments
 (0)