config vite for oauth
This commit is contained in:
parent
b251074253
commit
e53ebcfbfd
3 changed files with 69 additions and 2 deletions
17
src/lib/client-metadata.json
Normal file
17
src/lib/client-metadata.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"client_id": "woach",
|
||||
"client_name": "Woach",
|
||||
"client_uri": "https://woach.me",
|
||||
"redirect_uris": ["https://woach.me/callback"],
|
||||
"application_type": "web",
|
||||
"dpop_bound_access_tokens": true,
|
||||
"grant_types": [
|
||||
"authorization_code",
|
||||
"refresh_token"
|
||||
],
|
||||
"response_types": [
|
||||
"code"
|
||||
],
|
||||
"scope": "atproto transition:chat.bsky transition:generic",
|
||||
"token_endpoint_auth_method": "none"
|
||||
}
|
||||
13
src/vite-env.d.ts
vendored
Normal file
13
src/vite-env.d.ts
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_DEV_SERVER_PORT?: string;
|
||||
readonly VITE_CLIENT_URI: string;
|
||||
readonly VITE_OAUTH_CLIENT_ID: string;
|
||||
readonly VITE_OAUTH_REDIRECT_URI: string;
|
||||
readonly VITE_OAUTH_SCOPE: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
||||
|
|
@ -1,7 +1,44 @@
|
|||
import tailwindcss from '@tailwindcss/vite';
|
||||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import { defineConfig } from 'vite';
|
||||
import metadata from './src/lib/client-metadata.json' with { type: 'json' };
|
||||
|
||||
const SERVER_HOST = '127.0.0.1';
|
||||
const SERVER_PORT = 12520;
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [tailwindcss(), sveltekit()]
|
||||
server: {
|
||||
host: SERVER_HOST,
|
||||
port: SERVER_PORT
|
||||
},
|
||||
plugins: [
|
||||
sveltekit(),
|
||||
tailwindcss(),
|
||||
{
|
||||
name: 'oauth-env-injection',
|
||||
config(_conf, { command }) {
|
||||
if (command === 'build') {
|
||||
process.env.VITE_OAUTH_CLIENT_ID = metadata.client_id;
|
||||
process.env.VITE_OAUTH_REDIRECT_URI = metadata.redirect_uris[0];
|
||||
} else {
|
||||
const redirectUri = (() => {
|
||||
const url = new URL(metadata.redirect_uris[0]);
|
||||
return `http://${SERVER_HOST}:${SERVER_PORT}${url.pathname}`;
|
||||
})();
|
||||
|
||||
const clientId =
|
||||
`http://localhost` +
|
||||
`?redirect_uri=${encodeURIComponent(redirectUri)}` +
|
||||
`&scope=${encodeURIComponent(metadata.scope)}`;
|
||||
|
||||
process.env.VITE_DEV_SERVER_PORT = '' + SERVER_PORT;
|
||||
process.env.VITE_OAUTH_CLIENT_ID = clientId;
|
||||
process.env.VITE_OAUTH_REDIRECT_URI = redirectUri;
|
||||
}
|
||||
|
||||
process.env.VITE_CLIENT_URI = metadata.client_uri;
|
||||
process.env.VITE_OAUTH_SCOPE = metadata.scope;
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue