nuxt-auther 1.0.1 → 1.0.3
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/dist/module.cjs +5 -0
- package/dist/module.d.mts +3 -0
- package/dist/module.d.ts +3 -0
- package/dist/module.json +8 -0
- package/dist/module.mjs +1007 -0
- package/dist/runtime/composables.d.ts +2 -0
- package/dist/runtime/composables.mjs +2 -0
- package/dist/runtime/core/auth.d.ts +53 -0
- package/dist/runtime/core/auth.mjs +387 -0
- package/dist/runtime/core/index.d.ts +3 -0
- package/dist/runtime/core/index.mjs +3 -0
- package/dist/runtime/core/middleware.d.ts +2 -0
- package/dist/runtime/core/middleware.mjs +41 -0
- package/dist/runtime/core/storage.d.ts +41 -0
- package/dist/runtime/core/storage.mjs +277 -0
- package/dist/runtime/inc/configuration-document-request-error.d.ts +3 -0
- package/dist/runtime/inc/configuration-document-request-error.mjs +6 -0
- package/dist/runtime/inc/configuration-document.d.ts +26 -0
- package/dist/runtime/inc/configuration-document.mjs +94 -0
- package/dist/runtime/inc/default-properties.d.ts +123 -0
- package/dist/runtime/inc/default-properties.mjs +132 -0
- package/dist/runtime/inc/expired-auth-session-error.d.ts +3 -0
- package/dist/runtime/inc/expired-auth-session-error.mjs +6 -0
- package/dist/runtime/inc/id-token.d.ts +15 -0
- package/dist/runtime/inc/id-token.mjs +81 -0
- package/dist/runtime/inc/index.d.ts +10 -0
- package/dist/runtime/inc/index.mjs +10 -0
- package/dist/runtime/inc/refresh-controller.d.ts +9 -0
- package/dist/runtime/inc/refresh-controller.mjs +29 -0
- package/dist/runtime/inc/refresh-token.d.ts +14 -0
- package/dist/runtime/inc/refresh-token.mjs +75 -0
- package/dist/runtime/inc/request-handler.d.ts +17 -0
- package/dist/runtime/inc/request-handler.mjs +93 -0
- package/dist/runtime/inc/token-status.d.ts +12 -0
- package/dist/runtime/inc/token-status.mjs +39 -0
- package/dist/runtime/inc/token.d.ts +14 -0
- package/dist/runtime/inc/token.mjs +83 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.mjs +3 -0
- package/dist/runtime/providers/auth0.d.ts +7 -0
- package/dist/runtime/providers/auth0.mjs +15 -0
- package/dist/runtime/providers/discord.d.ts +6 -0
- package/dist/runtime/providers/discord.mjs +18 -0
- package/dist/runtime/providers/facebook.d.ts +6 -0
- package/dist/runtime/providers/facebook.mjs +13 -0
- package/dist/runtime/providers/github.d.ts +6 -0
- package/dist/runtime/providers/github.mjs +15 -0
- package/dist/runtime/providers/google.d.ts +6 -0
- package/dist/runtime/providers/google.mjs +13 -0
- package/dist/runtime/providers/index.d.ts +8 -0
- package/dist/runtime/providers/index.mjs +8 -0
- package/dist/runtime/providers/laravel-jwt.d.ts +7 -0
- package/dist/runtime/providers/laravel-jwt.mjs +47 -0
- package/dist/runtime/providers/laravel-passport.d.ts +12 -0
- package/dist/runtime/providers/laravel-passport.mjs +69 -0
- package/dist/runtime/providers/laravel-sanctum.d.ts +6 -0
- package/dist/runtime/providers/laravel-sanctum.mjs +52 -0
- package/dist/runtime/schemes/auth0.d.ts +4 -0
- package/dist/runtime/schemes/auth0.mjs +13 -0
- package/dist/runtime/schemes/base.d.ts +8 -0
- package/dist/runtime/schemes/base.mjs +11 -0
- package/dist/runtime/schemes/cookie.d.ts +23 -0
- package/dist/runtime/schemes/cookie.mjs +111 -0
- package/dist/runtime/schemes/index.d.ts +8 -0
- package/dist/runtime/schemes/index.mjs +8 -0
- package/dist/runtime/schemes/laravel-jwt.d.ts +5 -0
- package/dist/runtime/schemes/laravel-jwt.mjs +6 -0
- package/dist/runtime/schemes/local.d.ts +38 -0
- package/dist/runtime/schemes/local.mjs +160 -0
- package/dist/runtime/schemes/oauth2.d.ts +61 -0
- package/dist/runtime/schemes/oauth2.mjs +374 -0
- package/dist/runtime/schemes/openIDConnect.d.ts +24 -0
- package/dist/runtime/schemes/openIDConnect.mjs +190 -0
- package/dist/runtime/schemes/refresh.d.ts +26 -0
- package/dist/runtime/schemes/refresh.mjs +141 -0
- package/dist/runtime/token-nitro.d.ts +2 -0
- package/dist/runtime/token-nitro.mjs +9 -0
- package/dist/types/index.d.ts +42 -0
- package/dist/types/openIDConnectConfigurationDocument.d.ts +31 -0
- package/dist/types/options.d.ts +125 -0
- package/dist/types/provider.d.ts +21 -0
- package/dist/types/request.d.ts +8 -0
- package/dist/types/router.d.ts +7 -0
- package/dist/types/scheme.d.ts +108 -0
- package/dist/types/store.d.ts +30 -0
- package/dist/types/strategy.d.ts +16 -0
- package/dist/types/utils.d.ts +5 -0
- package/dist/utils/index.d.ts +28 -0
- package/dist/utils/index.mjs +123 -0
- package/dist/utils/provider.d.ts +13 -0
- package/dist/utils/provider.mjs +360 -0
- package/package.json +5 -3
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { cleanObj, getProp } from "../../utils";
|
|
2
|
+
import { RefreshController, RefreshToken, ExpiredAuthSessionError } from "../inc/index.mjs";
|
|
3
|
+
import { LocalScheme } from "./local.mjs";
|
|
4
|
+
const DEFAULTS = {
|
|
5
|
+
name: "refresh",
|
|
6
|
+
endpoints: {
|
|
7
|
+
refresh: {
|
|
8
|
+
url: "/api/auth/refresh",
|
|
9
|
+
method: "POST"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
refreshToken: {
|
|
13
|
+
property: "refresh_token",
|
|
14
|
+
data: "refresh_token",
|
|
15
|
+
maxAge: 60 * 60 * 24 * 30,
|
|
16
|
+
required: true,
|
|
17
|
+
tokenRequired: false,
|
|
18
|
+
prefix: "_refresh_token.",
|
|
19
|
+
expirationPrefix: "_refresh_token_expiration.",
|
|
20
|
+
httpOnly: false
|
|
21
|
+
},
|
|
22
|
+
autoLogout: false
|
|
23
|
+
};
|
|
24
|
+
export class RefreshScheme extends LocalScheme {
|
|
25
|
+
refreshToken;
|
|
26
|
+
refreshController;
|
|
27
|
+
constructor($auth, options) {
|
|
28
|
+
super($auth, options, DEFAULTS);
|
|
29
|
+
this.refreshToken = new RefreshToken(this, this.$auth.$storage);
|
|
30
|
+
this.refreshController = new RefreshController(this);
|
|
31
|
+
}
|
|
32
|
+
check(checkStatus = false) {
|
|
33
|
+
const response = {
|
|
34
|
+
valid: false,
|
|
35
|
+
tokenExpired: false,
|
|
36
|
+
refreshTokenExpired: false,
|
|
37
|
+
isRefreshable: true
|
|
38
|
+
};
|
|
39
|
+
const token = this.token.sync();
|
|
40
|
+
this.refreshToken.sync();
|
|
41
|
+
if (!token) {
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
44
|
+
if (!checkStatus) {
|
|
45
|
+
response.valid = true;
|
|
46
|
+
return response;
|
|
47
|
+
}
|
|
48
|
+
const tokenStatus = this.token.status();
|
|
49
|
+
const refreshTokenStatus = this.refreshToken.status();
|
|
50
|
+
if (refreshTokenStatus.expired()) {
|
|
51
|
+
response.refreshTokenExpired = true;
|
|
52
|
+
return response;
|
|
53
|
+
}
|
|
54
|
+
if (tokenStatus.expired()) {
|
|
55
|
+
response.tokenExpired = true;
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
58
|
+
response.valid = true;
|
|
59
|
+
return response;
|
|
60
|
+
}
|
|
61
|
+
mounted() {
|
|
62
|
+
return super.mounted({
|
|
63
|
+
tokenCallback: () => {
|
|
64
|
+
if (this.options.autoLogout) {
|
|
65
|
+
this.$auth.reset();
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
refreshTokenCallback: () => {
|
|
69
|
+
this.$auth.reset();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async refreshTokens() {
|
|
74
|
+
if (!this.options.endpoints.refresh) {
|
|
75
|
+
return Promise.resolve();
|
|
76
|
+
}
|
|
77
|
+
if (!this.check().valid) {
|
|
78
|
+
return Promise.resolve();
|
|
79
|
+
}
|
|
80
|
+
const refreshTokenStatus = this.refreshToken.status();
|
|
81
|
+
if (refreshTokenStatus.expired()) {
|
|
82
|
+
this.$auth.reset();
|
|
83
|
+
throw new ExpiredAuthSessionError();
|
|
84
|
+
}
|
|
85
|
+
if (!this.options.refreshToken.tokenRequired) {
|
|
86
|
+
this.requestHandler.clearHeader();
|
|
87
|
+
}
|
|
88
|
+
const endpoint = {
|
|
89
|
+
body: {
|
|
90
|
+
client_id: void 0,
|
|
91
|
+
grant_type: void 0
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
if (this.options.refreshToken.required && this.options.refreshToken.data && !this.options.refreshToken.httpOnly) {
|
|
95
|
+
endpoint.body[this.options.refreshToken.data] = this.refreshToken.get();
|
|
96
|
+
}
|
|
97
|
+
if (this.options.clientId) {
|
|
98
|
+
endpoint.body.client_id = this.options.clientId;
|
|
99
|
+
}
|
|
100
|
+
endpoint.body.grant_type = "refresh_token";
|
|
101
|
+
cleanObj(endpoint.body);
|
|
102
|
+
if (this.options.ssr) {
|
|
103
|
+
endpoint.baseURL = "";
|
|
104
|
+
}
|
|
105
|
+
const response = await this.$auth.request(endpoint, this.options.endpoints.refresh);
|
|
106
|
+
this.updateTokens(response);
|
|
107
|
+
}
|
|
108
|
+
setUserToken(token, refreshToken) {
|
|
109
|
+
this.token.set(token);
|
|
110
|
+
if (refreshToken) {
|
|
111
|
+
this.refreshToken.set(refreshToken);
|
|
112
|
+
}
|
|
113
|
+
return this.fetchUser();
|
|
114
|
+
}
|
|
115
|
+
reset({ resetInterceptor = true } = {}) {
|
|
116
|
+
this.$auth.setUser(false);
|
|
117
|
+
this.token.reset();
|
|
118
|
+
this.refreshToken.reset();
|
|
119
|
+
if (resetInterceptor) {
|
|
120
|
+
this.requestHandler.reset();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
extractRefreshToken(response) {
|
|
124
|
+
return getProp(response._data, this.options.refreshToken.property);
|
|
125
|
+
}
|
|
126
|
+
updateTokens(response) {
|
|
127
|
+
let tokenExpiresIn = false;
|
|
128
|
+
const token = this.options.token?.required ? this.extractToken(response) : true;
|
|
129
|
+
const refreshToken = this.options.refreshToken.required ? this.extractRefreshToken(response) : true;
|
|
130
|
+
tokenExpiresIn = this.options.token?.maxAge || getProp(response._data, this.options.token.expiresProperty);
|
|
131
|
+
this.token.set(token, tokenExpiresIn);
|
|
132
|
+
if (refreshToken) {
|
|
133
|
+
this.refreshToken.set(refreshToken);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
initializeRequestInterceptor() {
|
|
137
|
+
this.requestHandler.initializeRequestInterceptor(
|
|
138
|
+
this.options.endpoints.refresh.url
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readBody, defineEventHandler, deleteCookie } from "h3";
|
|
2
|
+
import { config } from "#nuxt-auth-options";
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
const body = await readBody(event);
|
|
5
|
+
const token = config.stores?.cookie?.prefix + body?.token;
|
|
6
|
+
if (token) {
|
|
7
|
+
deleteCookie(event, token, { ...config.stores.cookie.options });
|
|
8
|
+
}
|
|
9
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ModuleOptions } from './options';
|
|
2
|
+
import type { Auth } from '../runtime';
|
|
3
|
+
import * as NuxtSchema from '@nuxt/schema';
|
|
4
|
+
|
|
5
|
+
export * from './openIDConnectConfigurationDocument';
|
|
6
|
+
export * from './provider';
|
|
7
|
+
export * from './request';
|
|
8
|
+
export * from './router';
|
|
9
|
+
export * from './scheme';
|
|
10
|
+
export * from './strategy';
|
|
11
|
+
export * from './utils';
|
|
12
|
+
export * from './options';
|
|
13
|
+
export * from './store'
|
|
14
|
+
|
|
15
|
+
declare module '#app' {
|
|
16
|
+
interface NuxtApp {
|
|
17
|
+
$auth: Auth;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module 'vue-router' {
|
|
22
|
+
interface RouteMeta {
|
|
23
|
+
auth?: 'guest' | false
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare module '@nuxt/schema' {
|
|
28
|
+
interface NuxtConfig {
|
|
29
|
+
['auth']?: Partial<ModuleOptions>
|
|
30
|
+
}
|
|
31
|
+
interface NuxtOptions {
|
|
32
|
+
['auth']?: ModuleOptions
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare const NuxtAuth: NuxtSchema.NuxtModule<ModuleOptions>
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
ModuleOptions,
|
|
40
|
+
NuxtAuth as default
|
|
41
|
+
};
|
|
42
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type OpenIDConnectConfigurationDocument = {
|
|
2
|
+
issuer?: string;
|
|
3
|
+
authorization_endpoint?: string;
|
|
4
|
+
token_endpoint?: string;
|
|
5
|
+
token_endpoint_auth_methods_supported?: string[];
|
|
6
|
+
token_endpoint_auth_signing_alg_values_supported?: string[];
|
|
7
|
+
userinfo_endpoint?: string;
|
|
8
|
+
check_session_iframe?: string;
|
|
9
|
+
end_session_endpoint?: string;
|
|
10
|
+
jwks_uri?: string;
|
|
11
|
+
registration_endpoint?: string;
|
|
12
|
+
scopes_supported?: string[];
|
|
13
|
+
response_types_supported?: string[];
|
|
14
|
+
acr_values_supported?: string[];
|
|
15
|
+
response_modes_supported?: string[];
|
|
16
|
+
grant_types_supported?: string[];
|
|
17
|
+
subject_types_supported?: string[];
|
|
18
|
+
userinfo_signing_alg_values_supported?: string[];
|
|
19
|
+
userinfo_encryption_alg_values_supported?: string[];
|
|
20
|
+
userinfo_encryption_enc_values_supported?: string[];
|
|
21
|
+
id_token_signing_alg_values_supported?: string[];
|
|
22
|
+
id_token_encryption_alg_values_supported?: string[];
|
|
23
|
+
id_token_encryption_enc_values_supported?: string[];
|
|
24
|
+
request_object_signing_alg_values_supported?: string[];
|
|
25
|
+
display_values_supported?: string[];
|
|
26
|
+
claim_types_supported?: string[];
|
|
27
|
+
claims_supported?: string[];
|
|
28
|
+
claims_parameter_supported?: boolean;
|
|
29
|
+
service_documentation?: string;
|
|
30
|
+
ui_locales_supported?: string[];
|
|
31
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { Strategy, StrategyOptions } from './strategy';
|
|
2
|
+
import type { NuxtPlugin } from '@nuxt/schema';
|
|
3
|
+
import type { AuthState, RefreshableScheme, TokenableScheme } from './index';
|
|
4
|
+
import type { CookieSerializeOptions } from 'cookie-es';
|
|
5
|
+
import type { Auth } from '../runtime'
|
|
6
|
+
|
|
7
|
+
export interface ModuleOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Whether the global middleware is enabled or not.
|
|
10
|
+
* This option is disabled if `enableMiddleware` is `false`
|
|
11
|
+
*/
|
|
12
|
+
globalMiddleware?: boolean;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Whether middleware is enabled or not.
|
|
16
|
+
*/
|
|
17
|
+
enableMiddleware?: boolean;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Plugins to be used by the module.
|
|
21
|
+
*/
|
|
22
|
+
plugins?: (NuxtPlugin | string)[];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Authentication strategies used by the module.
|
|
26
|
+
*/
|
|
27
|
+
strategies?: Record<string, StrategyOptions>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether exceptions should be ignored or not.
|
|
31
|
+
*/
|
|
32
|
+
ignoreExceptions: boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Whether the auth module should reset login data on an error.
|
|
36
|
+
*/
|
|
37
|
+
resetOnError: boolean | ((...args: any[]) => boolean);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Whether to reset on a response error.
|
|
41
|
+
*/
|
|
42
|
+
resetOnResponseError: boolean | ((error: any, auth: Auth, scheme: TokenableScheme | RefreshableScheme) => void);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Default authentication strategy to be used by the module.
|
|
46
|
+
* This is used internally.
|
|
47
|
+
*/
|
|
48
|
+
defaultStrategy: string | undefined;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Whether to watch user logged in state or not.
|
|
52
|
+
*/
|
|
53
|
+
watchLoggedIn: boolean;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Interval for token validation.
|
|
57
|
+
*/
|
|
58
|
+
tokenValidationInterval: boolean | number;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Whether to rewrite redirects or not.
|
|
62
|
+
*/
|
|
63
|
+
rewriteRedirects: boolean;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Whether to redirect with full path or not.
|
|
67
|
+
*/
|
|
68
|
+
fullPathRedirect: boolean;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Redirect strategy to be used: 'query' or 'storage'
|
|
72
|
+
*/
|
|
73
|
+
redirectStrategy?: 'query' | 'storage';
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Key for scope.
|
|
77
|
+
*/
|
|
78
|
+
scopeKey: string;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Store options for the auth module. The `pinia` store will not
|
|
82
|
+
* be utilized unless you enable it. By default `useState()` will be
|
|
83
|
+
* used instead.
|
|
84
|
+
*/
|
|
85
|
+
stores: Partial<{
|
|
86
|
+
state: {
|
|
87
|
+
namespace?: string
|
|
88
|
+
};
|
|
89
|
+
pinia: {
|
|
90
|
+
enabled?: boolean;
|
|
91
|
+
namespace?: string;
|
|
92
|
+
};
|
|
93
|
+
cookie: {
|
|
94
|
+
enabled?: boolean;
|
|
95
|
+
prefix?: string;
|
|
96
|
+
options?: CookieSerializeOptions;
|
|
97
|
+
};
|
|
98
|
+
local: {
|
|
99
|
+
enabled: boolean;
|
|
100
|
+
prefix?: string;
|
|
101
|
+
};
|
|
102
|
+
session: {
|
|
103
|
+
enabled?: boolean;
|
|
104
|
+
prefix?: string;
|
|
105
|
+
};
|
|
106
|
+
}>;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Redirect URL for login, logout, callback and home.
|
|
110
|
+
*
|
|
111
|
+
* *Note:* The `trans` argument is only available if
|
|
112
|
+
* `nuxt/i18n` is available.
|
|
113
|
+
*/
|
|
114
|
+
redirect: {
|
|
115
|
+
login: string | ((auth: Auth, trans?: Function) => string);
|
|
116
|
+
logout: string | ((auth: Auth, trans?: Function) => string);
|
|
117
|
+
callback: string | ((auth: Auth, trans?: Function) => string);
|
|
118
|
+
home: string | ((auth: Auth, trans?: Function) => string);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Initial state for Auth. This is used Internally.
|
|
123
|
+
*/
|
|
124
|
+
initialState?: AuthState;
|
|
125
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SchemeOptions, SchemeNames } from './scheme';
|
|
2
|
+
import type { StrategyOptions } from './strategy';
|
|
3
|
+
import type { PartialExcept } from './utils';
|
|
4
|
+
import type { Nuxt } from '@nuxt/schema';
|
|
5
|
+
|
|
6
|
+
export type ProviderNames<N = ''> = 'laravel/sanctum' | 'laravel/jwt' | 'laravel/passport' | 'google' | 'github' | 'facebook' | 'discord' | 'auth0' | N | ((nuxt: Nuxt, strategy: StrategyOptions, ...args: any[]) => void);
|
|
7
|
+
|
|
8
|
+
export interface ImportOptions {
|
|
9
|
+
name: string;
|
|
10
|
+
as: string;
|
|
11
|
+
from: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ProviderOptions {
|
|
15
|
+
scheme?: SchemeNames;
|
|
16
|
+
clientSecret: string | number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ProviderOptionsKeys = Exclude<keyof ProviderOptions, 'clientSecret'>;
|
|
20
|
+
|
|
21
|
+
export type ProviderPartialOptions<Options extends ProviderOptions & SchemeOptions> = PartialExcept<Options, ProviderOptionsKeys>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { HTTPRequest, HTTPResponse } from '.';
|
|
2
|
+
import type { Auth } from '../runtime/core';
|
|
3
|
+
import type { Token, IdToken, RefreshToken, RefreshController, RequestHandler } from '../runtime/inc';
|
|
4
|
+
import type { PartialExcept } from './utils';
|
|
5
|
+
|
|
6
|
+
export type SchemeNames<N = ''> = 'local' | 'cookie' | 'laravelJWT' | 'openIDConnect' | 'refresh' | 'oauth2' | 'auth0' | `~/${string}` | N
|
|
7
|
+
|
|
8
|
+
export interface UserOptions {
|
|
9
|
+
property: string | false;
|
|
10
|
+
autoFetch: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface EndpointsOption {
|
|
14
|
+
[endpoint: string]: string | HTTPRequest | false | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Scheme
|
|
18
|
+
|
|
19
|
+
export interface SchemeOptions {
|
|
20
|
+
name?: string;
|
|
21
|
+
ssr?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type SchemePartialOptions<Options extends SchemeOptions> = PartialExcept<Options, keyof SchemeOptions>;
|
|
25
|
+
|
|
26
|
+
export interface SchemeCheck {
|
|
27
|
+
valid: boolean;
|
|
28
|
+
tokenExpired?: boolean;
|
|
29
|
+
refreshTokenExpired?: boolean;
|
|
30
|
+
idTokenExpired?: boolean;
|
|
31
|
+
isRefreshable?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface Scheme<OptionsT extends SchemeOptions = SchemeOptions> {
|
|
35
|
+
options: OptionsT;
|
|
36
|
+
name?: string;
|
|
37
|
+
$auth: Auth;
|
|
38
|
+
mounted?(...args: any[]): Promise<HTTPResponse<any> | void>;
|
|
39
|
+
check?(checkStatus?: boolean): SchemeCheck;
|
|
40
|
+
login(...args: any[]): Promise<HTTPResponse<any> | void>;
|
|
41
|
+
fetchUser(endpoint?: HTTPRequest): Promise<HTTPResponse<any> | void>;
|
|
42
|
+
setUserToken?(
|
|
43
|
+
token: string | boolean,
|
|
44
|
+
refreshToken?: string | boolean
|
|
45
|
+
): Promise<HTTPResponse<any> | void>;
|
|
46
|
+
logout?(endpoint?: HTTPRequest): Promise<void> | void;
|
|
47
|
+
reset?(options?: { resetInterceptor: boolean }): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Token
|
|
51
|
+
|
|
52
|
+
export interface TokenOptions {
|
|
53
|
+
property: string;
|
|
54
|
+
expiresProperty: string;
|
|
55
|
+
type: string | false;
|
|
56
|
+
name: string;
|
|
57
|
+
maxAge: number | false;
|
|
58
|
+
global: boolean;
|
|
59
|
+
required: boolean;
|
|
60
|
+
prefix: string;
|
|
61
|
+
expirationPrefix: string;
|
|
62
|
+
httpOnly: boolean
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface TokenableSchemeOptions extends SchemeOptions {
|
|
66
|
+
token?: TokenOptions;
|
|
67
|
+
endpoints: EndpointsOption;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface TokenableScheme<OptionsT extends TokenableSchemeOptions = TokenableSchemeOptions> extends Scheme<OptionsT> {
|
|
71
|
+
token?: Token;
|
|
72
|
+
requestHandler: RequestHandler;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ID Token
|
|
76
|
+
|
|
77
|
+
export interface IdTokenableSchemeOptions extends SchemeOptions {
|
|
78
|
+
idToken: TokenOptions;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface IdTokenableScheme<OptionsT extends IdTokenableSchemeOptions = IdTokenableSchemeOptions> extends Scheme<OptionsT> {
|
|
82
|
+
idToken: IdToken;
|
|
83
|
+
requestHandler: RequestHandler;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Refrash
|
|
87
|
+
|
|
88
|
+
export interface RefreshTokenOptions {
|
|
89
|
+
property: string | false;
|
|
90
|
+
type: string | false;
|
|
91
|
+
data: string | false;
|
|
92
|
+
maxAge: number | false;
|
|
93
|
+
required: boolean;
|
|
94
|
+
tokenRequired: boolean;
|
|
95
|
+
prefix: string;
|
|
96
|
+
expirationPrefix: string;
|
|
97
|
+
httpOnly: boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface RefreshableSchemeOptions extends TokenableSchemeOptions {
|
|
101
|
+
refreshToken: RefreshTokenOptions;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface RefreshableScheme<OptionsT extends RefreshableSchemeOptions = RefreshableSchemeOptions> extends TokenableScheme<OptionsT> {
|
|
105
|
+
refreshToken: RefreshToken;
|
|
106
|
+
refreshController: RefreshController;
|
|
107
|
+
refreshTokens(): Promise<HTTPResponse<any> | void>;
|
|
108
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { _StoreWithState } from 'pinia';
|
|
2
|
+
import type { CookieSerializeOptions } from 'cookie-es';
|
|
3
|
+
|
|
4
|
+
export type AuthStore = _StoreWithState<string, AuthState, {}, {}> & {
|
|
5
|
+
[key: string]: AuthState
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type StoreMethod = 'cookie' | 'session' | 'local';
|
|
9
|
+
|
|
10
|
+
export interface StoreIncludeOptions {
|
|
11
|
+
cookie?: boolean | CookieSerializeOptions;
|
|
12
|
+
session?: boolean;
|
|
13
|
+
local?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface UserInfo {
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type AuthState = {
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
// user object
|
|
23
|
+
user?: UserInfo;
|
|
24
|
+
// indicates whether the user is logged in
|
|
25
|
+
loggedIn?: boolean;
|
|
26
|
+
// indicates the strategy of authentication used
|
|
27
|
+
strategy?: string;
|
|
28
|
+
// indicates if the authentication system is busy performing tasks, may not be defined initially
|
|
29
|
+
busy?: boolean;
|
|
30
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SchemePartialOptions, RefreshableSchemeOptions, SchemeOptions, SchemeNames } from './scheme';
|
|
2
|
+
import type { CookieSchemeOptions, Oauth2SchemeOptions, OpenIDConnectSchemeOptions } from '../runtime/schemes';
|
|
3
|
+
import type { ProviderPartialOptions, ProviderOptions, ProviderNames } from './provider';
|
|
4
|
+
import type { RecursivePartial } from './utils';
|
|
5
|
+
|
|
6
|
+
export type Strategy<S = {}> = S & Strategies;
|
|
7
|
+
|
|
8
|
+
// @ts-ignore: endpoints dont match
|
|
9
|
+
export interface AuthSchemeOptions extends RefreshableSchemeOptions, Oauth2SchemeOptions, CookieSchemeOptions, OpenIDConnectSchemeOptions {}
|
|
10
|
+
|
|
11
|
+
export interface Strategies {
|
|
12
|
+
provider?: ProviderNames;
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type StrategyOptions<SOptions extends RecursivePartial<AuthSchemeOptions> = RecursivePartial<AuthSchemeOptions>> = ProviderPartialOptions<ProviderOptions & SOptions & Strategy>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RouteComponent, RouteLocationNormalized } from '#vue-router';
|
|
2
|
+
import type { RecursivePartial } from '../types';
|
|
3
|
+
import type { NuxtApp } from '#app';
|
|
4
|
+
import type { H3Event } from 'h3';
|
|
5
|
+
export declare const isUnset: (o: any) => boolean;
|
|
6
|
+
export declare const isSet: (o: any) => boolean;
|
|
7
|
+
export declare function parseQuery(queryString: string): Record<string, unknown>;
|
|
8
|
+
export declare function isRelativeURL(u: string): boolean | "" | 0;
|
|
9
|
+
export declare function routeMeta(route: RouteLocationNormalized, key: string, value: string | boolean): boolean;
|
|
10
|
+
export declare function getMatchedComponents(route: RouteLocationNormalized, matches?: unknown[]): RouteComponent[][];
|
|
11
|
+
export declare function normalizePath(path: string | undefined, ctx: NuxtApp): string;
|
|
12
|
+
export declare function encodeValue(val: any): string;
|
|
13
|
+
export declare function decodeValue(val: any): any;
|
|
14
|
+
/**
|
|
15
|
+
* Get property defined by dot notation in string.
|
|
16
|
+
* Based on https://github.com/dy/dotprop (MIT)
|
|
17
|
+
*
|
|
18
|
+
* @param { Object } holder Target object where to look property up
|
|
19
|
+
* @param { string } propName Dot notation, like 'this.a.b.c'
|
|
20
|
+
* @return { * } A property value
|
|
21
|
+
*/
|
|
22
|
+
export declare function getProp(holder: any, propName: string | false): any;
|
|
23
|
+
export declare function addTokenPrefix(token: string | boolean, tokenType: string | false): string | boolean;
|
|
24
|
+
export declare function removeTokenPrefix(token: string | boolean, tokenType: string | false): string | boolean;
|
|
25
|
+
export declare function cleanObj<T extends Record<string, any>>(obj: T): RecursivePartial<T>;
|
|
26
|
+
export declare function randomString(length: number): string;
|
|
27
|
+
export declare function setH3Cookie(event: H3Event, serializedCookie: string): void;
|
|
28
|
+
export declare const hasOwn: <O extends object, K extends PropertyKey>(object: O, key: K) => any;
|