@phila/sso-nuxt 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/package.json +21 -0
- package/src/module.ts +84 -0
- package/src/runtime/middleware.auth.ts +16 -0
- package/src/runtime/plugin.client.ts +25 -0
- package/tsconfig.json +15 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 City of Philadelphia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@phila/sso-nuxt",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./src/module.ts"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@nuxt/kit": "^3.0.0",
|
|
10
|
+
"@phila/sso-core": "file:../sso-core",
|
|
11
|
+
"@phila/sso-vue": "file:../sso-vue",
|
|
12
|
+
"defu": "^6.0.0"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"nuxt": "^3.0.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"nuxt": "^3.17.0",
|
|
19
|
+
"typescript": "^5.9.3"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/module.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// ABOUTME: Nuxt module that wires up phila-identity SSO with zero app boilerplate
|
|
2
|
+
// ABOUTME: Installs pinia, registers the client plugin, auto-imports useAuth, and optionally guards routes
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
defineNuxtModule,
|
|
6
|
+
addPlugin,
|
|
7
|
+
addImports,
|
|
8
|
+
addRouteMiddleware,
|
|
9
|
+
installModule,
|
|
10
|
+
createResolver,
|
|
11
|
+
extendViteConfig,
|
|
12
|
+
} from "@nuxt/kit";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { dirname, resolve } from "node:path";
|
|
15
|
+
import { defu } from "defu";
|
|
16
|
+
|
|
17
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
// packages/sso-nuxt/src → packages/sso-nuxt → packages → phila-identity
|
|
19
|
+
const philaIdentityRoot = resolve(__dirname, "../../..");
|
|
20
|
+
|
|
21
|
+
export interface ModuleOptions {
|
|
22
|
+
globalAuth?: boolean;
|
|
23
|
+
loginPath?: string;
|
|
24
|
+
excludePaths?: string[];
|
|
25
|
+
signInPolicy?: string;
|
|
26
|
+
resetPasswordPolicy?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default defineNuxtModule<ModuleOptions>({
|
|
30
|
+
meta: {
|
|
31
|
+
name: "@phila/sso-nuxt",
|
|
32
|
+
configKey: "sso",
|
|
33
|
+
},
|
|
34
|
+
defaults: {
|
|
35
|
+
globalAuth: true,
|
|
36
|
+
loginPath: "/login",
|
|
37
|
+
excludePaths: ["/logout"],
|
|
38
|
+
signInPolicy: "B2C_1A_AD_SIGNIN_ONLY",
|
|
39
|
+
resetPasswordPolicy: "B2C_1A_PASSWORDRESET",
|
|
40
|
+
},
|
|
41
|
+
async setup(options, nuxt) {
|
|
42
|
+
const resolver = createResolver(import.meta.url);
|
|
43
|
+
|
|
44
|
+
// 1. Install @pinia/nuxt so apps don't need to list it explicitly
|
|
45
|
+
await installModule("@pinia/nuxt");
|
|
46
|
+
|
|
47
|
+
// 2. Transpile local file: linked packages so Vite/SSR can process them
|
|
48
|
+
nuxt.options.build.transpile.push("@phila/sso-core", "@phila/sso-vue");
|
|
49
|
+
|
|
50
|
+
// 3. Allow Vite dev server to serve files from phila-identity source tree
|
|
51
|
+
extendViteConfig(config => {
|
|
52
|
+
config.server = config.server ?? {};
|
|
53
|
+
config.server.fs = config.server.fs ?? {};
|
|
54
|
+
config.server.fs.allow = [...(config.server.fs.allow ?? []), philaIdentityRoot];
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// 4 & 5. Declare SSO keys in runtimeConfig.public (env vars override at runtime)
|
|
58
|
+
nuxt.options.runtimeConfig.public = defu(nuxt.options.runtimeConfig.public, {
|
|
59
|
+
ssoClientId: "",
|
|
60
|
+
ssoRedirectUri: "http://localhost:3000",
|
|
61
|
+
ssoTenant: "PhilaB2CDev",
|
|
62
|
+
ssoAuthorityDomain: "PhilaB2CDev.b2clogin.com",
|
|
63
|
+
ssoSignInPolicy: options.signInPolicy,
|
|
64
|
+
ssoResetPasswordPolicy: options.resetPasswordPolicy,
|
|
65
|
+
ssoLoginPath: options.loginPath,
|
|
66
|
+
ssoExcludePaths: options.excludePaths,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// 6. Register client-only plugin that initialises the B2C auth client
|
|
70
|
+
addPlugin({ src: resolver.resolve("./runtime/plugin.client"), mode: "client" });
|
|
71
|
+
|
|
72
|
+
// 7. Auto-import useAuth so components don't need an explicit import
|
|
73
|
+
addImports({ name: "useAuth", as: "useAuth", from: "@phila/sso-vue" });
|
|
74
|
+
|
|
75
|
+
// 8. Optionally register global route guard
|
|
76
|
+
if (options.globalAuth) {
|
|
77
|
+
addRouteMiddleware({
|
|
78
|
+
name: "auth",
|
|
79
|
+
path: resolver.resolve("./runtime/middleware.auth"),
|
|
80
|
+
global: true,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// ABOUTME: Route middleware registered by @phila/sso-nuxt module
|
|
2
|
+
// ABOUTME: Redirects unauthenticated users to the configured login path
|
|
3
|
+
import { useSSOStore } from "@phila/sso-vue";
|
|
4
|
+
|
|
5
|
+
export default defineNuxtRouteMiddleware(to => {
|
|
6
|
+
const config = useRuntimeConfig().public;
|
|
7
|
+
const store = useSSOStore();
|
|
8
|
+
|
|
9
|
+
// Don't redirect while auth is still initialising
|
|
10
|
+
if (!store.authReady) return;
|
|
11
|
+
|
|
12
|
+
const excluded = [config.ssoLoginPath as string, ...(config.ssoExcludePaths as string[])];
|
|
13
|
+
if (excluded.some(p => to.path.startsWith(p))) return;
|
|
14
|
+
|
|
15
|
+
if (!store.isAuthenticated) return navigateTo({ path: config.ssoLoginPath as string });
|
|
16
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// ABOUTME: Client-only Nuxt plugin registered by @phila/sso-nuxt module
|
|
2
|
+
// ABOUTME: Initializes Azure AD B2C authentication on the Nuxt app instance
|
|
3
|
+
import { createSSOPlugin } from "@phila/sso-vue";
|
|
4
|
+
import { B2CProvider } from "@phila/sso-core";
|
|
5
|
+
|
|
6
|
+
export default defineNuxtPlugin(nuxtApp => {
|
|
7
|
+
const config = useRuntimeConfig().public;
|
|
8
|
+
const plugin = createSSOPlugin({
|
|
9
|
+
clientConfig: {
|
|
10
|
+
provider: new B2CProvider({
|
|
11
|
+
clientId: config.ssoClientId as string,
|
|
12
|
+
b2cEnvironment: config.ssoTenant as string,
|
|
13
|
+
authorityDomain: config.ssoAuthorityDomain as string,
|
|
14
|
+
redirectUri: config.ssoRedirectUri as string,
|
|
15
|
+
policies: {
|
|
16
|
+
signUpSignIn: config.ssoSignInPolicy as string,
|
|
17
|
+
signInOnly: config.ssoSignInPolicy as string,
|
|
18
|
+
resetPassword: config.ssoResetPasswordPolicy as string,
|
|
19
|
+
},
|
|
20
|
+
}),
|
|
21
|
+
debug: import.meta.dev,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
nuxtApp.vueApp.use(plugin);
|
|
25
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"moduleResolution": "bundler",
|
|
8
|
+
"allowImportingTsExtensions": true,
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"noEmit": true,
|
|
12
|
+
"strict": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*.ts"]
|
|
15
|
+
}
|