Skip to content

Commit 9bbd993

Browse files
committed
feat(idp): support login page background configuration
This revision introduces a new environment variable `IDP_LOGIN_BACKGROUND_URL` that overrides the default background image of the IDP login page when present.
1 parent 1cbf0ba commit 9bbd993

6 files changed

Lines changed: 32 additions & 11 deletions

File tree

‎services/idp/pkg/config/config.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ type Ldap struct {
5454

5555
// Asset defines the available asset configuration.
5656
type Asset struct {
57-
Path string `yaml:"asset" env:"IDP_ASSET_PATH" desc:"Serve IDP assets from a path on the filesystem instead of the builtin assets."`
57+
Path string `yaml:"asset" env:"IDP_ASSET_PATH" desc:"Serve IDP assets from a path on the filesystem instead of the builtin assets."`
58+
LoginBackgroundUrl string `yaml:"login-background-url" env:"IDP_LOGIN_BACKGROUND_URL" desc:"Configure an alternative URL to the background image for the login page."`
5859
}
5960

6061
type Client struct {

‎services/idp/pkg/service/v0/service.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (idp IDP) ServeHTTP(w http.ResponseWriter, r *http.Request) {
276276
idp.mux.ServeHTTP(w, r)
277277
}
278278

279-
// Index renders the static html with the
279+
// Index renders the static html with templated variables.
280280
func (idp IDP) Index() http.HandlerFunc {
281281
f, err := idp.assets.Open("/identifier/index.html")
282282
if err != nil {
@@ -295,6 +295,9 @@ func (idp IDP) Index() http.HandlerFunc {
295295
pp := "/signin/v1"
296296
indexHTML := bytes.Replace(template, []byte("__PATH_PREFIX__"), []byte(pp), 1)
297297

298+
background := idp.config.Asset.LoginBackgroundUrl
299+
indexHTML = bytes.Replace(template, []byte("__BG_IMG_URL__"), []byte(background), 1)
300+
298301
nonce := rndm.GenerateRandomString(32)
299302
indexHTML = bytes.Replace(indexHTML, []byte("__CSP_NONCE__"), []byte(nonce), 1)
300303

‎services/idp/public/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
<noscript>
1313
You need to enable JavaScript to run this app.
1414
</noscript>
15-
<main id="root" class="oc-login-bg" data-path-prefix="__PATH_PREFIX__" passwort-reset-link="__PASSWORD_RESET_LINK__"></main>
15+
<main id="root" data-path-prefix="__PATH_PREFIX__" passwort-reset-link="__PASSWORD_RESET_LINK__" data-bg-img="__BG_IMG_URL__"></main>
1616
</body>
1717
</html>

‎services/idp/src/App.jsx‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { ReactElement, Suspense, lazy } from 'react';
2+
import PropTypes from 'prop-types';
23

34
import { MuiThemeProvider } from '@material-ui/core/styles';
45
import { defaultTheme as theme } from 'kpop/es/theme';
@@ -13,14 +14,23 @@ const LazyMain = lazy(() => import(/* webpackChunkName: "identifier-main" */ './
1314

1415
console.info(`Kopano Identifier build version: ${version.build}`); // eslint-disable-line no-console
1516

16-
const App = (): ReactElement => {
17+
const App = ({ bgImg }): ReactElement => {
1718
return (
18-
<MuiThemeProvider theme={theme}>
19-
<Suspense fallback={<Spinner/>}>
20-
<LazyMain />
21-
</Suspense>
22-
</MuiThemeProvider>
19+
<div
20+
className='oc-login-bg'
21+
style={{ backgroundImage: bgImg ? `url(${bgImg})` : undefined }}
22+
>
23+
<MuiThemeProvider theme={theme}>
24+
<Suspense fallback={<Spinner/>}>
25+
<LazyMain/>
26+
</Suspense>
27+
</MuiThemeProvider>
28+
</div>
2329
);
2430
}
2531

32+
App.propTypes = {
33+
bgImg: PropTypes.string
34+
};
35+
2636
export default App;

‎services/idp/src/app.css‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ strong {
2424
background-repeat: no-repeat;
2525
background-position: center;
2626
z-index: 0;
27+
display: flex;
28+
width: 100%;
2729
}
2830

2931
#loader {

‎services/idp/src/index.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ import store from './store';
99

1010
import './app.css';
1111

12+
const root = document.getElementById('root')
13+
14+
// if a custom background image has been configured, make use of it
15+
const bgImg = root.getAttribute('data-bg-img')
16+
1217
ReactDOM.render(
1318
<React.StrictMode>
1419
<Provider store={store as any}>
15-
<App/>
20+
<App bgImg={bgImg}/>
1621
</Provider>
1722
</React.StrictMode>,
18-
document.getElementById('root')
23+
root
1924
);

0 commit comments

Comments
 (0)