Skip to content

Commit

Permalink
oauth progress
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Aug 12, 2024
1 parent 3e4a447 commit 7e20d69
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 88 deletions.
138 changes: 69 additions & 69 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ itertools = { version = "0.13.0", default-features = false }
moka = { version = "=0.12.7", features = ["sync"] }
simdutf8 = { version = "0.1.4", features = ["aarch64_neon"] }
sonic-rs = "0.3.10"
syn = "=2.0.72"
triomphe = { version = "0.1.13", default-features = false, features = [
"unsize",
] }
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-derive/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0.86"
quote = "1.0.36"
syn = { workspace = true, features = ["full"] }
syn = { version = "2.0.74", features = ["full"] }

[lints]
workspace = true
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
packages = rec {
default = main;

devenv-up = self.devShells.${system}.default.config.procfileScript;

cli = craneLib.buildPackage (
commonArgs
// {
Expand Down
1 change: 1 addition & 0 deletions kitsune-fe/package-lock.json

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

24 changes: 12 additions & 12 deletions kitsune-fe/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { HoudiniClient } from '$houdini';
import { HoudiniClient, getClientSession } from '$houdini';
import { houdiniPlugin as authPlugin } from '$lib/oauth/auth.svelte';

export default new HoudiniClient({
url: `${import.meta.env.VITE_BACKEND_URL ?? ''}/graphql`

// uncomment this to configure the network call (for things like authentication)
// for more information, please visit here: https://www.houdinigraphql.com/guides/authentication
// fetchParams({ session }) {
// return {
// headers: {
// Authentication: `Bearer ${session.token}`,
// }
// }
// }
url: `${import.meta.env.VITE_BACKEND_URL ?? ''}/graphql`,
plugins: [authPlugin],
fetchParams(wha) {

Check warning on line 7 in kitsune-fe/src/client.ts

View workflow job for this annotation

GitHub Actions / Spell-check repository source

"wha" should be "what".
const session = getClientSession();
return {
headers: {
...session.headers
}
};
}
});
12 changes: 12 additions & 0 deletions kitsune-fe/src/lib/oauth/auth.svelte.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { setClientSession, type ClientPlugin } from '$houdini';

const houdiniPlugin: ClientPlugin = () => {
return {
async start(ctx, { next }) {
setClientSession({ headers: { owo: 'uwu' } });
next(ctx);
}
};
};

export { houdiniPlugin };
76 changes: 76 additions & 0 deletions kitsune-fe/src/lib/oauth/client.svelte.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { RegisterOAuthAppStore } from '$houdini';

import { readable, type Readable } from 'svelte/store';
import { z } from 'zod';

const OAUTH_STORAGE_KEY = 'oauth_app';
const OAUTH_APP_SCHEMA = z.object({
id: z.string().min(1),
secret: z.string().min(1)
});

const REGISTER_APP = new RegisterOAuthAppStore();

type OAuthApplicationTy = z.infer<typeof OAUTH_APP_SCHEMA>;

async function registerOAuthApp(): Promise<OAuthApplicationTy> {
const redirectUri = `${window.location.origin}/oauth-callback`;

try {
const response = await REGISTER_APP.mutate({
redirectUri
});

if (response.errors) {
throw new Error(response.errors.map((error) => error.message).join('\n'));
}

// If we don't have any errors, we can assume the data is well formed.
// And if the data isn't well formed, then we're fucked anyways.

return response.data!.registerOauthApplication;
} catch (error) {
console.error(`Failed to register OAuth app: ${error}`);
throw error;
}
}

async function registerAndStore(): Promise<void> {
const oauthApp = await registerOAuthApp();
localStorage.setItem(OAUTH_STORAGE_KEY, JSON.stringify(oauthApp));
}

async function loadOAuthApp(): Promise<OAuthApplicationTy> {
const rawApp = localStorage.getItem(OAUTH_STORAGE_KEY);

if (rawApp) {
try {
return OAUTH_APP_SCHEMA.parseAsync(JSON.parse(rawApp));
} catch (error) {
console.error(`Failed to load OAuth app. Error: ${error}`);
console.error(`Registering new..`);

await registerAndStore();
return await loadOAuthApp();
}
} else {
await registerAndStore();
return await loadOAuthApp();
}
}

class OAuthApplication {
#data = $state<OAuthApplicationTy | undefined>();

get data() {
return this.#data;
}

constructor() {
loadOAuthApp()
.then((loadedApp) => (this.#data = loadedApp))
.catch(console.error);
}
}

export { OAuthApplication };
2 changes: 1 addition & 1 deletion lib/geomjeungja/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ unsize = "1.1.0"
[dev-dependencies]
insta = { version = "1.39.0", features = ["json"] }
rand_xorshift = "0.3.0"
serde_json = "1.0.122"
serde_json = "1.0.124"
tokio = { version = "1.39.2", features = ["macros", "rt"] }

[lints]
Expand Down
4 changes: 2 additions & 2 deletions lib/mrf-manifest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ olpc-cjson = { version = "0.1.3", optional = true }
schemars = { version = "0.8.21", features = ["impl_json_schema", "semver"] }
semver = { version = "1.0.23", features = ["serde"] }
serde = { version = "1.0.206", features = ["derive"] }
serde_json = { version = "1.0.122", optional = true }
serde_json = { version = "1.0.124", optional = true }
sonic-rs = { workspace = true, optional = true }
thiserror = { version = "1.0.63", optional = true }
wasm-encoder = { version = "0.215.0", optional = true }
wasmparser = { version = "0.215.0", optional = true }

[dev-dependencies]
serde_json = "1.0.122"
serde_json = "1.0.124"
insta = { version = "1.39.0", default-features = false, features = ["json"] }
wat = "1.215.0"

Expand Down
4 changes: 2 additions & 2 deletions lib/mrf-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ mrf-manifest = { workspace = true, features = [
"encode",
"serialise",
] }
serde_json = "1.0.122"
serde_json = "1.0.124"
wasmparser = "0.215.0"

[lints]
workspace = true

[dev-dependencies]
serde_json = "1.0.122"
serde_json = "1.0.124"
wat = "1.215.0"

0 comments on commit 7e20d69

Please sign in to comment.