Skip to content

Commit 9682b56

Browse files
committed
add build time auth switch
1 parent ac3162a commit 9682b56

File tree

6 files changed

+79
-6
lines changed

6 files changed

+79
-6
lines changed

apps/sensenet/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,67 @@ If you start typing a Content query term (that starts with a '+' sign), the term
5959
## ℹ Version info
6060

6161
(Coming soon...)
62+
63+
# sensenet Admin UI
64+
65+
React-based UI for sensenet. This application provides a rich UI for managing your sensenet content repository. It was designed to take advantage of the modern web technologies - which means we built it for evergreen browsers (Edge, Chrome, Firefox). If you need legacy browser support (e.g. IE11) please use the [old admin UI](https://github.com/SenseNet/sensenet/tree/master/src/nuget/snadmin/install-webpages) instead.
66+
67+
## Authentication Configuration
68+
69+
The application supports two authentication methods:
70+
71+
- **SNAuth**: sensenet's JWT-based authentication
72+
- **IdentityServer**: OIDC-based authentication with Identity Server
73+
74+
You can specify which authentication method to use during the build process. This is a build-time configuration, meaning the application will be built to use only one authentication method.
75+
76+
### Building with specific authentication method
77+
78+
To build the application with SNAuth (default):
79+
80+
```bash
81+
yarn build:snauth
82+
# or npm run build:snauth
83+
```
84+
85+
To build the application with Identity Server authentication:
86+
87+
```bash
88+
yarn build:idserver
89+
# or npm run build:idserver
90+
```
91+
92+
### Development with specific authentication method
93+
94+
To run the development server with SNAuth:
95+
96+
```bash
97+
yarn start:snauth
98+
# or npm run start:snauth
99+
```
100+
101+
To run the development server with Identity Server authentication:
102+
103+
```bash
104+
yarn start:idserver
105+
# or npm run start:idserver
106+
```
107+
108+
If you don't specify an authentication method, the application will default to using SNAuth.
109+
110+
## Development
111+
112+
To run the application locally:
113+
114+
```bash
115+
yarn install
116+
yarn start
117+
```
118+
119+
Navigate to http://localhost:8080 in your browser.
120+
121+
To build the application:
122+
123+
```bash
124+
yarn build
125+
```

apps/sensenet/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
"fix:prettier": "prettier \"{,!(dist|temp|bundle)/**/}*.{ts,tsx}\" --write",
1818
"build": "cross-env NODE_OPTIONS=--openssl-legacy-provider webpack --config webpack.prod.js",
1919
"build:stats": "webpack --config webpack.prod.js --profile --json > stats.json",
20+
"build:snauth": "cross-env NODE_OPTIONS=--openssl-legacy-provider AUTH_TYPE=SNAuth webpack --config webpack.prod.js",
21+
"build:idserver": "cross-env NODE_OPTIONS=--openssl-legacy-provider AUTH_TYPE=IdentityServer webpack --config webpack.prod.js",
2022
"start": "cross-env NODE_OPTIONS=--openssl-legacy-provider webpack serve --progress --config webpack.dev.js",
23+
"start:snauth": "cross-env NODE_OPTIONS=--openssl-legacy-provider AUTH_TYPE=SNAuth webpack serve --progress --config webpack.dev.js",
24+
"start:idserver": "cross-env NODE_OPTIONS=--openssl-legacy-provider AUTH_TYPE=IdentityServer webpack serve --progress --config webpack.dev.js",
2125
"cypress": "cypress open --env coverage=false",
2226
"cypress:local": "cypress open --env coverage=false --config baseUrl=http://localhost:8080",
2327
"cypress:all": "cypress run --env coverage=false",

apps/sensenet/src/auth-config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface AuthenticationConfig {
44
authType: AuthServerType
55
}
66

7+
// Use process.env.AUTH_TYPE if available (from build), otherwise default to 'SNAuth'
78
export const defaultAuthConfig: AuthenticationConfig = {
8-
authType: 'SNAuth',
9+
authType: (process.env.AUTH_TYPE || 'SNAuth') as AuthServerType,
910
}

apps/sensenet/src/components/content/Explore.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { FullScreenLoader } from '../full-screen-loader'
2626
import { Grid } from '../grid/Grid'
2727
// @ts-ignore
2828
import ExpandedItemsProvider from '../tree/Contexts/ExpandedItemsProvider'
29-
import { SimpleTree } from '../tree/SimpleTree'
29+
import { SimpleTree } from '../tree/simpletree'
3030
// @ts-ignore
3131
import TreeWithData from '../tree/tree-with-data'
3232
import { BrowseView, EditView, ImageView, NewView, PermissionView, VersionView } from '../view-controls'

apps/sensenet/src/context/repository-provider.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ export function RepositoryProvider({ children }: { children: React.ReactNode })
4242
const prevAuthConfig = JSON.parse(configString)
4343
setIdentityServerUrl(prevAuthConfig.authority)
4444

45-
if (repoFromUrl && prevAuthConfig.extraQueryParams.snrepo !== repoFromUrl) {
45+
// Access extraQueryParams via userManagerSettings
46+
const extraQueryParams = prevAuthConfig.userManagerSettings?.extraQueryParams
47+
if (repoFromUrl && extraQueryParams?.snrepo !== repoFromUrl) {
4648
return setAuthState({ repoUrl: repoFromUrl, config: null })
4749
}
4850

4951
setAuthState((oldState) => ({
50-
repoUrl: prevAuthConfig?.extraQueryParams.snrepo || '',
51-
config: prevAuthConfig?.extraQueryParams.snrepo === oldState.repoUrl ? prevAuthConfig : null,
52+
repoUrl: extraQueryParams?.snrepo || '',
53+
config: extraQueryParams?.snrepo === oldState.repoUrl ? prevAuthConfig.userManagerSettings : null,
5254
}))
5355
} else {
5456
repoFromUrl && setAuthState({ repoUrl: repoFromUrl, config: null })
@@ -64,6 +66,7 @@ export function RepositoryProvider({ children }: { children: React.ReactNode })
6466
setIsLoginInProgress(true)
6567
const config = await getAuthConfig(authState.repoUrl)
6668
window.localStorage.setItem(authConfigKey, JSON.stringify(config))
69+
// Set only userManagerSettings in authState to match the expected type
6770
setAuthState((oldState) => ({ ...oldState, config: config.userManagerSettings }))
6871
} catch (error) {
6972
logger.warning({ data: error, message: `Couldn't connect to ${authState.repoUrl}` })

apps/sensenet/webpack.common.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ module.exports = {
2929
},
3030
plugins: [
3131
new webpack.ProvidePlugin({
32-
"React": "react",
32+
React: 'react',
3333
}),
3434
new webpack.EnvironmentPlugin({
3535
APP_VERSION: require('./package.json').version,
36+
AUTH_TYPE: process.env.AUTH_TYPE || 'SNAuth', // Default to SNAuth if not specified
3637
}),
3738
new MonacoWebpackPlugin({
3839
languages: ['json', 'xml', 'html', 'javascript', 'markdown'],

0 commit comments

Comments
 (0)