@moreillon/vue-oidc 0.0.6 → 0.0.8

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.
@@ -1,4 +1,81 @@
1
+ import type OidcClient from "@moreillon/oidc-auth";
2
+ declare function login(): () => void;
3
+ declare function logout(): () => void;
1
4
  export default function (): {
5
+ client: import("vue").Ref<{
6
+ cookieName: string;
7
+ options: {
8
+ redirect_uri: string;
9
+ authority: string;
10
+ client_id: string;
11
+ extraQueryParams?: {
12
+ [key: string]: string;
13
+ } | undefined;
14
+ };
15
+ openidConfig?: {
16
+ authorization_endpoint: string;
17
+ token_endpoint: string;
18
+ userinfo_endpoint: string;
19
+ end_session_endpoint: string;
20
+ } | undefined;
21
+ refreshEventHandlers: Function[];
22
+ init: (enforce?: boolean) => Promise<import("@moreillon/oidc-auth").InitOutput | undefined>;
23
+ sendUserToAuthUrl: (saveHref: Boolean) => Promise<void>;
24
+ fetchOidcConfig: () => Promise<any>;
25
+ generateAuthUrl: () => Promise<string>;
26
+ createTimeoutForTokenExpiry: (oidConfig: import("@moreillon/oidc-auth").OidcConfig) => void;
27
+ makeCookieOptions: () => string;
28
+ makeExpiryDate: (expires_in: number) => Date;
29
+ isExpired: (expires_at: string) => boolean;
30
+ saveAuthDataInCookies: (data: {
31
+ expires_in: number;
32
+ }) => void;
33
+ exchangeCodeForToken: (code: string) => Promise<void>;
34
+ getUser: () => Promise<any>;
35
+ refreshAccessToken: (oidcConfig: import("@moreillon/oidc-auth").OidcConfig) => Promise<void>;
36
+ onTokenRefreshed: (handler: (oidcData: import("@moreillon/oidc-auth").Tokens) => void) => void;
37
+ runRefreshEventHandlers: (newTokens: import("@moreillon/oidc-auth").Tokens) => void;
38
+ login: () => void;
39
+ logout: () => void;
40
+ } | null, OidcClient | {
41
+ cookieName: string;
42
+ options: {
43
+ redirect_uri: string;
44
+ authority: string;
45
+ client_id: string;
46
+ extraQueryParams?: {
47
+ [key: string]: string;
48
+ } | undefined;
49
+ };
50
+ openidConfig?: {
51
+ authorization_endpoint: string;
52
+ token_endpoint: string;
53
+ userinfo_endpoint: string;
54
+ end_session_endpoint: string;
55
+ } | undefined;
56
+ refreshEventHandlers: Function[];
57
+ init: (enforce?: boolean) => Promise<import("@moreillon/oidc-auth").InitOutput | undefined>;
58
+ sendUserToAuthUrl: (saveHref: Boolean) => Promise<void>;
59
+ fetchOidcConfig: () => Promise<any>;
60
+ generateAuthUrl: () => Promise<string>;
61
+ createTimeoutForTokenExpiry: (oidConfig: import("@moreillon/oidc-auth").OidcConfig) => void;
62
+ makeCookieOptions: () => string;
63
+ makeExpiryDate: (expires_in: number) => Date;
64
+ isExpired: (expires_at: string) => boolean;
65
+ saveAuthDataInCookies: (data: {
66
+ expires_in: number;
67
+ }) => void;
68
+ exchangeCodeForToken: (code: string) => Promise<void>;
69
+ getUser: () => Promise<any>;
70
+ refreshAccessToken: (oidcConfig: import("@moreillon/oidc-auth").OidcConfig) => Promise<void>;
71
+ onTokenRefreshed: (handler: (oidcData: import("@moreillon/oidc-auth").Tokens) => void) => void;
72
+ runRefreshEventHandlers: (newTokens: import("@moreillon/oidc-auth").Tokens) => void;
73
+ login: () => void;
74
+ logout: () => void;
75
+ } | null>;
2
76
  user: import("vue").Ref<any, any>;
3
77
  access_token: import("vue").Ref<string | null, string | null>;
78
+ login: typeof login;
79
+ logout: typeof logout;
4
80
  };
81
+ export {};
@@ -1,9 +1,23 @@
1
1
  import { ref } from "vue";
2
+ const client = ref(null);
2
3
  const user = ref(null);
3
4
  const access_token = ref(null);
5
+ function login() {
6
+ if (!client.value)
7
+ throw new Error("OIDC Client not instanciated");
8
+ return client.value.login;
9
+ }
10
+ function logout() {
11
+ if (!client.value)
12
+ throw new Error("OIDC Client not instanciated");
13
+ return client.value.logout;
14
+ }
4
15
  export default function () {
5
16
  return {
17
+ client,
6
18
  user,
7
19
  access_token,
20
+ login,
21
+ logout,
8
22
  };
9
23
  }
@@ -1,18 +1,17 @@
1
1
  import useAuth from "../composables/useAuth";
2
2
  import OidcClient from "@moreillon/oidc-auth";
3
- let oidcClient;
4
3
  export default {
5
4
  async install(app, options) {
6
5
  const { enforce, ...oidcOptions } = options;
7
6
  const auth = useAuth();
8
- oidcClient = new OidcClient(oidcOptions);
9
- const oidcData = await oidcClient.init(enforce);
7
+ auth.client.value = new OidcClient(oidcOptions);
8
+ const oidcData = await auth.client.value.init(enforce);
10
9
  if (!oidcData)
11
10
  return;
12
11
  const { user, tokens: { access_token }, } = oidcData;
13
12
  auth.user.value = user;
14
13
  auth.access_token.value = access_token;
15
- oidcClient.onTokenRefreshed(({ access_token }) => {
14
+ auth.client.value.onTokenRefreshed(({ access_token }) => {
16
15
  auth.access_token.value = access_token;
17
16
  });
18
17
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moreillon/vue-oidc",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -11,7 +11,7 @@
11
11
  "build": "tsc"
12
12
  },
13
13
  "dependencies": {
14
- "@moreillon/oidc-auth": "^3.0.1",
14
+ "@moreillon/oidc-auth": "^3.0.3",
15
15
  "vue": "^3.5.17"
16
16
  },
17
17
  "devDependencies": {