Skip to content

Commit

Permalink
Merge pull request #7900 from brandon1024/idp-bg-config
Browse files Browse the repository at this point in the history
feat(idp): support login page background configuration
  • Loading branch information
kulmann committed Jan 31, 2024
2 parents 45d1936 + fbb4f9b commit 7f2d2d2
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 11 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/enhancement-idp-config-background-img.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Support login page background configuration

Introduce a new environment variable `IDP_LOGIN_BACKGROUND_URL`
that overrides the default background image of the IDP login page when present.

https://github.com/owncloud/ocis/issues/7674
https://github.com/owncloud/ocis/pull/7900
3 changes: 2 additions & 1 deletion services/idp/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ type Ldap struct {

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

type Client struct {
Expand Down
5 changes: 4 additions & 1 deletion services/idp/pkg/service/v0/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (idp IDP) ServeHTTP(w http.ResponseWriter, r *http.Request) {
idp.mux.ServeHTTP(w, r)
}

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

background := idp.config.Asset.LoginBackgroundUrl
indexHTML = bytes.Replace(template, []byte("__BG_IMG_URL__"), []byte(background), 1)

nonce := rndm.GenerateRandomString(32)
indexHTML = bytes.Replace(indexHTML, []byte("__CSP_NONCE__"), []byte(nonce), 1)

Expand Down
2 changes: 1 addition & 1 deletion services/idp/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<main id="root" class="oc-login-bg" data-path-prefix="__PATH_PREFIX__" passwort-reset-link="__PASSWORD_RESET_LINK__"></main>
<main id="root" data-path-prefix="__PATH_PREFIX__" passwort-reset-link="__PASSWORD_RESET_LINK__" data-bg-img="__BG_IMG_URL__"></main>
</body>
</html>
22 changes: 16 additions & 6 deletions services/idp/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { ReactElement, Suspense, lazy } from 'react';
import PropTypes from 'prop-types';

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

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

const App = (): ReactElement => {
const App = ({ bgImg }): ReactElement => {
return (
<MuiThemeProvider theme={theme}>
<Suspense fallback={<Spinner/>}>
<LazyMain />
</Suspense>
</MuiThemeProvider>
<div
className='oc-login-bg'
style={{ backgroundImage: bgImg ? `url(${bgImg})` : undefined }}
>
<MuiThemeProvider theme={theme}>
<Suspense fallback={<Spinner/>}>
<LazyMain/>
</Suspense>
</MuiThemeProvider>
</div>
);
}

App.propTypes = {
bgImg: PropTypes.string
};

export default App;
2 changes: 2 additions & 0 deletions services/idp/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ strong {
background-repeat: no-repeat;
background-position: center;
z-index: 0;
display: flex;
width: 100%;
}

#loader {
Expand Down
9 changes: 7 additions & 2 deletions services/idp/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import store from './store';

import './app.css';

const root = document.getElementById('root')

// if a custom background image has been configured, make use of it
const bgImg = root.getAttribute('data-bg-img')

ReactDOM.render(
<React.StrictMode>
<Provider store={store as any}>
<App/>
<App bgImg={bgImg}/>
</Provider>
</React.StrictMode>,
document.getElementById('root')
root
);

0 comments on commit 7f2d2d2

Please sign in to comment.