···1111 http_client: Arc::clone(&http_client),
1212 });
1313 let doc = resolver.resolve(&Did::new(did).unwrap()).await.unwrap(); // TODO: this is only half the resolution? or is atrium checking dns?
1414+ // tokio::time::sleep(std::time::Duration::from_secs(2)).await;
1415 doc.also_known_as.and_then(|mut aka| {
1516 if aka.is_empty() {
1617 None
+20-7
who-am-i/src/server.rs
···1212use handlebars::{Handlebars, handlebars_helper};
13131414use serde::Deserialize;
1515-use serde_json::{Value, json};
1515+use serde_json::json;
1616use std::sync::Arc;
1717use std::time::Duration;
1818use tokio::net::TcpListener;
···4949 hbs.register_templates_directory("templates", Default::default())
5050 .unwrap();
51515252- handlebars_helper!(json: |v: Value| serde_json::to_string(&v).unwrap());
5252+ handlebars_helper!(json: |v: String| serde_json::to_string(&v).unwrap());
5353 hbs.register_helper("json", Box::new(json));
54545555 // clients have to pick up their identity-resolving tasks within this period
···110110 let task_shutdown = shutdown.child_token();
111111 let fetch_key = resolving.dispatch(resolve_identity(did.clone()), task_shutdown);
112112113113- let json_did = Value::String(did);
114114- let json_fetch_key = Value::String(fetch_key);
115113 RenderHtml(
116114 "prompt-known",
117115 engine,
118116 json!({
119119- "did": json_did,
120120- "fetch_key": json_fetch_key,
117117+ "did": did,
118118+ "fetch_key": fetch_key,
121119 "parent_host": parent_host,
122120 }),
123121 )
···183181 panic!("failed to do client callback");
184182 };
185183 let did = oauth_session.did().await.expect("a did to be present");
184184+186185 let cookie = Cookie::build((DID_COOKIE_KEY, did.to_string()))
187186 .http_only(true)
188187 .secure(true)
189188 .same_site(SameSite::None)
190189 .max_age(std::time::Duration::from_secs(86_400).try_into().unwrap());
190190+191191 let jar = jar.add(cookie);
192192+193193+ let task_shutdown = state.shutdown.child_token();
194194+ let fetch_key = state
195195+ .resolving
196196+ .dispatch(resolve_identity(did.to_string()), task_shutdown);
197197+192198 (
193199 jar,
194194- RenderHtml("authorized", state.engine, json!({ "did": did })),
200200+ RenderHtml(
201201+ "authorized",
202202+ state.engine,
203203+ json!({
204204+ "did": did,
205205+ "fetch_key": fetch_key,
206206+ }),
207207+ ),
195208 )
196209}
+5-1
who-am-i/templates/authorized.hbs
···4455<script>
66// TODO: tie this back to its source...........
77-localStorage.setItem("did", {{{json did}}});
77+88+localStorage.setItem("who-am-i", JSON.stringify({
99+ did: {{{json did}}},
1010+ fetch_key: {{{json fetch_key}}},
1111+}));
812window.close();
913</script>
+44-1
who-am-i/templates/prompt-anon.hbs
···44 <span class="parent-host">{{ parent_host }}</span>?
55</p>
6677+<div id="loader" class="hidden">
88+ <span class="spinner"></span>
99+</div>
1010+711<div id="user-info">
812 <form id="action" action="/auth" method="GET" target="_blank">
913 <label>
···1418</div>
15191620<script>
2121+var loaderEl = document.getElementById('loader');
2222+var infoEl = document.getElementById('user-info');
1723const formEl = document.getElementById('action');
1824const handleEl = document.getElementById('handle');
2525+1926formEl.onsubmit = e => {
2027 e.preventDefault();
2128 // TODO: include expected referer! (..this system is probably bad)
2929+ // maybe a random localstorage key that we specifically listen for?
2230 var url = new URL('/auth', window.location);
2331 url.searchParams.set('handle', handleEl.value);
2432 var flow = window.open(url, '_blank');
2533 window.f = flow;
26342735 window.addEventListener('storage', e => {
2828- location.reload();
3636+ var details = localStorage.getItem("who-am-i");
3737+ if (!details) {
3838+ console.error("hmm, heard from localstorage but did not get DID");
3939+ }
4040+ var parsed = JSON.parse(details);
4141+4242+ infoEl.classList.add('hidden');
4343+ loaderEl.classList.remove('hidden');
4444+ lookUpAndShare(parsed.fetch_key);
2945 });
3046}
4747+4848+function lookUpAndShare(fetch_key) {
4949+ let user_info = new URL('/user-info', window.location);
5050+ user_info.searchParams.set('fetch-key', fetch_key);
5151+ fetch(user_info)
5252+ .then(resp => {
5353+ if (!resp.ok) throw new Error('request failed');
5454+ return resp.json();
5555+ })
5656+ .then(
5757+ ({ handle }) => {
5858+ loaderEl.remove();
5959+ handleEl.textContent = `@${handle}`;
6060+ infoEl.classList.remove('hidden');
6161+ share(handle);
6262+ },
6363+ err => {
6464+ infoEl.textContent = 'ohno';
6565+ console.error(err);
6666+ },
6767+ );
6868+}
6969+7070+function share(handle) {
7171+ top.postMessage({ source: 'whoami', handle }, '*'); // TODO: pass the referrer back from server
7272+}
7373+3174</script>
3275{{/inline}}
3376