forked from janus-idp/backstage-showcase
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(showcase): add conditional rendering for login page (janus-idp#602)
* feat(showcase): add conditional rendering for login page Signed-off-by: Paul Schultz <pschultz@pobox.com> * update custom data api class name Signed-off-by: Paul Schultz <pschultz@pobox.com> * add changeset Signed-off-by: Paul Schultz <pschultz@pobox.com> * add saml support Signed-off-by: Paul Schultz <pschultz@pobox.com> * fix auth issue Signed-off-by: Paul Schultz <pschultz@pobox.com> * fix config Signed-off-by: Paul Schultz <pschultz@pobox.com> * update docs Signed-off-by: Paul Schultz <pschultz@pobox.com> --------- Signed-off-by: Paul Schultz <pschultz@pobox.com> Co-authored-by: Tomas Kral <tkral@redhat.com>
- Loading branch information
1 parent
a61d88b
commit 1de46ce
Showing
12 changed files
with
392 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'app': minor | ||
--- | ||
|
||
Add authentication provider conditional rendering for login page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { | ||
createApiRef, | ||
type ApiRef, | ||
type BackstageIdentityApi, | ||
type OAuthApi, | ||
type OpenIdConnectApi, | ||
type ProfileInfoApi, | ||
type SessionApi, | ||
} from '@backstage/core-plugin-api'; | ||
|
||
type CustomAuthApiRefType = OAuthApi & | ||
OpenIdConnectApi & | ||
ProfileInfoApi & | ||
BackstageIdentityApi & | ||
SessionApi; | ||
|
||
export const oidcAuthApiRef: ApiRef<CustomAuthApiRefType> = createApiRef({ | ||
id: 'internal.auth.oidc', | ||
}); | ||
|
||
export const auth0AuthApiRef: ApiRef<CustomAuthApiRefType> = createApiRef({ | ||
id: 'internal.auth.auth0', | ||
}); | ||
|
||
export const samlAuthApiRef: ApiRef<CustomAuthApiRefType> = createApiRef({ | ||
id: 'internal.auth.saml', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { | ||
ConfigApi, | ||
createApiRef, | ||
DiscoveryApi, | ||
} from '@backstage/core-plugin-api'; | ||
import { TechRadarLoaderResponse } from '@backstage/plugin-tech-radar'; | ||
import { QuickAccessLinks } from '../types/types'; | ||
|
||
const DEFAULT_PROXY_PATH = '/developer-hub'; | ||
|
||
export interface CustomDataApi { | ||
getHomeDataJson(): Promise<QuickAccessLinks[]>; | ||
getTechRadarDataJson(): Promise<TechRadarLoaderResponse>; | ||
} | ||
|
||
export const customDataApiRef = createApiRef<CustomDataApi>({ | ||
id: 'app.developer-hub.service', | ||
}); | ||
|
||
export type Options = { | ||
discoveryApi: DiscoveryApi; | ||
configApi: ConfigApi; | ||
}; | ||
|
||
export class CustomDataApiClient implements CustomDataApi { | ||
private readonly discoveryApi: DiscoveryApi; | ||
private readonly configApi: ConfigApi; | ||
|
||
constructor(options: Options) { | ||
this.discoveryApi = options.discoveryApi; | ||
this.configApi = options.configApi; | ||
} | ||
|
||
private async getBaseUrl() { | ||
const proxyPath = | ||
this.configApi.getOptionalString('developerHub.proxyPath') || | ||
DEFAULT_PROXY_PATH; | ||
return `${await this.discoveryApi.getBaseUrl('proxy')}${proxyPath}`; | ||
} | ||
|
||
private async fetcher(url: string) { | ||
const response = await fetch(url, { | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
if (!response.ok) { | ||
throw new Error( | ||
`failed to fetch data, status ${response.status}: ${response.statusText}`, | ||
); | ||
} | ||
return await response.json(); | ||
} | ||
|
||
async getHomeDataJson() { | ||
const proxyUrl = await this.getBaseUrl(); | ||
const data = await this.fetcher(`${proxyUrl}`); | ||
return data; | ||
} | ||
|
||
async getTechRadarDataJson() { | ||
const proxyUrl = await this.getBaseUrl(); | ||
const data = await this.fetcher(`${proxyUrl}/tech-radar`); | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,2 @@ | ||
import { | ||
ConfigApi, | ||
createApiRef, | ||
DiscoveryApi, | ||
} from '@backstage/core-plugin-api'; | ||
import { TechRadarLoaderResponse } from '@backstage/plugin-tech-radar'; | ||
import { QuickAccessLinks } from '../types/types'; | ||
|
||
const DEFAULT_PROXY_PATH = '/developer-hub'; | ||
|
||
export interface JanusBackstageCustomizeApi { | ||
getHomeDataJson(): Promise<QuickAccessLinks[]>; | ||
getTechRadarDataJson(): Promise<TechRadarLoaderResponse>; | ||
} | ||
|
||
export const janusBackstageCustomizeApiRef = | ||
createApiRef<JanusBackstageCustomizeApi>({ | ||
id: 'app.developer-hub.service', | ||
}); | ||
|
||
export type Options = { | ||
discoveryApi: DiscoveryApi; | ||
configApi: ConfigApi; | ||
}; | ||
|
||
export class JanusBackstageCustomizeApiClient | ||
implements JanusBackstageCustomizeApi | ||
{ | ||
// @ts-ignore | ||
private readonly discoveryApi: DiscoveryApi; | ||
|
||
private readonly configApi: ConfigApi; | ||
|
||
constructor(options: Options) { | ||
this.discoveryApi = options.discoveryApi; | ||
this.configApi = options.configApi; | ||
} | ||
|
||
private async getBaseUrl() { | ||
const proxyPath = | ||
this.configApi.getOptionalString('developerHub.proxyPath') || | ||
DEFAULT_PROXY_PATH; | ||
return `${await this.discoveryApi.getBaseUrl('proxy')}${proxyPath}`; | ||
} | ||
|
||
private async fetcher(url: string) { | ||
const response = await fetch(url, { | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
if (!response.ok) { | ||
throw new Error( | ||
`failed to fetch data, status ${response.status}: ${response.statusText}`, | ||
); | ||
} | ||
return await response.json(); | ||
} | ||
|
||
async getHomeDataJson() { | ||
const proxyUrl = await this.getBaseUrl(); | ||
const data = await this.fetcher(`${proxyUrl}`); | ||
return data; | ||
} | ||
|
||
async getTechRadarDataJson() { | ||
const proxyUrl = await this.getBaseUrl(); | ||
const data = await this.fetcher(`${proxyUrl}/tech-radar`); | ||
return data; | ||
} | ||
} | ||
export * from './AuthApiRefs'; | ||
export * from './CustomDataApiClient'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 3 additions & 29 deletions
32
packages/app/src/components/DynamicRoot/defaultAppComponents.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,9 @@ | ||
import { ProxiedSignInPage, SignInPage } from '@backstage/core-components'; | ||
import { | ||
AppComponents, | ||
configApiRef, | ||
githubAuthApiRef, | ||
useApi, | ||
} from '@backstage/core-plugin-api'; | ||
import { AppComponents } from '@backstage/core-plugin-api'; | ||
import React from 'react'; | ||
import { SignInPage } from '../SignInPage/SignInPage'; | ||
|
||
const defaultAppComponents: Partial<AppComponents> = { | ||
SignInPage: props => { | ||
const configApi = useApi(configApiRef); | ||
if (configApi.getString('auth.environment') === 'development') { | ||
return ( | ||
<SignInPage | ||
{...props} | ||
title="Select a sign-in method" | ||
align="center" | ||
providers={[ | ||
'guest', | ||
{ | ||
id: 'github-auth-provider', | ||
title: 'GitHub', | ||
message: 'Sign in using GitHub', | ||
apiRef: githubAuthApiRef, | ||
}, | ||
]} | ||
/> | ||
); | ||
} | ||
return <ProxiedSignInPage {...props} provider="oauth2Proxy" />; | ||
}, | ||
SignInPage: props => <SignInPage {...props} />, | ||
}; | ||
|
||
export default defaultAppComponents; |
Oops, something went wrong.