Jelajahi Sumber

improve typings

Yuki Takei 1 tahun lalu
induk
melakukan
426f1ceedd

+ 2 - 2
apps/app/src/features/external-user-group/server/service/external-user-group-sync.ts

@@ -1,4 +1,4 @@
-import type { IUserHasId } from '@growi/core';
+import type { IExternalAuthProviderType, IUserHasId } from '@growi/core';
 
 
 import { SocketEventName } from '~/interfaces/websocket';
 import { SocketEventName } from '~/interfaces/websocket';
 import ExternalAccount from '~/server/models/external-account';
 import ExternalAccount from '~/server/models/external-account';
@@ -37,7 +37,7 @@ abstract class ExternalUserGroupSyncService implements S2sMessageHandlable {
 
 
   groupProviderType: ExternalGroupProviderType; // name of external service that contains user group info (e.g: ldap, keycloak)
   groupProviderType: ExternalGroupProviderType; // name of external service that contains user group info (e.g: ldap, keycloak)
 
 
-  authProviderType: string | null; // auth provider type (e.g: ldap, oidc). Has to be set before syncExternalUserGroups execution.
+  authProviderType: IExternalAuthProviderType | null; // auth provider type (e.g: ldap, oidc). Has to be set before syncExternalUserGroups execution.
 
 
   socketIoService: any;
   socketIoService: any;
 
 

+ 2 - 1
apps/app/src/server/service/external-account.ts

@@ -1,3 +1,4 @@
+import type { IExternalAuthProviderType } from '@growi/core';
 import { ErrorV3 } from '@growi/core/dist/models';
 import { ErrorV3 } from '@growi/core/dist/models';
 
 
 import { LoginErrorCode } from '~/interfaces/errors/login-error';
 import { LoginErrorCode } from '~/interfaces/errors/login-error';
@@ -22,7 +23,7 @@ class ExternalAccountService {
 
 
   async getOrCreateUser(
   async getOrCreateUser(
       userInfo: {id: string, username: string, name?: string, email?: string},
       userInfo: {id: string, username: string, name?: string, email?: string},
-      providerId: 'ldap' | 'google' | 'github' | 'saml' | 'oidc',
+      providerId: IExternalAuthProviderType,
   ): Promise<ExternalAccountDocument | undefined> {
   ): Promise<ExternalAccountDocument | undefined> {
     // get option
     // get option
     const isSameUsernameTreatedAsIdenticalUser = this.passportService.isSameUsernameTreatedAsIdenticalUser(providerId);
     const isSameUsernameTreatedAsIdenticalUser = this.passportService.isSameUsernameTreatedAsIdenticalUser(providerId);

+ 5 - 3
apps/app/src/server/service/passport.ts

@@ -1,5 +1,6 @@
 import type { IncomingMessage } from 'http';
 import type { IncomingMessage } from 'http';
 
 
+import type { IExternalAuthProviderType } from '@growi/core';
 import axiosRetry from 'axios-retry';
 import axiosRetry from 'axios-retry';
 import luceneQueryParser from 'lucene-query-parser';
 import luceneQueryParser from 'lucene-query-parser';
 import { Strategy as OidcStrategy, Issuer as OIDCIssuer, custom } from 'openid-client';
 import { Strategy as OidcStrategy, Issuer as OIDCIssuer, custom } from 'openid-client';
@@ -18,6 +19,7 @@ import loggerFactory from '~/utils/logger';
 import S2sMessage from '../models/vo/s2s-message';
 import S2sMessage from '../models/vo/s2s-message';
 
 
 import { configManager } from './config-manager';
 import { configManager } from './config-manager';
+import type { ConfigKey } from './config-manager/config-definition';
 import type { S2sMessageHandlable } from './s2s-messaging/handlable';
 import type { S2sMessageHandlable } from './s2s-messaging/handlable';
 
 
 const logger = loggerFactory('growi:service:PassportService');
 const logger = loggerFactory('growi:service:PassportService');
@@ -86,7 +88,7 @@ class PassportService implements S2sMessageHandlable {
     'security:passport-saml:attrMapId',
     'security:passport-saml:attrMapId',
     'security:passport-saml:attrMapUsername',
     'security:passport-saml:attrMapUsername',
     'security:passport-saml:attrMapMail',
     'security:passport-saml:attrMapMail',
-  ];
+  ] satisfies ConfigKey[];
 
 
   setupFunction = {
   setupFunction = {
     local: {
     local: {
@@ -973,11 +975,11 @@ class PassportService implements S2sMessageHandlable {
     this.isSerializerSetup = true;
     this.isSerializerSetup = true;
   }
   }
 
 
-  isSameUsernameTreatedAsIdenticalUser(providerType: 'ldap' | 'google' | 'github' | 'saml' | 'oidc'): boolean {
+  isSameUsernameTreatedAsIdenticalUser(providerType: IExternalAuthProviderType): boolean {
     return configManager.getConfig(`security:passport-${providerType}:isSameUsernameTreatedAsIdenticalUser`);
     return configManager.getConfig(`security:passport-${providerType}:isSameUsernameTreatedAsIdenticalUser`);
   }
   }
 
 
-  isSameEmailTreatedAsIdenticalUser(providerType: 'google' | 'github' | 'saml' | 'oidc'): boolean {
+  isSameEmailTreatedAsIdenticalUser(providerType: Exclude<IExternalAuthProviderType, 'ldap'>): boolean {
     return configManager.getConfig(`security:passport-${providerType}:isSameEmailTreatedAsIdenticalUser`);
     return configManager.getConfig(`security:passport-${providerType}:isSameEmailTreatedAsIdenticalUser`);
   }
   }