diff --git a/packages/account-client/src/client.ts b/packages/account-client/src/client.ts index 632f72a6381..937db76d722 100644 --- a/packages/account-client/src/client.ts +++ b/packages/account-client/src/client.ts @@ -23,6 +23,7 @@ import { type PersonId, type PersonInfo, type PersonUuid, + type ProviderInfo, type SocialIdType, Version, type WorkspaceInfoWithStatus, @@ -52,7 +53,7 @@ import { getClientTimezone } from './utils' /** @public */ export interface AccountClient { // Static methods - getProviders: () => Promise + getProviders: () => Promise // RPC getUserWorkspaces: () => Promise @@ -217,7 +218,7 @@ class AccountClientImpl implements AccountClient { this.rpc = withRetryUntilTimeout(this._rpc.bind(this), retryTimeoutMs ?? 5000) } - async getProviders (): Promise { + async getProviders (): Promise { return await withRetryUntilMaxAttempts(async () => { const response = await fetch(concatLink(this.url, '/providers')) diff --git a/packages/core/src/classes.ts b/packages/core/src/classes.ts index 8638c763457..a3fab19b24a 100644 --- a/packages/core/src/classes.ts +++ b/packages/core/src/classes.ts @@ -869,4 +869,9 @@ export interface AccountInfo { locale?: string } +export interface ProviderInfo { + name: string + displayName?: string +} + export type SocialKey = Pick diff --git a/plugins/login-resources/src/components/Providers.svelte b/plugins/login-resources/src/components/Providers.svelte index 4629cb48e91..4a57115734e 100644 --- a/plugins/login-resources/src/components/Providers.svelte +++ b/plugins/login-resources/src/components/Providers.svelte @@ -1,5 +1,5 @@
-
diff --git a/plugins/login-resources/src/components/providers/Google.svelte b/plugins/login-resources/src/components/providers/Google.svelte index aec3f1cfc4c..5f586f980b2 100644 --- a/plugins/login-resources/src/components/providers/Google.svelte +++ b/plugins/login-resources/src/components/providers/Google.svelte @@ -2,9 +2,11 @@ import { Label } from '@hcengineering/ui' import Google from '../icons/Google.svelte' import login from '../../plugin' + + export let displayName = 'Google'
-
diff --git a/plugins/login-resources/src/components/providers/OpenId.svelte b/plugins/login-resources/src/components/providers/OpenId.svelte index 1948f535c81..3de13049b44 100644 --- a/plugins/login-resources/src/components/providers/OpenId.svelte +++ b/plugins/login-resources/src/components/providers/OpenId.svelte @@ -2,9 +2,11 @@ import { Label } from '@hcengineering/ui' import OpenId from '../icons/OpenId.svelte' import login from '../../plugin' + + export let displayName = 'OpenId'
-
diff --git a/plugins/login-resources/src/utils.ts b/plugins/login-resources/src/utils.ts index b93c051147f..f1e9e260ced 100644 --- a/plugins/login-resources/src/utils.ts +++ b/plugins/login-resources/src/utils.ts @@ -30,7 +30,8 @@ import { type AccountUuid, type Person, type WorkspaceInfoWithStatus, - type WorkspaceUserOperation + type WorkspaceUserOperation, + type ProviderInfo } from '@hcengineering/core' import { loginId } from '@hcengineering/login' import platform, { @@ -851,8 +852,8 @@ export async function getLoginInfoFromQuery (): Promise { - let providers: string[] +export async function getProviders (): Promise { + let providers: ProviderInfo[] try { providers = await getAccountClient(null).getProviders() diff --git a/pods/authProviders/src/github.ts b/pods/authProviders/src/github.ts index 8fdf6c45fae..275b332ea43 100644 --- a/pods/authProviders/src/github.ts +++ b/pods/authProviders/src/github.ts @@ -1,4 +1,5 @@ import { type AccountDB } from '@hcengineering/account' +import { type ProviderInfo } from '@hcengineering/core' import { BrandingMap, concatLink, MeasureContext, getBranding, SocialIdType } from '@hcengineering/core' import Router from 'koa-router' import { Strategy as GitHubStrategy } from 'passport-github2' @@ -14,9 +15,11 @@ export function registerGithub ( frontUrl: string, brandings: BrandingMap, signUpDisabled?: boolean -): string | undefined { +): ProviderInfo | undefined { const GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID const GITHUB_CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET + const name = 'github' + const displayName = process.env.GITHUB_DISPLAY_NAME const redirectURL = '/auth/github/callback' if (GITHUB_CLIENT_ID === undefined || GITHUB_CLIENT_SECRET === undefined) return @@ -80,5 +83,5 @@ export function registerGithub ( } ) - return 'github' + return { name, displayName } } diff --git a/pods/authProviders/src/google.ts b/pods/authProviders/src/google.ts index 32575c57b40..6c862f15991 100644 --- a/pods/authProviders/src/google.ts +++ b/pods/authProviders/src/google.ts @@ -1,4 +1,5 @@ import { type AccountDB } from '@hcengineering/account' +import { type ProviderInfo } from '@hcengineering/core' import { BrandingMap, concatLink, MeasureContext, getBranding, SocialIdType } from '@hcengineering/core' import Router from 'koa-router' import { Strategy as GoogleStrategy } from 'passport-google-oauth20' @@ -14,9 +15,11 @@ export function registerGoogle ( frontUrl: string, brandings: BrandingMap, signUpDisabled?: boolean -): string | undefined { +): ProviderInfo | undefined { const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID const GOOGLE_CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET + const name = 'google' + const displayName = process.env.GOOGLE_DISPLAY_NAME const redirectURL = '/auth/google/callback' if (GOOGLE_CLIENT_ID === undefined || GOOGLE_CLIENT_SECRET === undefined) return @@ -85,5 +88,5 @@ export function registerGoogle ( } ) - return 'google' + return { name, displayName } } diff --git a/pods/authProviders/src/index.ts b/pods/authProviders/src/index.ts index 2b8bd73d4c4..af8bc096ab9 100644 --- a/pods/authProviders/src/index.ts +++ b/pods/authProviders/src/index.ts @@ -6,7 +6,7 @@ import { registerGithub } from './github' import { registerGoogle } from './google' import { registerOpenid } from './openid' import { registerToken } from './token' -import { BrandingMap, MeasureContext } from '@hcengineering/core' +import { BrandingMap, MeasureContext, type ProviderInfo } from '@hcengineering/core' import { type AccountDB } from '@hcengineering/account' export type Passport = typeof passport @@ -20,7 +20,7 @@ export type AuthProvider = ( frontUrl: string, brandings: BrandingMap, signUpDisabled?: boolean -) => string | undefined +) => ProviderInfo | undefined export function registerProviders ( ctx: MeasureContext, @@ -62,7 +62,7 @@ export function registerProviders ( registerToken(ctx, passport, router, accountsUrl, db, frontUrl, brandings) - const res: string[] = [] + const res: ProviderInfo[] = [] const providers: AuthProvider[] = [registerGoogle, registerGithub, registerOpenid] for (const provider of providers) { const value = provider(ctx, passport, router, accountsUrl, db, frontUrl, brandings, signUpDisabled) diff --git a/pods/authProviders/src/openid.ts b/pods/authProviders/src/openid.ts index 43a0282dd33..c3acf9f19dc 100644 --- a/pods/authProviders/src/openid.ts +++ b/pods/authProviders/src/openid.ts @@ -13,6 +13,7 @@ // limitations under the License. // import { type AccountDB } from '@hcengineering/account' +import { type ProviderInfo } from '@hcengineering/core' import { BrandingMap, concatLink, MeasureContext, getBranding, SocialIdType } from '@hcengineering/core' import Router from 'koa-router' import { Issuer, Strategy } from 'openid-client' @@ -29,10 +30,12 @@ export function registerOpenid ( frontUrl: string, brandings: BrandingMap, signUpDisabled?: boolean -): string | undefined { +): ProviderInfo | undefined { const openidClientId = process.env.OPENID_CLIENT_ID const openidClientSecret = process.env.OPENID_CLIENT_SECRET const issuer = process.env.OPENID_ISSUER + const name = 'openid' + const displayName = process.env.OPENID_DISPLAY_NAME const redirectURL = '/auth/openid/callback' if (openidClientId === undefined || openidClientSecret === undefined || issuer === undefined) return @@ -110,5 +113,5 @@ export function registerOpenid ( } ) - return 'openid' + return { name, displayName } }