Skip to content

Commit

Permalink
Implement Google JWT verification and OpenID Google client id init pa…
Browse files Browse the repository at this point in the history
…rameter. (#2780)

* Implement Google JWT verification and build time environment variables.

* 🤖 cargo-fmt auto-update

* Make env variable optional

* Make env variable optional

* Make env variable optional

* Fix clippy complaints.

* 🤖 cargo-fmt auto-update

* Rewrite Google OpenIdProvider as trait implementation and add more extensive test coverage.

* 🤖 cargo-fmt auto-update

* Rewrite Google OpenIdProvider as trait implementation and add more extensive test coverage.

* Fix integration tests

* Simplify initialize

* Add OpenID to config integration tests

* 🤖 cargo-fmt auto-update

* 🤖 npm run generate auto-update

* Fix clippy

* 🤖 cargo-fmt auto-update

* Fix integration test

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
sea-snake and github-actions[bot] authored Jan 15, 2025
1 parent bd8ac9a commit 760f271
Show file tree
Hide file tree
Showing 16 changed files with 656 additions and 36 deletions.
80 changes: 80 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ serde = "1"
serde_bytes = "0.11"
serde_cbor = "0.11"
sha2 = "0.10"
rsa = "0.9.7"
4 changes: 2 additions & 2 deletions dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"wasm": "internet_identity.wasm.gz",
"build": "bash -c 'II_DEV_CSP=1 II_FETCH_ROOT_KEY=1 II_DUMMY_CAPTCHA=${II_DUMMY_CAPTCHA:-1} scripts/build'",
"init_arg": "(opt record { captcha_config = opt record { max_unsolved_captchas= 50:nat64; captcha_trigger = variant {Static = variant {CaptchaDisabled}}}})",
"shrink" : false
"shrink": false
},
"test_app": {
"type": "custom",
Expand All @@ -20,7 +20,7 @@
"wasm": "demos/vc_issuer/vc_demo_issuer.wasm.gz",
"build": "demos/vc_issuer/build.sh",
"post_install": "bash -c 'demos/vc_issuer/provision'",
"dependencies": [ "internet_identity" ]
"dependencies": ["internet_identity"]
}
},
"defaults": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"private": true,
"license": "SEE LICENSE IN LICENSE.md",
"scripts": {
"dev": "II_FETCH_ROOT_KEY=1 II_DUMMY_CAPTCHA=1 II_OPENID_GOOGLE_CLIENT_ID=45431994619-cbbfgtn7o0pp0dpfcg2l66bc4rcg7qbu.apps.googleusercontent.com vite",
"host": "II_FETCH_ROOT_KEY=1 II_DUMMY_CAPTCHA=1 II_OPENID_GOOGLE_CLIENT_ID=45431994619-cbbfgtn7o0pp0dpfcg2l66bc4rcg7qbu.apps.googleusercontent.com vite --host",
"dev": "II_FETCH_ROOT_KEY=1 II_DUMMY_CAPTCHA=1 II_OPENID_GOOGLE_CLIENT_ID=\"45431994619-cbbfgtn7o0pp0dpfcg2l66bc4rcg7qbu.apps.googleusercontent.com\" vite",
"host": "II_FETCH_ROOT_KEY=1 II_DUMMY_CAPTCHA=1 II_OPENID_GOOGLE_CLIENT_ID=\"45431994619-cbbfgtn7o0pp0dpfcg2l66bc4rcg7qbu.apps.googleusercontent.com\" vite --host",
"showcase": "astro dev --root ./src/showcase",
"build": "tsc --noEmit && vite build",
"check": "tsc --project ./tsconfig.all.json --noEmit",
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/generated/internet_identity_idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const idlFactory = ({ IDL }) => {
'canister_creation_cycles_cost' : IDL.Opt(IDL.Nat64),
'related_origins' : IDL.Opt(IDL.Vec(IDL.Text)),
'captcha_config' : IDL.Opt(CaptchaConfig),
'openid_google_client_id' : IDL.Opt(IDL.Text),
'register_rate_limit' : IDL.Opt(RateLimitConfig),
});
const UserNumber = IDL.Nat64;
Expand Down Expand Up @@ -561,6 +562,7 @@ export const init = ({ IDL }) => {
'canister_creation_cycles_cost' : IDL.Opt(IDL.Nat64),
'related_origins' : IDL.Opt(IDL.Vec(IDL.Text)),
'captcha_config' : IDL.Opt(CaptchaConfig),
'openid_google_client_id' : IDL.Opt(IDL.Text),
'register_rate_limit' : IDL.Opt(RateLimitConfig),
});
return [IDL.Opt(InternetIdentityInit)];
Expand Down
1 change: 1 addition & 0 deletions src/frontend/generated/internet_identity_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export interface InternetIdentityInit {
'canister_creation_cycles_cost' : [] | [bigint],
'related_origins' : [] | [Array<string>],
'captcha_config' : [] | [CaptchaConfig],
'openid_google_client_id' : [] | [string],
'register_rate_limit' : [] | [RateLimitConfig],
}
export interface InternetIdentityStats {
Expand Down
3 changes: 2 additions & 1 deletion src/internet_identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ serde.workspace = true
serde_bytes.workspace = true
serde_cbor.workspace = true
serde_json = { version = "1.0", default-features = false, features = ["std"] }
sha2.workspace = true
sha2 = { workspace = true, features = ["oid"]}
base64.workspace = true
rsa.workspace = true

# Captcha deps
lodepng = "*"
Expand Down
2 changes: 2 additions & 0 deletions src/internet_identity/internet_identity.did
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ type InternetIdentityInit = record {
captcha_config: opt CaptchaConfig;
// Configuration for Related Origins Requests
related_origins: opt vec text;
// Configuration for OpenID Google client
openid_google_client_id: opt text;
};

type ChallengeKey = text;
Expand Down
23 changes: 17 additions & 6 deletions src/internet_identity/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ fn config() -> InternetIdentityInit {
register_rate_limit: Some(persistent_state.registration_rate_limit.clone()),
captcha_config: Some(persistent_state.captcha_config.clone()),
related_origins: persistent_state.related_origins.clone(),
openid_google_client_id: persistent_state.openid_google_client_id.clone(),
})
}

