@bagelink/auth 1.9.59 → 1.9.63
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/api.d.ts +36 -32
- package/dist/index.cjs +101 -127
- package/dist/index.mjs +101 -127
- package/dist/sso.d.ts +2 -2
- package/dist/types.d.ts +70 -24
- package/dist/useAuth.d.ts +19 -20
- package/package.json +1 -1
- package/src/api.ts +81 -82
- package/src/sso.ts +26 -24
- package/src/types.ts +77 -28
- package/src/useAuth.ts +19 -51
package/dist/index.mjs
CHANGED
|
@@ -95,6 +95,12 @@ class AuthApi {
|
|
|
95
95
|
// ============================================
|
|
96
96
|
// Authentication Methods
|
|
97
97
|
// ============================================
|
|
98
|
+
/**
|
|
99
|
+
* Get authentication status
|
|
100
|
+
*/
|
|
101
|
+
async getAuthStatus() {
|
|
102
|
+
return this.api.get("authentication/status");
|
|
103
|
+
}
|
|
98
104
|
/**
|
|
99
105
|
* Get available authentication methods
|
|
100
106
|
*/
|
|
@@ -113,12 +119,42 @@ class AuthApi {
|
|
|
113
119
|
/**
|
|
114
120
|
* Login with password
|
|
115
121
|
*/
|
|
116
|
-
async login(
|
|
122
|
+
async login(data) {
|
|
117
123
|
return this.api.post("authentication/login/password", {
|
|
118
|
-
|
|
119
|
-
|
|
124
|
+
...data,
|
|
125
|
+
email: data.email.toLowerCase()
|
|
120
126
|
});
|
|
121
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Send email token to user
|
|
130
|
+
*/
|
|
131
|
+
async sendEmailToken(data) {
|
|
132
|
+
return this.api.post("authentication/login/email-token/send", data);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Verify email token and login
|
|
136
|
+
*/
|
|
137
|
+
async verifyEmailToken(data) {
|
|
138
|
+
return this.api.post("authentication/login/email-token/verify", data);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Send OTP code to phone number
|
|
142
|
+
*/
|
|
143
|
+
async sendOTP(data) {
|
|
144
|
+
return this.api.post("authentication/login/otp/send", data);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Verify OTP code and login
|
|
148
|
+
*/
|
|
149
|
+
async verifyOTP(data) {
|
|
150
|
+
return this.api.post("authentication/login/otp/verify", data);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Login with SSO provider (legacy endpoint without PKCE)
|
|
154
|
+
*/
|
|
155
|
+
async loginWithSSO(provider, data) {
|
|
156
|
+
return this.api.post(`authentication/login/sso/${provider}`, data);
|
|
157
|
+
}
|
|
122
158
|
/**
|
|
123
159
|
* Logout and clear session
|
|
124
160
|
*/
|
|
@@ -138,29 +174,20 @@ class AuthApi {
|
|
|
138
174
|
* Initiate SSO login flow
|
|
139
175
|
* Returns authorization URL to redirect user to
|
|
140
176
|
*/
|
|
141
|
-
async initiateSSO(data) {
|
|
142
|
-
return this.api.post(`authentication/sso/${
|
|
143
|
-
redirect_uri: data.redirect_uri,
|
|
144
|
-
state: data.state
|
|
145
|
-
});
|
|
177
|
+
async initiateSSO(provider, data) {
|
|
178
|
+
return this.api.post(`authentication/sso/${provider}/initiate`, data);
|
|
146
179
|
}
|
|
147
180
|
/**
|
|
148
181
|
* Complete SSO login after callback from provider
|
|
149
182
|
*/
|
|
150
|
-
async ssoCallback(data) {
|
|
151
|
-
return this.api.post(`authentication/sso/${
|
|
152
|
-
code: data.code,
|
|
153
|
-
state: data.state
|
|
154
|
-
});
|
|
183
|
+
async ssoCallback(provider, data) {
|
|
184
|
+
return this.api.post(`authentication/sso/${provider}/callback`, data);
|
|
155
185
|
}
|
|
156
186
|
/**
|
|
157
187
|
* Link an SSO provider to existing account
|
|
158
188
|
*/
|
|
159
|
-
async linkSSOProvider(data) {
|
|
160
|
-
return this.api.post(`authentication/sso/${
|
|
161
|
-
code: data.code,
|
|
162
|
-
state: data.state
|
|
163
|
-
});
|
|
189
|
+
async linkSSOProvider(provider, data) {
|
|
190
|
+
return this.api.post(`authentication/sso/${provider}/link`, data);
|
|
164
191
|
}
|
|
165
192
|
/**
|
|
166
193
|
* Unlink an SSO provider from account
|
|
@@ -190,39 +217,6 @@ class AuthApi {
|
|
|
190
217
|
return this.api.delete("authentication/me");
|
|
191
218
|
}
|
|
192
219
|
// ============================================
|
|
193
|
-
// Account Management (Admin)
|
|
194
|
-
// ============================================
|
|
195
|
-
/**
|
|
196
|
-
* Get account information by ID
|
|
197
|
-
*/
|
|
198
|
-
async getAccount(accountId) {
|
|
199
|
-
return this.api.get(`authentication/account/${accountId}`);
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Update account by ID
|
|
203
|
-
*/
|
|
204
|
-
async updateAccount(accountId, data) {
|
|
205
|
-
return this.api.patch(`authentication/account/${accountId}`, data);
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Delete account by ID
|
|
209
|
-
*/
|
|
210
|
-
async deleteAccount(accountId) {
|
|
211
|
-
return this.api.delete(`authentication/account/${accountId}`);
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Activate account by ID
|
|
215
|
-
*/
|
|
216
|
-
async activateAccount(accountId) {
|
|
217
|
-
return this.api.post(`authentication/account/${accountId}/activate`, {});
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Deactivate account by ID
|
|
221
|
-
*/
|
|
222
|
-
async deactivateAccount(accountId) {
|
|
223
|
-
return this.api.post(`authentication/account/${accountId}/deactivate`, {});
|
|
224
|
-
}
|
|
225
|
-
// ============================================
|
|
226
220
|
// Password Management
|
|
227
221
|
// ============================================
|
|
228
222
|
/**
|
|
@@ -234,9 +228,10 @@ class AuthApi {
|
|
|
234
228
|
/**
|
|
235
229
|
* Initiate forgot password flow
|
|
236
230
|
*/
|
|
237
|
-
async forgotPassword(
|
|
231
|
+
async forgotPassword(data) {
|
|
238
232
|
return this.api.post("authentication/password/forgot", {
|
|
239
|
-
|
|
233
|
+
...data,
|
|
234
|
+
email: data.email.toLowerCase()
|
|
240
235
|
});
|
|
241
236
|
}
|
|
242
237
|
/**
|
|
@@ -265,17 +260,17 @@ class AuthApi {
|
|
|
265
260
|
/**
|
|
266
261
|
* Verify email with token
|
|
267
262
|
*/
|
|
268
|
-
async verifyEmail(
|
|
269
|
-
return this.api.post("authentication/verify/email",
|
|
263
|
+
async verifyEmail(data) {
|
|
264
|
+
return this.api.post("authentication/verify/email", data);
|
|
270
265
|
}
|
|
271
266
|
// ============================================
|
|
272
267
|
// Session Management
|
|
273
268
|
// ============================================
|
|
274
269
|
/**
|
|
275
|
-
* Get sessions for
|
|
270
|
+
* Get active sessions for current identity
|
|
276
271
|
*/
|
|
277
|
-
async getSessions(
|
|
278
|
-
return this.api.get(
|
|
272
|
+
async getSessions() {
|
|
273
|
+
return this.api.get("authentication/sessions");
|
|
279
274
|
}
|
|
280
275
|
/**
|
|
281
276
|
* Revoke a specific session
|
|
@@ -284,10 +279,10 @@ class AuthApi {
|
|
|
284
279
|
return this.api.delete(`authentication/sessions/${sessionToken}`);
|
|
285
280
|
}
|
|
286
281
|
/**
|
|
287
|
-
* Revoke all sessions for
|
|
282
|
+
* Revoke all sessions for current identity
|
|
288
283
|
*/
|
|
289
|
-
async revokeAllSessions(
|
|
290
|
-
return this.api.delete(
|
|
284
|
+
async revokeAllSessions() {
|
|
285
|
+
return this.api.delete("authentication/sessions");
|
|
291
286
|
}
|
|
292
287
|
/**
|
|
293
288
|
* Cleanup expired sessions (admin)
|
|
@@ -1636,8 +1631,7 @@ function createSSOProvider(config) {
|
|
|
1636
1631
|
sessionStorage.setItem(getStateKey(), state);
|
|
1637
1632
|
sessionStorage.setItem(`oauth_provider:${state}`, config.id);
|
|
1638
1633
|
}
|
|
1639
|
-
const authUrl = await auth.initiateSSO({
|
|
1640
|
-
provider: config.id,
|
|
1634
|
+
const authUrl = await auth.initiateSSO(config.id, {
|
|
1641
1635
|
redirect_uri: redirectUri,
|
|
1642
1636
|
state,
|
|
1643
1637
|
scopes: options.scopes ?? config.defaultScopes,
|
|
@@ -1661,8 +1655,7 @@ function createSSOProvider(config) {
|
|
|
1661
1655
|
sessionStorage.setItem(getStateKey(), state);
|
|
1662
1656
|
sessionStorage.setItem(`oauth_provider:${state}`, config.id);
|
|
1663
1657
|
}
|
|
1664
|
-
const authUrl = await auth.initiateSSO({
|
|
1665
|
-
provider: config.id,
|
|
1658
|
+
const authUrl = await auth.initiateSSO(config.id, {
|
|
1666
1659
|
redirect_uri: redirectUri,
|
|
1667
1660
|
state,
|
|
1668
1661
|
scopes: options.scopes ?? config.defaultScopes,
|
|
@@ -1674,15 +1667,14 @@ function createSSOProvider(config) {
|
|
|
1674
1667
|
throw new PopupBlockedError();
|
|
1675
1668
|
}
|
|
1676
1669
|
const result = await waitForPopupCallback(popupWindow, config.id, timeout2);
|
|
1677
|
-
return auth.loginWithSSO({
|
|
1678
|
-
provider: config.id,
|
|
1670
|
+
return auth.loginWithSSO(config.id, {
|
|
1679
1671
|
code: result.code,
|
|
1680
|
-
state: result.state
|
|
1672
|
+
state: result.state ?? generateState()
|
|
1681
1673
|
});
|
|
1682
1674
|
},
|
|
1683
1675
|
async callback(code, state) {
|
|
1684
1676
|
const auth = getAuthApi();
|
|
1685
|
-
if (typeof sessionStorage !== "undefined"
|
|
1677
|
+
if (typeof sessionStorage !== "undefined") {
|
|
1686
1678
|
const storedState = sessionStorage.getItem(getStateKey());
|
|
1687
1679
|
sessionStorage.removeItem(getStateKey());
|
|
1688
1680
|
sessionStorage.removeItem(`oauth_provider:${state}`);
|
|
@@ -1690,15 +1682,14 @@ function createSSOProvider(config) {
|
|
|
1690
1682
|
throw new StateMismatchError();
|
|
1691
1683
|
}
|
|
1692
1684
|
}
|
|
1693
|
-
return auth.loginWithSSO({
|
|
1694
|
-
provider: config.id,
|
|
1685
|
+
return auth.loginWithSSO(config.id, {
|
|
1695
1686
|
code,
|
|
1696
|
-
state
|
|
1687
|
+
state: state ?? generateState()
|
|
1697
1688
|
});
|
|
1698
1689
|
},
|
|
1699
1690
|
async link(code, state) {
|
|
1700
1691
|
const auth = getAuthApi();
|
|
1701
|
-
if (typeof sessionStorage !== "undefined"
|
|
1692
|
+
if (typeof sessionStorage !== "undefined") {
|
|
1702
1693
|
const storedState = sessionStorage.getItem(getStateKey());
|
|
1703
1694
|
sessionStorage.removeItem(getStateKey());
|
|
1704
1695
|
sessionStorage.removeItem(`oauth_provider:${state}`);
|
|
@@ -1706,10 +1697,9 @@ function createSSOProvider(config) {
|
|
|
1706
1697
|
throw new StateMismatchError();
|
|
1707
1698
|
}
|
|
1708
1699
|
}
|
|
1709
|
-
await auth.linkSSOProvider({
|
|
1710
|
-
provider: config.id,
|
|
1700
|
+
await auth.linkSSOProvider(config.id, {
|
|
1711
1701
|
code,
|
|
1712
|
-
state
|
|
1702
|
+
state: state ?? generateState()
|
|
1713
1703
|
});
|
|
1714
1704
|
},
|
|
1715
1705
|
async unlink() {
|
|
@@ -1720,8 +1710,7 @@ function createSSOProvider(config) {
|
|
|
1720
1710
|
const auth = getAuthApi();
|
|
1721
1711
|
const redirectUri = options.redirectUri ?? getDefaultRedirectUri();
|
|
1722
1712
|
const state = options.state ?? generateState();
|
|
1723
|
-
return auth.initiateSSO({
|
|
1724
|
-
provider: config.id,
|
|
1713
|
+
return auth.initiateSSO(config.id, {
|
|
1725
1714
|
redirect_uri: redirectUri,
|
|
1726
1715
|
state,
|
|
1727
1716
|
scopes: options.scopes ?? config.defaultScopes,
|
|
@@ -1830,6 +1819,16 @@ const ssoProviders = {
|
|
|
1830
1819
|
authDomain: "www.facebook.com",
|
|
1831
1820
|
buttonText: "Continue with Facebook"
|
|
1832
1821
|
}
|
|
1822
|
+
}),
|
|
1823
|
+
custom: createSSOProvider({
|
|
1824
|
+
id: "custom",
|
|
1825
|
+
name: "Custom",
|
|
1826
|
+
color: "#000000",
|
|
1827
|
+
icon: "custom",
|
|
1828
|
+
defaultScopes: [],
|
|
1829
|
+
metadata: {
|
|
1830
|
+
buttonText: "Continue with Custom"
|
|
1831
|
+
}
|
|
1833
1832
|
})
|
|
1834
1833
|
};
|
|
1835
1834
|
const sso = {
|
|
@@ -1931,13 +1930,13 @@ function accountToUser(account) {
|
|
|
1931
1930
|
id: account.person.id,
|
|
1932
1931
|
accountId: account.id,
|
|
1933
1932
|
name: account.person.name,
|
|
1934
|
-
email: account.person.email
|
|
1933
|
+
email: account.person.email,
|
|
1935
1934
|
type: account.account_type,
|
|
1936
|
-
roles: account.
|
|
1935
|
+
roles: account.roles,
|
|
1937
1936
|
isActive: account.is_active,
|
|
1938
1937
|
isVerified: account.is_verified,
|
|
1939
1938
|
person: account.person,
|
|
1940
|
-
lastLogin: account.last_login
|
|
1939
|
+
lastLogin: account.last_login,
|
|
1941
1940
|
hasPersonLinked: true
|
|
1942
1941
|
};
|
|
1943
1942
|
}
|
|
@@ -1950,9 +1949,10 @@ function accountToUser(account) {
|
|
|
1950
1949
|
name: account.display_name,
|
|
1951
1950
|
email: emailMethod == null ? void 0 : emailMethod.identifier,
|
|
1952
1951
|
type: account.account_type,
|
|
1952
|
+
roles: account.roles,
|
|
1953
1953
|
isActive: account.is_active,
|
|
1954
1954
|
isVerified: account.is_verified,
|
|
1955
|
-
lastLogin: account.last_login
|
|
1955
|
+
lastLogin: account.last_login,
|
|
1956
1956
|
hasPersonLinked: false
|
|
1957
1957
|
};
|
|
1958
1958
|
}
|
|
@@ -2110,20 +2110,20 @@ function useAuth() {
|
|
|
2110
2110
|
const api = authApi;
|
|
2111
2111
|
const emitter = eventEmitter;
|
|
2112
2112
|
const authMethods = {
|
|
2113
|
-
initiateSSO: async (params) => {
|
|
2114
|
-
const { data } = await api.initiateSSO(params);
|
|
2113
|
+
initiateSSO: async (provider, params) => {
|
|
2114
|
+
const { data } = await api.initiateSSO(provider, params);
|
|
2115
2115
|
return data.authorization_url;
|
|
2116
2116
|
},
|
|
2117
|
-
loginWithSSO: async (params) => {
|
|
2118
|
-
const { data } = await api.ssoCallback(params);
|
|
2117
|
+
loginWithSSO: async (provider, params) => {
|
|
2118
|
+
const { data } = await api.ssoCallback(provider, params);
|
|
2119
2119
|
if (data.success === true && data.requires_verification !== true) {
|
|
2120
2120
|
await checkAuth();
|
|
2121
2121
|
}
|
|
2122
2122
|
emitter.emit(AuthState.LOGIN);
|
|
2123
2123
|
return data;
|
|
2124
2124
|
},
|
|
2125
|
-
linkSSOProvider: async (params) => {
|
|
2126
|
-
await api.linkSSOProvider(params);
|
|
2125
|
+
linkSSOProvider: async (provider, params) => {
|
|
2126
|
+
await api.linkSSOProvider(provider, params);
|
|
2127
2127
|
await checkAuth();
|
|
2128
2128
|
},
|
|
2129
2129
|
unlinkSSOProvider: async (provider) => {
|
|
@@ -2167,10 +2167,7 @@ function useAuth() {
|
|
|
2167
2167
|
emitter.emit(AuthState.LOGOUT);
|
|
2168
2168
|
}
|
|
2169
2169
|
async function login(credentials) {
|
|
2170
|
-
const { data } = await api.login(
|
|
2171
|
-
credentials.email.toLowerCase(),
|
|
2172
|
-
credentials.password
|
|
2173
|
-
);
|
|
2170
|
+
const { data } = await api.login(credentials);
|
|
2174
2171
|
if (data.success === true && data.requires_verification !== true) {
|
|
2175
2172
|
await checkAuth();
|
|
2176
2173
|
}
|
|
@@ -2253,7 +2250,7 @@ function useAuth() {
|
|
|
2253
2250
|
return data;
|
|
2254
2251
|
}
|
|
2255
2252
|
async function forgotPassword(email) {
|
|
2256
|
-
await api.forgotPassword(email);
|
|
2253
|
+
await api.forgotPassword({ email });
|
|
2257
2254
|
}
|
|
2258
2255
|
async function verifyResetToken(token) {
|
|
2259
2256
|
await api.verifyResetToken(token);
|
|
@@ -2277,15 +2274,6 @@ function useAuth() {
|
|
|
2277
2274
|
accountInfo.value = data;
|
|
2278
2275
|
emitter.emit(AuthState.PROFILE_UPDATE);
|
|
2279
2276
|
}
|
|
2280
|
-
async function activateAccount(accountId) {
|
|
2281
|
-
await api.activateAccount(accountId);
|
|
2282
|
-
}
|
|
2283
|
-
async function deactivateAccount(accountId) {
|
|
2284
|
-
await api.deactivateAccount(accountId);
|
|
2285
|
-
}
|
|
2286
|
-
async function deleteAccount(accountId) {
|
|
2287
|
-
await api.deleteAccount(accountId);
|
|
2288
|
-
}
|
|
2289
2277
|
async function deleteCurrentUser() {
|
|
2290
2278
|
await api.deleteCurrentUser();
|
|
2291
2279
|
accountInfo.value = null;
|
|
@@ -2294,7 +2282,7 @@ function useAuth() {
|
|
|
2294
2282
|
await api.sendVerification({ email });
|
|
2295
2283
|
}
|
|
2296
2284
|
async function verifyEmail(token) {
|
|
2297
|
-
await api.verifyEmail(token);
|
|
2285
|
+
await api.verifyEmail({ token });
|
|
2298
2286
|
await checkAuth();
|
|
2299
2287
|
emitter.emit(AuthState.EMAIL_VERIFIED);
|
|
2300
2288
|
}
|
|
@@ -2302,39 +2290,29 @@ function useAuth() {
|
|
|
2302
2290
|
await api.refreshSession();
|
|
2303
2291
|
emitter.emit(AuthState.SESSION_REFRESH);
|
|
2304
2292
|
}
|
|
2305
|
-
async function getSessions(
|
|
2306
|
-
|
|
2307
|
-
const id = accountId ?? ((_a = user.value) == null ? void 0 : _a.accountId);
|
|
2308
|
-
if (id === void 0 || id === "") {
|
|
2309
|
-
throw new Error("No account ID available");
|
|
2310
|
-
}
|
|
2311
|
-
return api.getSessions(id);
|
|
2293
|
+
async function getSessions() {
|
|
2294
|
+
return api.getSessions();
|
|
2312
2295
|
}
|
|
2313
2296
|
async function revokeSession(sessionToken) {
|
|
2314
2297
|
await api.revokeSession(sessionToken);
|
|
2315
2298
|
}
|
|
2316
|
-
async function revokeAllSessions(
|
|
2317
|
-
|
|
2318
|
-
const id = accountId ?? ((_a = user.value) == null ? void 0 : _a.accountId);
|
|
2319
|
-
if (id === void 0 || id === "") {
|
|
2320
|
-
throw new Error("No account ID available");
|
|
2321
|
-
}
|
|
2322
|
-
await api.revokeAllSessions(id);
|
|
2299
|
+
async function revokeAllSessions() {
|
|
2300
|
+
await api.revokeAllSessions();
|
|
2323
2301
|
}
|
|
2324
|
-
async function initiateSSO(params) {
|
|
2325
|
-
const { data } = await api.initiateSSO(params);
|
|
2302
|
+
async function initiateSSO(provider, params) {
|
|
2303
|
+
const { data } = await api.initiateSSO(provider, params);
|
|
2326
2304
|
return data.authorization_url;
|
|
2327
2305
|
}
|
|
2328
|
-
async function loginWithSSO(params) {
|
|
2329
|
-
const { data } = await api.ssoCallback(params);
|
|
2306
|
+
async function loginWithSSO(provider, params) {
|
|
2307
|
+
const { data } = await api.ssoCallback(provider, params);
|
|
2330
2308
|
if (data.success === true && data.requires_verification !== true) {
|
|
2331
2309
|
await checkAuth();
|
|
2332
2310
|
}
|
|
2333
2311
|
emitter.emit(AuthState.LOGIN);
|
|
2334
2312
|
return data;
|
|
2335
2313
|
}
|
|
2336
|
-
async function linkSSOProvider(params) {
|
|
2337
|
-
await api.linkSSOProvider(params);
|
|
2314
|
+
async function linkSSOProvider(provider, params) {
|
|
2315
|
+
await api.linkSSOProvider(provider, params);
|
|
2338
2316
|
await checkAuth();
|
|
2339
2317
|
}
|
|
2340
2318
|
async function unlinkSSOProvider(provider) {
|
|
@@ -2382,10 +2360,6 @@ function useAuth() {
|
|
|
2382
2360
|
// Email Verification Actions
|
|
2383
2361
|
sendVerification,
|
|
2384
2362
|
verifyEmail,
|
|
2385
|
-
// Admin Actions
|
|
2386
|
-
activateAccount,
|
|
2387
|
-
deactivateAccount,
|
|
2388
|
-
deleteAccount,
|
|
2389
2363
|
// Session Management
|
|
2390
2364
|
getSessions,
|
|
2391
2365
|
revokeSession,
|
package/dist/sso.d.ts
CHANGED
|
@@ -90,12 +90,12 @@ export interface SSOProviderInstance extends SSOProviderConfig {
|
|
|
90
90
|
* Complete OAuth flow after callback
|
|
91
91
|
* Call this on your callback page
|
|
92
92
|
*/
|
|
93
|
-
callback: (code: string, state
|
|
93
|
+
callback: (code: string, state: string) => Promise<AuthenticationResponse>;
|
|
94
94
|
/**
|
|
95
95
|
* Link this provider to the current logged-in user
|
|
96
96
|
* Call this after OAuth redirect completes on link callback page
|
|
97
97
|
*/
|
|
98
|
-
link: (code: string, state
|
|
98
|
+
link: (code: string, state: string) => Promise<void>;
|
|
99
99
|
/**
|
|
100
100
|
* Unlink this provider from the current user
|
|
101
101
|
*/
|
package/dist/types.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface TenantInfo {
|
|
|
37
37
|
updated_at: string;
|
|
38
38
|
}
|
|
39
39
|
export type AuthenticationMethodType = 'password' | 'email_token' | 'sso' | 'otp';
|
|
40
|
-
export type SSOProvider = 'google' | 'microsoft' | 'github' | 'okta' | 'apple' | 'facebook';
|
|
40
|
+
export type SSOProvider = 'google' | 'microsoft' | 'github' | 'okta' | 'apple' | 'facebook' | 'custom';
|
|
41
41
|
export interface AuthenticationAccount {
|
|
42
42
|
created_at?: string;
|
|
43
43
|
updated_at?: string;
|
|
@@ -58,9 +58,9 @@ export interface PersonInfo {
|
|
|
58
58
|
name: string;
|
|
59
59
|
first_name: string;
|
|
60
60
|
last_name: string;
|
|
61
|
-
email?: string
|
|
62
|
-
phone_number?: string
|
|
63
|
-
|
|
61
|
+
email?: string;
|
|
62
|
+
phone_number?: string;
|
|
63
|
+
tags: string[];
|
|
64
64
|
}
|
|
65
65
|
export interface AuthMethodInfo {
|
|
66
66
|
id: string;
|
|
@@ -69,7 +69,7 @@ export interface AuthMethodInfo {
|
|
|
69
69
|
is_verified: boolean;
|
|
70
70
|
last_used?: string;
|
|
71
71
|
use_count: number;
|
|
72
|
-
provider?:
|
|
72
|
+
provider?: string;
|
|
73
73
|
provider_user_id?: string;
|
|
74
74
|
}
|
|
75
75
|
export interface AccountInfo {
|
|
@@ -78,9 +78,10 @@ export interface AccountInfo {
|
|
|
78
78
|
display_name: string;
|
|
79
79
|
is_active: boolean;
|
|
80
80
|
is_verified: boolean;
|
|
81
|
-
last_login?: string
|
|
81
|
+
last_login?: string;
|
|
82
|
+
roles: string[];
|
|
82
83
|
authentication_methods: AuthMethodInfo[];
|
|
83
|
-
person?: PersonInfo
|
|
84
|
+
person?: PersonInfo;
|
|
84
85
|
}
|
|
85
86
|
export interface EntityInfo {
|
|
86
87
|
id: string;
|
|
@@ -158,6 +159,29 @@ export interface SendVerificationRequest {
|
|
|
158
159
|
export interface VerifyEmailRequest {
|
|
159
160
|
token: string;
|
|
160
161
|
}
|
|
162
|
+
export interface EmailTokenSendRequest {
|
|
163
|
+
email: string;
|
|
164
|
+
}
|
|
165
|
+
export interface EmailTokenVerifyRequest {
|
|
166
|
+
email: string;
|
|
167
|
+
token: string;
|
|
168
|
+
}
|
|
169
|
+
export interface OTPSendRequest {
|
|
170
|
+
phone_number: string;
|
|
171
|
+
}
|
|
172
|
+
export interface OTPVerifyRequest {
|
|
173
|
+
phone_number: string;
|
|
174
|
+
otp_code: string;
|
|
175
|
+
nonce: string;
|
|
176
|
+
verification_hash: string;
|
|
177
|
+
timestamp: number;
|
|
178
|
+
}
|
|
179
|
+
export interface SSOLoginRequest {
|
|
180
|
+
provider: SSOProvider;
|
|
181
|
+
authorization_code?: string;
|
|
182
|
+
id_token?: string;
|
|
183
|
+
access_token?: string;
|
|
184
|
+
}
|
|
161
185
|
export interface NewUser extends RegisterRequest {
|
|
162
186
|
confirmPassword: string;
|
|
163
187
|
}
|
|
@@ -186,34 +210,28 @@ export interface OTPMetadata {
|
|
|
186
210
|
};
|
|
187
211
|
}
|
|
188
212
|
export interface SSOMetadata {
|
|
189
|
-
provider:
|
|
213
|
+
provider: string;
|
|
190
214
|
sso_user_info: {
|
|
191
215
|
[key: string]: any;
|
|
192
216
|
};
|
|
193
217
|
can_create_account?: boolean;
|
|
194
218
|
}
|
|
195
219
|
export interface SSOInitiateRequest {
|
|
196
|
-
provider: SSOProvider;
|
|
197
220
|
redirect_uri?: string;
|
|
198
|
-
state
|
|
221
|
+
state: string;
|
|
199
222
|
scopes?: string[];
|
|
200
|
-
params?:
|
|
201
|
-
|
|
202
|
-
|
|
223
|
+
params?: {
|
|
224
|
+
[key: string]: any;
|
|
225
|
+
};
|
|
203
226
|
}
|
|
204
227
|
export interface SSOCallbackRequest {
|
|
205
|
-
provider: SSOProvider;
|
|
206
228
|
code: string;
|
|
207
|
-
state
|
|
229
|
+
state: string;
|
|
208
230
|
}
|
|
209
231
|
export interface SSOLinkRequest {
|
|
210
|
-
provider: SSOProvider;
|
|
211
232
|
code: string;
|
|
212
233
|
state: string;
|
|
213
234
|
}
|
|
214
|
-
export interface SSOUnlinkRequest {
|
|
215
|
-
provider: SSOProvider;
|
|
216
|
-
}
|
|
217
235
|
export interface AuthenticationResponse {
|
|
218
236
|
success: boolean;
|
|
219
237
|
account_id?: string;
|
|
@@ -252,13 +270,41 @@ export type DeleteSessionResponse = AxiosResponse<MessageResponse>;
|
|
|
252
270
|
export type DeleteAllSessionsResponse = AxiosResponse<MessageResponse>;
|
|
253
271
|
export type CleanupSessionsResponse = AxiosResponse<MessageResponse>;
|
|
254
272
|
export type GetMethodsResponse = AxiosResponse<AvailableMethodsResponse>;
|
|
255
|
-
export
|
|
273
|
+
export interface SSOInitiateResponse {
|
|
256
274
|
authorization_url: string;
|
|
257
|
-
}
|
|
258
|
-
export
|
|
259
|
-
|
|
260
|
-
|
|
275
|
+
}
|
|
276
|
+
export interface SSOCallbackResponse {
|
|
277
|
+
success: boolean;
|
|
278
|
+
account_id?: string;
|
|
279
|
+
session_token?: string;
|
|
280
|
+
requires_verification?: boolean;
|
|
281
|
+
metadata?: {
|
|
282
|
+
[key: string]: any;
|
|
283
|
+
};
|
|
284
|
+
message?: string;
|
|
285
|
+
}
|
|
286
|
+
export interface SSOLinkResponse {
|
|
287
|
+
success?: boolean;
|
|
288
|
+
message?: string;
|
|
289
|
+
provider?: string;
|
|
290
|
+
provider_user_id?: string;
|
|
291
|
+
email?: string;
|
|
292
|
+
}
|
|
293
|
+
export interface SSOUnlinkResponse {
|
|
294
|
+
success?: boolean;
|
|
295
|
+
message?: string;
|
|
296
|
+
}
|
|
297
|
+
export type InitiateSSOResponse = AxiosResponse<SSOInitiateResponse>;
|
|
298
|
+
export type CallbackSSOResponse = AxiosResponse<SSOCallbackResponse>;
|
|
299
|
+
export type LinkSSOResponse = AxiosResponse<SSOLinkResponse>;
|
|
300
|
+
export type UnlinkSSOResponse = AxiosResponse<SSOUnlinkResponse>;
|
|
261
301
|
export type GetTenantsResponse = AxiosResponse<TenantInfo[]>;
|
|
302
|
+
export type GetAuthStatusResponse = AxiosResponse<AuthStatusResponse>;
|
|
303
|
+
export type SendEmailTokenResponse = AxiosResponse<AuthenticationResponse>;
|
|
304
|
+
export type VerifyEmailTokenResponse = AxiosResponse<AuthenticationResponse>;
|
|
305
|
+
export type SendOTPResponse = AxiosResponse<AuthenticationResponse>;
|
|
306
|
+
export type VerifyOTPResponse = AxiosResponse<AuthenticationResponse>;
|
|
307
|
+
export type LegacySSOLoginResponse = AxiosResponse<AuthenticationResponse>;
|
|
262
308
|
/**
|
|
263
309
|
* Extract unified user from account info
|
|
264
310
|
* All accounts are identities that may be linked to a person
|