@eaccess/auth 0.1.13 → 0.1.15
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/index.cjs +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -92,9 +92,12 @@ interface OAuthUserData {
|
|
|
92
92
|
name?: string;
|
|
93
93
|
avatar?: string;
|
|
94
94
|
}
|
|
95
|
+
interface OAuthCallbackResult {
|
|
96
|
+
isNewUser: boolean;
|
|
97
|
+
}
|
|
95
98
|
interface OAuthProvider {
|
|
96
99
|
getAuthUrl(state?: string, scopes?: string[]): string;
|
|
97
|
-
handleCallback(req: Request): Promise<
|
|
100
|
+
handleCallback(req: Request): Promise<OAuthCallbackResult>;
|
|
98
101
|
getUserData(req: Request): Promise<OAuthUserData>;
|
|
99
102
|
}
|
|
100
103
|
interface AuthConfirmation {
|
|
@@ -272,6 +275,7 @@ interface AuthManager$1 {
|
|
|
272
275
|
completeTwoFactorLogin(): Promise<void>;
|
|
273
276
|
logout(): Promise<void>;
|
|
274
277
|
register(email: string, password: string, userId?: string | number, callback?: TokenCallback): Promise<AuthAccount>;
|
|
278
|
+
resyncSession(force?: boolean): Promise<void>;
|
|
275
279
|
getId(): number | null;
|
|
276
280
|
getEmail(): string | null;
|
|
277
281
|
getStatus(): number | null;
|
|
@@ -1146,8 +1150,8 @@ declare abstract class BaseOAuthProvider implements OAuthProvider {
|
|
|
1146
1150
|
constructor(config: OAuthProviderConfig, authConfig: AuthConfig, authManager: AuthManager);
|
|
1147
1151
|
abstract getAuthUrl(state?: string, scopes?: string[]): string;
|
|
1148
1152
|
abstract getUserData(req: Request): Promise<OAuthUserData>;
|
|
1149
|
-
handleCallback(req: Request): Promise<
|
|
1150
|
-
protected processOAuthLogin(userData: OAuthUserData, req: Request): Promise<
|
|
1153
|
+
handleCallback(req: Request): Promise<OAuthCallbackResult>;
|
|
1154
|
+
protected processOAuthLogin(userData: OAuthUserData, req: Request): Promise<OAuthCallbackResult>;
|
|
1151
1155
|
protected abstract getProviderName(): string;
|
|
1152
1156
|
protected exchangeCodeForToken(code: string, tokenUrl: string): Promise<string>;
|
|
1153
1157
|
protected fetchUserFromAPI(accessToken: string, apiUrl: string): Promise<any>;
|
|
@@ -1175,4 +1179,4 @@ declare class AzureProvider extends BaseOAuthProvider {
|
|
|
1175
1179
|
protected exchangeCodeForToken(code: string, tokenUrl: string): Promise<string>;
|
|
1176
1180
|
}
|
|
1177
1181
|
|
|
1178
|
-
export { ActivityLogger, type AuthAccount, type AuthActivity, AuthActivityAction, type AuthActivityActionType, type AuthConfig, type AuthConfirmation, type AuthContext, AuthError, type AuthManager$1 as AuthManager, type AuthProvider, type AuthRemember, type AuthReset, AuthRole, type AuthSession, AuthStatus, AzureProvider, type AzureProviderConfig, BaseOAuthProvider, ConfirmationExpiredError, ConfirmationNotFoundError, EmailNotVerifiedError, EmailTakenError, GitHubProvider, type GitHubProviderConfig, GoogleProvider, type GoogleProviderConfig, InvalidBackupCodeError, InvalidEmailError, InvalidPasswordError, InvalidTokenError, InvalidTwoFactorCodeError, type OAuthProvider, type OAuthProviderConfig, type OAuthUserData, OtpProvider, ResetDisabledError, ResetExpiredError, ResetNotFoundError, SecondFactorRequiredError, type TokenCallback, TooManyResetsError, TotpProvider, TwoFactorAlreadyEnabledError, type TwoFactorChallenge, TwoFactorExpiredError, TwoFactorManager, TwoFactorMechanism, type TwoFactorMethod, TwoFactorNotSetupError, TwoFactorSetupIncompleteError, type TwoFactorSetupResult, type TwoFactorToken, type UserIdentifier, UserInactiveError, UserNotFoundError, UserNotLoggedInError, addRoleForUserBy, addRoleToUser, authFunctions, changePasswordForUserBy, cleanupExpiredTokens, confirmResetPassword, createAuthContext, createAuthMiddleware, createAuthTables, createUser, deleteUserBy, dropAuthTables, forceLogoutForUserBy, getAuthTableStats, getUserRoles, hasRoleForUserBy, initiatePasswordResetForUserBy, isValidEmail, register, removeRoleForUserBy, removeRoleFromUser, resetPassword, setStatusForUserBy, setUserRoles, userExistsByEmail, validateEmail };
|
|
1182
|
+
export { ActivityLogger, type AuthAccount, type AuthActivity, AuthActivityAction, type AuthActivityActionType, type AuthConfig, type AuthConfirmation, type AuthContext, AuthError, type AuthManager$1 as AuthManager, type AuthProvider, type AuthRemember, type AuthReset, AuthRole, type AuthSession, AuthStatus, AzureProvider, type AzureProviderConfig, BaseOAuthProvider, ConfirmationExpiredError, ConfirmationNotFoundError, EmailNotVerifiedError, EmailTakenError, GitHubProvider, type GitHubProviderConfig, GoogleProvider, type GoogleProviderConfig, InvalidBackupCodeError, InvalidEmailError, InvalidPasswordError, InvalidTokenError, InvalidTwoFactorCodeError, type OAuthCallbackResult, type OAuthProvider, type OAuthProviderConfig, type OAuthUserData, OtpProvider, ResetDisabledError, ResetExpiredError, ResetNotFoundError, SecondFactorRequiredError, type TokenCallback, TooManyResetsError, TotpProvider, TwoFactorAlreadyEnabledError, type TwoFactorChallenge, TwoFactorExpiredError, TwoFactorManager, TwoFactorMechanism, type TwoFactorMethod, TwoFactorNotSetupError, TwoFactorSetupIncompleteError, type TwoFactorSetupResult, type TwoFactorToken, type UserIdentifier, UserInactiveError, UserNotFoundError, UserNotLoggedInError, addRoleForUserBy, addRoleToUser, authFunctions, changePasswordForUserBy, cleanupExpiredTokens, confirmResetPassword, createAuthContext, createAuthMiddleware, createAuthTables, createUser, deleteUserBy, dropAuthTables, forceLogoutForUserBy, getAuthTableStats, getUserRoles, hasRoleForUserBy, initiatePasswordResetForUserBy, isValidEmail, register, removeRoleForUserBy, removeRoleFromUser, resetPassword, setStatusForUserBy, setUserRoles, userExistsByEmail, validateEmail };
|
package/dist/index.d.ts
CHANGED
|
@@ -92,9 +92,12 @@ interface OAuthUserData {
|
|
|
92
92
|
name?: string;
|
|
93
93
|
avatar?: string;
|
|
94
94
|
}
|
|
95
|
+
interface OAuthCallbackResult {
|
|
96
|
+
isNewUser: boolean;
|
|
97
|
+
}
|
|
95
98
|
interface OAuthProvider {
|
|
96
99
|
getAuthUrl(state?: string, scopes?: string[]): string;
|
|
97
|
-
handleCallback(req: Request): Promise<
|
|
100
|
+
handleCallback(req: Request): Promise<OAuthCallbackResult>;
|
|
98
101
|
getUserData(req: Request): Promise<OAuthUserData>;
|
|
99
102
|
}
|
|
100
103
|
interface AuthConfirmation {
|
|
@@ -272,6 +275,7 @@ interface AuthManager$1 {
|
|
|
272
275
|
completeTwoFactorLogin(): Promise<void>;
|
|
273
276
|
logout(): Promise<void>;
|
|
274
277
|
register(email: string, password: string, userId?: string | number, callback?: TokenCallback): Promise<AuthAccount>;
|
|
278
|
+
resyncSession(force?: boolean): Promise<void>;
|
|
275
279
|
getId(): number | null;
|
|
276
280
|
getEmail(): string | null;
|
|
277
281
|
getStatus(): number | null;
|
|
@@ -1146,8 +1150,8 @@ declare abstract class BaseOAuthProvider implements OAuthProvider {
|
|
|
1146
1150
|
constructor(config: OAuthProviderConfig, authConfig: AuthConfig, authManager: AuthManager);
|
|
1147
1151
|
abstract getAuthUrl(state?: string, scopes?: string[]): string;
|
|
1148
1152
|
abstract getUserData(req: Request): Promise<OAuthUserData>;
|
|
1149
|
-
handleCallback(req: Request): Promise<
|
|
1150
|
-
protected processOAuthLogin(userData: OAuthUserData, req: Request): Promise<
|
|
1153
|
+
handleCallback(req: Request): Promise<OAuthCallbackResult>;
|
|
1154
|
+
protected processOAuthLogin(userData: OAuthUserData, req: Request): Promise<OAuthCallbackResult>;
|
|
1151
1155
|
protected abstract getProviderName(): string;
|
|
1152
1156
|
protected exchangeCodeForToken(code: string, tokenUrl: string): Promise<string>;
|
|
1153
1157
|
protected fetchUserFromAPI(accessToken: string, apiUrl: string): Promise<any>;
|
|
@@ -1175,4 +1179,4 @@ declare class AzureProvider extends BaseOAuthProvider {
|
|
|
1175
1179
|
protected exchangeCodeForToken(code: string, tokenUrl: string): Promise<string>;
|
|
1176
1180
|
}
|
|
1177
1181
|
|
|
1178
|
-
export { ActivityLogger, type AuthAccount, type AuthActivity, AuthActivityAction, type AuthActivityActionType, type AuthConfig, type AuthConfirmation, type AuthContext, AuthError, type AuthManager$1 as AuthManager, type AuthProvider, type AuthRemember, type AuthReset, AuthRole, type AuthSession, AuthStatus, AzureProvider, type AzureProviderConfig, BaseOAuthProvider, ConfirmationExpiredError, ConfirmationNotFoundError, EmailNotVerifiedError, EmailTakenError, GitHubProvider, type GitHubProviderConfig, GoogleProvider, type GoogleProviderConfig, InvalidBackupCodeError, InvalidEmailError, InvalidPasswordError, InvalidTokenError, InvalidTwoFactorCodeError, type OAuthProvider, type OAuthProviderConfig, type OAuthUserData, OtpProvider, ResetDisabledError, ResetExpiredError, ResetNotFoundError, SecondFactorRequiredError, type TokenCallback, TooManyResetsError, TotpProvider, TwoFactorAlreadyEnabledError, type TwoFactorChallenge, TwoFactorExpiredError, TwoFactorManager, TwoFactorMechanism, type TwoFactorMethod, TwoFactorNotSetupError, TwoFactorSetupIncompleteError, type TwoFactorSetupResult, type TwoFactorToken, type UserIdentifier, UserInactiveError, UserNotFoundError, UserNotLoggedInError, addRoleForUserBy, addRoleToUser, authFunctions, changePasswordForUserBy, cleanupExpiredTokens, confirmResetPassword, createAuthContext, createAuthMiddleware, createAuthTables, createUser, deleteUserBy, dropAuthTables, forceLogoutForUserBy, getAuthTableStats, getUserRoles, hasRoleForUserBy, initiatePasswordResetForUserBy, isValidEmail, register, removeRoleForUserBy, removeRoleFromUser, resetPassword, setStatusForUserBy, setUserRoles, userExistsByEmail, validateEmail };
|
|
1182
|
+
export { ActivityLogger, type AuthAccount, type AuthActivity, AuthActivityAction, type AuthActivityActionType, type AuthConfig, type AuthConfirmation, type AuthContext, AuthError, type AuthManager$1 as AuthManager, type AuthProvider, type AuthRemember, type AuthReset, AuthRole, type AuthSession, AuthStatus, AzureProvider, type AzureProviderConfig, BaseOAuthProvider, ConfirmationExpiredError, ConfirmationNotFoundError, EmailNotVerifiedError, EmailTakenError, GitHubProvider, type GitHubProviderConfig, GoogleProvider, type GoogleProviderConfig, InvalidBackupCodeError, InvalidEmailError, InvalidPasswordError, InvalidTokenError, InvalidTwoFactorCodeError, type OAuthCallbackResult, type OAuthProvider, type OAuthProviderConfig, type OAuthUserData, OtpProvider, ResetDisabledError, ResetExpiredError, ResetNotFoundError, SecondFactorRequiredError, type TokenCallback, TooManyResetsError, TotpProvider, TwoFactorAlreadyEnabledError, type TwoFactorChallenge, TwoFactorExpiredError, TwoFactorManager, TwoFactorMechanism, type TwoFactorMethod, TwoFactorNotSetupError, TwoFactorSetupIncompleteError, type TwoFactorSetupResult, type TwoFactorToken, type UserIdentifier, UserInactiveError, UserNotFoundError, UserNotLoggedInError, addRoleForUserBy, addRoleToUser, authFunctions, changePasswordForUserBy, cleanupExpiredTokens, confirmResetPassword, createAuthContext, createAuthMiddleware, createAuthTables, createUser, deleteUserBy, dropAuthTables, forceLogoutForUserBy, getAuthTableStats, getUserRoles, hasRoleForUserBy, initiatePasswordResetForUserBy, isValidEmail, register, removeRoleForUserBy, removeRoleFromUser, resetPassword, setStatusForUserBy, setUserRoles, userExistsByEmail, validateEmail };
|
package/dist/index.js
CHANGED
|
@@ -625,7 +625,7 @@ var BaseOAuthProvider = class {
|
|
|
625
625
|
}
|
|
626
626
|
async handleCallback(req) {
|
|
627
627
|
const userData = await this.getUserData(req);
|
|
628
|
-
|
|
628
|
+
return this.processOAuthLogin(userData, req);
|
|
629
629
|
}
|
|
630
630
|
async processOAuthLogin(userData, req) {
|
|
631
631
|
const { queries } = this.authManager;
|
|
@@ -635,7 +635,7 @@ var BaseOAuthProvider = class {
|
|
|
635
635
|
const account2 = await queries.findAccountById(existingProvider.account_id);
|
|
636
636
|
if (account2) {
|
|
637
637
|
await this.authManager.onLoginSuccessful(account2, false);
|
|
638
|
-
return;
|
|
638
|
+
return { isNewUser: false };
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
641
|
if (userData.email) {
|
|
@@ -670,6 +670,7 @@ var BaseOAuthProvider = class {
|
|
|
670
670
|
providerAvatar: userData.avatar || null
|
|
671
671
|
});
|
|
672
672
|
await this.authManager.onLoginSuccessful(account, false);
|
|
673
|
+
return { isNewUser: true };
|
|
673
674
|
}
|
|
674
675
|
async exchangeCodeForToken(code, tokenUrl) {
|
|
675
676
|
const response = await fetch(tokenUrl, {
|