-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
390 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.