Skip to content

Commit c313db2

Browse files
committed
add optional displayName attribute for providers, shown on login button (configurable via *_PROVIDER_NAME)
Signed-off-by: nicolasschneider <[email protected]>
1 parent 8e2e184 commit c313db2

File tree

11 files changed

+60
-24
lines changed

11 files changed

+60
-24
lines changed

packages/account-client/src/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
type PersonId,
2424
type PersonInfo,
2525
type PersonUuid,
26+
type ProviderInfo,
2627
type SocialIdType,
2728
Version,
2829
type WorkspaceInfoWithStatus,
@@ -52,7 +53,7 @@ import { getClientTimezone } from './utils'
5253
/** @public */
5354
export interface AccountClient {
5455
// Static methods
55-
getProviders: () => Promise<string[]>
56+
getProviders: () => Promise<ProviderInfo[]>
5657

5758
// RPC
5859
getUserWorkspaces: () => Promise<WorkspaceInfoWithStatus[]>
@@ -217,7 +218,7 @@ class AccountClientImpl implements AccountClient {
217218
this.rpc = withRetryUntilTimeout(this._rpc.bind(this), retryTimeoutMs ?? 5000)
218219
}
219220

220-
async getProviders (): Promise<string[]> {
221+
async getProviders (): Promise<ProviderInfo[]> {
221222
return await withRetryUntilMaxAttempts(async () => {
222223
const response = await fetch(concatLink(this.url, '/providers'))
223224

packages/core/src/classes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,4 +869,9 @@ export interface AccountInfo {
869869
locale?: string
870870
}
871871

872+
export interface ProviderInfo {
873+
name: string
874+
displayName?: string
875+
}
876+
872877
export type SocialKey = Pick<SocialId, 'type' | 'value'>

plugins/login-resources/src/components/Providers.svelte

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { concatLink } from '@hcengineering/core'
2+
import { concatLink, type ProviderInfo } from '@hcengineering/core'
33
import { getMetadata } from '@hcengineering/platform'
44
import { AnySvelteComponent, Button, Grid, deviceOptionsStore, getCurrentLocation } from '@hcengineering/ui'
55
import { onMount } from 'svelte'
@@ -12,28 +12,41 @@
1212
interface Provider {
1313
name: string
1414
component: AnySvelteComponent
15+
displayName: null
1516
}
1617
1718
const providers: Provider[] = [
1819
{
1920
name: 'google',
20-
component: Google
21+
component: Google,
22+
displayName: null
2123
},
2224
{
2325
name: 'github',
24-
component: Github
26+
component: Github,
27+
displayName: null
2528
},
2629
{
2730
name: 'openid',
28-
component: OpenId
31+
component: OpenId,
32+
displayName: null
2933
}
3034
]
3135
3236
let enabledProviders: Provider[] = []
3337
3438
onMount(() => {
35-
void getProviders().then((res) => {
36-
enabledProviders = providers.filter((provider) => res.includes(provider.name))
39+
void getProviders().then((res: ProviderInfo[]) => {
40+
enabledProviders = providers
41+
.map((provider) => {
42+
const match = res.find((r) => r.name === provider.name)
43+
if (!match) return null
44+
return {
45+
...provider,
46+
displayName: match.displayName
47+
}
48+
})
49+
.filter((p): p is Provider & { displayName: string } => p !== null)
3750
})
3851
})
3952
@@ -70,7 +83,7 @@
7083
<a href={getLink(provider)}>
7184
<Button kind={'contrast'} shape={'round2'} size={'x-large'} width="100%" stopPropagation={false}>
7285
<svelte:fragment slot="content">
73-
<svelte:component this={provider.component} />
86+
<svelte:component this={provider.component} displayName={provider.displayName} />
7487
</svelte:fragment>
7588
</Button>
7689
</a>

plugins/login-resources/src/components/providers/Github.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
import { Label } from '@hcengineering/ui'
33
import Github from '../icons/Github.svelte'
44
import login from '../../plugin'
5+
6+
export let displayName = 'Github'
57
</script>
68

79
<div class="flex-row-center flex-gap-2">
810
<Github />
9-
<Label label={login.string.ContinueWith} params={{ provider: 'Github' }} />
11+
<Label label={login.string.ContinueWith} params={{ provider: displayName }} />
1012
</div>

plugins/login-resources/src/components/providers/Google.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
import { Label } from '@hcengineering/ui'
33
import Google from '../icons/Google.svelte'
44
import login from '../../plugin'
5+
6+
export let displayName = 'Google'
57
</script>
68

79
<div class="flex-row-center flex-gap-2">
810
<Google />
9-
<Label label={login.string.ContinueWith} params={{ provider: 'Google' }} />
11+
<Label label={login.string.ContinueWith} params={{ provider: displayName }} />
1012
</div>

plugins/login-resources/src/components/providers/OpenId.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
import { Label } from '@hcengineering/ui'
33
import OpenId from '../icons/OpenId.svelte'
44
import login from '../../plugin'
5+
import { getMetadata } from '@hcengineering/platform'
6+
7+
const openIdDisplayName = getMetadata(login.metadata.OpenIdDisplayName) ?? 'OpenId'
58
</script>
69

710
<div class="flex-row-center flex-gap-2">
811
<OpenId />
9-
<Label label={login.string.ContinueWith} params={{ provider: 'OpenId' }} />
12+
<Label label={login.string.ContinueWith} params={{ provider: openIdDisplayName }} />
1013
</div>

plugins/login-resources/src/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import {
3030
type AccountUuid,
3131
type Person,
3232
type WorkspaceInfoWithStatus,
33-
type WorkspaceUserOperation
33+
type WorkspaceUserOperation,
34+
type ProviderInfo
3435
} from '@hcengineering/core'
3536
import { loginId } from '@hcengineering/login'
3637
import platform, {
@@ -851,8 +852,8 @@ export async function getLoginInfoFromQuery (): Promise<LoginInfo | WorkspaceLog
851852
}
852853
}
853854

854-
export async function getProviders (): Promise<string[]> {
855-
let providers: string[]
855+
export async function getProviders (): Promise<ProviderInfo[]> {
856+
let providers: ProviderInfo[]
856857

857858
try {
858859
providers = await getAccountClient(null).getProviders()

pods/authProviders/src/github.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type AccountDB } from '@hcengineering/account'
2+
import { type ProviderInfo } from '@hcengineering/core'
23
import { BrandingMap, concatLink, MeasureContext, getBranding, SocialIdType } from '@hcengineering/core'
34
import Router from 'koa-router'
45
import { Strategy as GitHubStrategy } from 'passport-github2'
@@ -14,9 +15,11 @@ export function registerGithub (
1415
frontUrl: string,
1516
brandings: BrandingMap,
1617
signUpDisabled?: boolean
17-
): string | undefined {
18+
): ProviderInfo | undefined {
1819
const GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID
1920
const GITHUB_CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET
21+
const name = 'github'
22+
const displayName = process.env.GITHUB_DISPLAY_NAME
2023

2124
const redirectURL = '/auth/github/callback'
2225
if (GITHUB_CLIENT_ID === undefined || GITHUB_CLIENT_SECRET === undefined) return
@@ -80,5 +83,5 @@ export function registerGithub (
8083
}
8184
)
8285

83-
return 'github'
86+
return { name, displayName }
8487
}

pods/authProviders/src/google.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type AccountDB } from '@hcengineering/account'
2+
import { type ProviderInfo } from '@hcengineering/core'
23
import { BrandingMap, concatLink, MeasureContext, getBranding, SocialIdType } from '@hcengineering/core'
34
import Router from 'koa-router'
45
import { Strategy as GoogleStrategy } from 'passport-google-oauth20'
@@ -14,9 +15,11 @@ export function registerGoogle (
1415
frontUrl: string,
1516
brandings: BrandingMap,
1617
signUpDisabled?: boolean
17-
): string | undefined {
18+
): ProviderInfo | undefined {
1819
const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID
1920
const GOOGLE_CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET
21+
const name = 'google'
22+
const displayName = process.env.GOOGLE_DISPLAY_NAME
2023

2124
const redirectURL = '/auth/google/callback'
2225
if (GOOGLE_CLIENT_ID === undefined || GOOGLE_CLIENT_SECRET === undefined) return
@@ -85,5 +88,5 @@ export function registerGoogle (
8588
}
8689
)
8790

88-
return 'google'
91+
return { name, displayName }
8992
}

pods/authProviders/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { registerGithub } from './github'
66
import { registerGoogle } from './google'
77
import { registerOpenid } from './openid'
88
import { registerToken } from './token'
9-
import { BrandingMap, MeasureContext } from '@hcengineering/core'
9+
import { BrandingMap, MeasureContext, type ProviderInfo } from '@hcengineering/core'
1010
import { type AccountDB } from '@hcengineering/account'
1111

1212
export type Passport = typeof passport
@@ -20,7 +20,7 @@ export type AuthProvider = (
2020
frontUrl: string,
2121
brandings: BrandingMap,
2222
signUpDisabled?: boolean
23-
) => string | undefined
23+
) => ProviderInfo | undefined
2424

2525
export function registerProviders (
2626
ctx: MeasureContext,
@@ -62,7 +62,7 @@ export function registerProviders (
6262

6363
registerToken(ctx, passport, router, accountsUrl, db, frontUrl, brandings)
6464

65-
const res: string[] = []
65+
const res: ProviderInfo[] = []
6666
const providers: AuthProvider[] = [registerGoogle, registerGithub, registerOpenid]
6767
for (const provider of providers) {
6868
const value = provider(ctx, passport, router, accountsUrl, db, frontUrl, brandings, signUpDisabled)

pods/authProviders/src/openid.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414
//
1515
import { type AccountDB } from '@hcengineering/account'
16+
import { type ProviderInfo } from '@hcengineering/core'
1617
import { BrandingMap, concatLink, MeasureContext, getBranding, SocialIdType } from '@hcengineering/core'
1718
import Router from 'koa-router'
1819
import { Issuer, Strategy } from 'openid-client'
@@ -29,10 +30,12 @@ export function registerOpenid (
2930
frontUrl: string,
3031
brandings: BrandingMap,
3132
signUpDisabled?: boolean
32-
): string | undefined {
33+
): ProviderInfo | undefined {
3334
const openidClientId = process.env.OPENID_CLIENT_ID
3435
const openidClientSecret = process.env.OPENID_CLIENT_SECRET
3536
const issuer = process.env.OPENID_ISSUER
37+
const name = 'openid'
38+
const displayName = process.env.OPENID_DISPLAY_NAME
3639

3740
const redirectURL = '/auth/openid/callback'
3841
if (openidClientId === undefined || openidClientSecret === undefined || issuer === undefined) return
@@ -110,5 +113,5 @@ export function registerOpenid (
110113
}
111114
)
112115

113-
return 'openid'
116+
return { name, displayName }
114117
}

0 commit comments

Comments
 (0)