Expand Down Expand Up @@ -387,15 +388,20 @@ fn post_upgrade(maybe_arg: Option<InternetIdentityInit>) {
}

fn initialize(maybe_arg: Option<InternetIdentityInit>) {
let state_related_origins = state::persistent_state(|storage| storage.related_origins.clone());
let related_origins = maybe_arg
.clone()
.map(|arg| arg.related_origins)
.unwrap_or(state_related_origins);
let related_origins = maybe_arg.as_ref().map_or_else(
|| persistent_state(|storage| storage.related_origins.clone()),
|arg| arg.related_origins.clone(),
);
let openid_google_client_id = maybe_arg.as_ref().map_or_else(
|| persistent_state(|storage| storage.openid_google_client_id.clone()),
|arg| arg.openid_google_client_id.clone(),
);
init_assets(related_origins);
apply_install_arg(maybe_arg);
update_root_hash();
openid::setup_timers();
if let Some(client_id) = openid_google_client_id {
openid::setup_google(client_id);
}
}

fn apply_install_arg(maybe_arg: Option<InternetIdentityInit>) {
Expand Down Expand Up @@ -428,6 +434,11 @@ fn apply_install_arg(maybe_arg: Option<InternetIdentityInit>) {
persistent_state.related_origins = Some(related_origins);
})
}
if let Some(openid_google_client_id) = arg.openid_google_client_id {
state::persistent_state_mut(|persistent_state| {
persistent_state.openid_google_client_id = Some(openid_google_client_id);
})
}
}
}

Expand Down
Loading

0 comments on commit 760f271

Please sign in to comment.