/
auth0-vue-client.ts
166 lines (153 loc) · 5.16 KB
/
auth0-vue-client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* eslint-disable @typescript-eslint/no-explicit-any */
import type {
User,
IdToken,
PopupLoginOptions,
PopupConfigOptions,
RedirectLoginResult,
GetTokenSilentlyOptions,
GetTokenSilentlyVerboseResponse,
GetTokenWithPopupOptions
} from '@auth0/auth0-spa-js';
import type { Ref } from 'vue';
import type { AppState } from './app-state';
import type {
LogoutOptions,
RedirectLoginOptions
} from './auth0-vue-client-options';
export interface Auth0VueClient {
/**
* The loading state of the SDK, `true` if the SDK is still processing the PKCE flow, `false` if the SDK has finished processing the PKCE flow.
*/
isLoading: Ref<boolean>;
/**
* The authentication state, `true` if the user is authenticated, `false` if not.
*/
isAuthenticated: Ref<boolean>;
/**
* Contains the information of the user if available.
*/
user: Ref<User | undefined>;
/**
* Contains all claims from the id_token if available.
*/
idTokenClaims: Ref<IdToken | undefined>;
/**
* Contains an error that occured in the SDK
*/
error: Ref<any>;
/**
* ```js
* try {
* await loginWithPopup(options);
* } catch(e) {
* if (e instanceof PopupCancelledError) {
* // Popup was closed before login completed
* }
* }
* ```
*
* Opens a popup with the `/authorize` URL using the parameters
* provided as arguments. Random and secure `state` and `nonce`
* parameters will be auto-generated. If the response is successful,
* results will be valid according to their expiration times.
*
* IMPORTANT: This method has to be called from an event handler
* that was started by the user like a button click, for example,
* otherwise the popup will be blocked in most browsers.
*
* @param options
* @param config
*/
loginWithPopup(
options?: PopupLoginOptions,
config?: PopupConfigOptions
): Promise<void>;
/**
* ```js
* await loginWithRedirect(options);
* ```
*
* Performs a redirect to `/authorize` using the parameters
* provided as arguments. Random and secure `state` and `nonce`
* parameters will be auto-generated.
*
* @param options
*/
loginWithRedirect(options?: RedirectLoginOptions<AppState>): Promise<void>;
/**
* After the browser redirects back to the callback page,
* call `handleRedirectCallback` to handle success and error
* responses from Auth0. If the response is successful, results
* will be valid according to their expiration times.
*
* **Note:** The Auth0-Vue SDK handles this for you, unless you set `skipRedirectCallback` to true.
* In that case, be sure to explicitly call `handleRedirectCallback` yourself.
*/
handleRedirectCallback(url?: string): Promise<RedirectLoginResult<AppState>>;
/**
* ```js
* await checkSession();
* ```
*
* Check if the user is logged in using `getTokenSilently`. The difference
* with `getTokenSilently` is that this doesn't return a token, but it will
* pre-fill the token cache.
*
* This method also heeds the `auth0.{clientId}.is.authenticated` cookie, as an optimization
* to prevent calling Auth0 unnecessarily. If the cookie is not present because
* there was no previous login (or it has expired) then tokens will not be refreshed.
*
* @param options
*/
checkSession(options?: GetTokenSilentlyOptions): Promise<void>;
/**
* Fetches a new access token and returns the response from the /oauth/token endpoint, omitting the refresh token.
*
* @param options
*/
getAccessTokenSilently(
options: GetTokenSilentlyOptions & { detailedResponse: true }
): Promise<GetTokenSilentlyVerboseResponse>;
/**
* Fetches a new access token and returns it.
*
* @param options
*/
getAccessTokenSilently(options?: GetTokenSilentlyOptions): Promise<string>;
/**
* ```js
* const token = await getTokenWithPopup(options);
* ```
* Opens a popup with the `/authorize` URL using the parameters
* provided as arguments. Random and secure `state` and `nonce`
* parameters will be auto-generated. If the response is successful,
* results will be valid according to their expiration times.
*
* @param options
* @param config
*/
getAccessTokenWithPopup(
options?: GetTokenWithPopupOptions,
config?: PopupConfigOptions
): Promise<string | undefined>;
/**
* ```js
* logout();
* ```
*
* Clears the application session and performs a redirect to `/v2/logout`, using
* the parameters provided as arguments, to clear the Auth0 session.
*
* **Note:** If you are using a custom cache, and specifying `localOnly: true`, and you want to perform actions or read state from the SDK immediately after logout, you should `await` the result of calling `logout`.
*
* If the `federated` option is specified it also clears the Identity Provider session.
* If the `localOnly` option is specified, it only clears the application session.
* It is invalid to set both the `federated` and `localOnly` options to `true`,
* and an error will be thrown if you do.
* [Read more about how Logout works at Auth0](https://auth0.com/docs/logout).
*
* @param options
*/
logout(options?: LogoutOptions): Promise<void>;
}