@phila/sso-vue 0.0.3 → 0.0.4
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/README.md +167 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# @phila/sso-vue
|
|
2
|
+
|
|
3
|
+
Vue 3 adapter for `@phila/sso-core`. Provides a Vue plugin, Pinia store, and composables for Azure AD B2C authentication.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @phila/sso-vue @phila/sso-core @azure/msal-browser pinia
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start (Vite + B2C)
|
|
12
|
+
|
|
13
|
+
The `createB2CPlugin` factory reads `VITE_SSO_*` environment variables automatically:
|
|
14
|
+
|
|
15
|
+
```env
|
|
16
|
+
VITE_SSO_CLIENT_ID=your-client-id
|
|
17
|
+
VITE_SSO_TENANT=YourTenant
|
|
18
|
+
VITE_SSO_AUTHORITY_DOMAIN=YourTenant.b2clogin.com
|
|
19
|
+
VITE_SSO_REDIRECT_URI=http://localhost:3000
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
// main.ts
|
|
24
|
+
import { createApp } from "vue";
|
|
25
|
+
import { createPinia } from "pinia";
|
|
26
|
+
import { createB2CPlugin } from "@phila/sso-vue";
|
|
27
|
+
import App from "./App.vue";
|
|
28
|
+
|
|
29
|
+
const app = createApp(App);
|
|
30
|
+
app.use(createPinia());
|
|
31
|
+
app.use(createB2CPlugin());
|
|
32
|
+
app.mount("#app");
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```vue
|
|
36
|
+
<!-- App.vue -->
|
|
37
|
+
<script setup lang="ts">
|
|
38
|
+
import { useAuth } from "@phila/sso-vue";
|
|
39
|
+
|
|
40
|
+
const { isAuthenticated, userName, authReady, signIn, signOut } = useAuth();
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<template>
|
|
44
|
+
<div v-if="!authReady">Loading...</div>
|
|
45
|
+
<div v-else-if="isAuthenticated">
|
|
46
|
+
<p>Welcome, {{ userName }}</p>
|
|
47
|
+
<button @click="signOut()">Sign out</button>
|
|
48
|
+
</div>
|
|
49
|
+
<div v-else>
|
|
50
|
+
<button @click="signIn()">Sign in</button>
|
|
51
|
+
</div>
|
|
52
|
+
</template>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Advanced Setup
|
|
56
|
+
|
|
57
|
+
For full control over the provider configuration:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { createSSOPlugin } from "@phila/sso-vue";
|
|
61
|
+
import { B2CProvider } from "@phila/sso-core";
|
|
62
|
+
|
|
63
|
+
app.use(
|
|
64
|
+
createSSOPlugin({
|
|
65
|
+
clientConfig: {
|
|
66
|
+
provider: new B2CProvider({
|
|
67
|
+
clientId: "your-client-id",
|
|
68
|
+
b2cEnvironment: "YourTenant",
|
|
69
|
+
authorityDomain: "YourTenant.b2clogin.com",
|
|
70
|
+
redirectUri: "http://localhost:3000",
|
|
71
|
+
apiScopes: ["https://YourTenant.onmicrosoft.com/api/read"],
|
|
72
|
+
policies: {
|
|
73
|
+
signUpSignIn: "B2C_1A_SIGNUP_SIGNIN",
|
|
74
|
+
signInOnly: "B2C_1A_AD_SIGNIN_ONLY",
|
|
75
|
+
resetPassword: "B2C_1A_PASSWORDRESET",
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
debug: true,
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Plugin Options
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
interface SSOPluginOptions {
|
|
88
|
+
clientConfig: SSOClientConfig;
|
|
89
|
+
autoInitialize?: boolean; // default: true
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Composables
|
|
94
|
+
|
|
95
|
+
### `useAuth()`
|
|
96
|
+
|
|
97
|
+
Primary composable for authentication. Must be called after the plugin is installed.
|
|
98
|
+
|
|
99
|
+
**Reactive state:**
|
|
100
|
+
|
|
101
|
+
| Property | Type | Description |
|
|
102
|
+
| ----------------- | ----------------------------- | ------------------------------ |
|
|
103
|
+
| `isAuthenticated` | `Ref<boolean>` | User is signed in |
|
|
104
|
+
| `isLoading` | `Ref<boolean>` | Auth operation in progress |
|
|
105
|
+
| `user` | `Ref<AccountInfo \| null>` | MSAL account info |
|
|
106
|
+
| `token` | `Ref<string \| null>` | Current access token |
|
|
107
|
+
| `error` | `Ref<Error \| null>` | Last auth error |
|
|
108
|
+
| `activePolicy` | `Ref<string \| null>` | Active B2C policy |
|
|
109
|
+
| `authReady` | `Ref<boolean>` | Initialization complete |
|
|
110
|
+
| `userName` | `ComputedRef<string \| null>` | Display name from token claims |
|
|
111
|
+
|
|
112
|
+
**Actions:**
|
|
113
|
+
|
|
114
|
+
| Method | Returns | Description |
|
|
115
|
+
| ------------------------------ | ------------------------- | -------------------------------- |
|
|
116
|
+
| `signIn(options?)` | `Promise<void>` | Start sign-in flow |
|
|
117
|
+
| `signInCityEmployee(options?)` | `Promise<void>` | Sign in with sign-in-only policy |
|
|
118
|
+
| `signOut(options?)` | `Promise<void>` | Sign out |
|
|
119
|
+
| `forgotPassword()` | `Promise<void>` | Start password reset |
|
|
120
|
+
| `acquireToken(options?)` | `Promise<string \| null>` | Get access token |
|
|
121
|
+
|
|
122
|
+
**Utilities:**
|
|
123
|
+
|
|
124
|
+
| Method | Returns | Description |
|
|
125
|
+
| --------------- | --------- | ------------------------------------------------------- |
|
|
126
|
+
| `hasRole(role)` | `boolean` | Check user role from `roles` or `extension_Roles` claim |
|
|
127
|
+
|
|
128
|
+
### `useSSOClient()`
|
|
129
|
+
|
|
130
|
+
Returns the raw `SSOClient` instance for advanced use cases (direct event subscription, etc.).
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
const client = useSSOClient();
|
|
134
|
+
client.events.on("auth:tokenAcquired", token => {
|
|
135
|
+
/* ... */
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### `useSSOStore()`
|
|
140
|
+
|
|
141
|
+
Direct access to the Pinia store. Useful when you need store-level reactivity outside of components.
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import { useSSOStore } from "@phila/sso-vue";
|
|
145
|
+
|
|
146
|
+
const store = useSSOStore();
|
|
147
|
+
watch(
|
|
148
|
+
() => store.isAuthenticated,
|
|
149
|
+
val => {
|
|
150
|
+
/* ... */
|
|
151
|
+
},
|
|
152
|
+
);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## `createB2CPlugin` Options
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
interface B2CPluginOptions {
|
|
159
|
+
signInPolicy?: string; // default: "B2C_1A_AD_SIGNIN_ONLY"
|
|
160
|
+
resetPasswordPolicy?: string; // default: "B2C_1A_PASSWORDRESET"
|
|
161
|
+
debug?: boolean; // default: import.meta.env.DEV
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
|
|
167
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phila/sso-vue",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vue 3 adapter for @phila/sso-core",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"author": "City of Philadelphia",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@phila/sso-core": "0.0.
|
|
29
|
+
"@phila/sso-core": "0.0.4"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"vue": "^3.0.0",
|