Skip to content

Commit 2cb3887

Browse files
authored
Merge pull request #65 from cgalibern/v7-remove-X509-support
Remove support for x509 authentication and add conditional checks for the `authenticated` state
2 parents 22478ce + 815e398 commit 2cb3887

File tree

11 files changed

+36
-44
lines changed

11 files changed

+36
-44
lines changed

src/js/OidcConfiguration.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const baseUrl = window.location.protocol + "//" + window.location.host
22
const initData = {
33
client_id: "ringfs",
44
redirect_uri: baseUrl + "/authentication/callback",
5-
response_type: "id_token token",
6-
scope: "openid profile email",
5+
response_type: "code",
6+
scope: "openid profile email offline_access opensvc:om2 opensvc:om2:root opensvc:om2:guest grant",
77
silent_redirect_uri: baseUrl + "/authentication/silent_callback",
88
automaticSilentRenew: true,
99
loadUserInfo: false,

src/js/api.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ function hasAuthorizationHeader(auth) {
9292
return (auth.username && auth.password) ? true : false
9393
} else if (auth.authChoice == "openid") {
9494
return auth.access_token ? true : false
95-
} else if (auth.authChoice == "x509") {
96-
return true
9795
}
9896
return false
9997
}

src/js/components/App.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ const AppStateProvider = (props) => {
141141
basicLogin: {},
142142
alerts: [], // ex: [{level: "warning", body: (<div>foo</div>)}],
143143
eventSourceAlive: false,
144+
authenticated: false,
144145
}
145146

146147
const reducer = (state, action) => {
@@ -151,6 +152,12 @@ const AppStateProvider = (props) => {
151152
user: action.data
152153
}
153154

155+
case 'setAuthenticated':
156+
return {
157+
...state,
158+
authenticated: action.data
159+
}
160+
154161
case 'setEventSourceAlive':
155162
if (action.data == state.eventSourceAlive) {
156163
return state

src/js/components/AuthChoice.jsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ function AuthChoice(props) {
3232
OpenId
3333
</Button>
3434
}
35-
<Button onClick={() => dispatch({type: "setAuthChoice", data: "x509"})}>
36-
x509
37-
</Button>
3835
{authInfo && authInfo.methods && authInfo.methods.indexOf("basic") >= 0 &&
3936
<Button onClick={() => dispatch({type: "setAuthChoice", data: "basic"})}>
4037
Basic
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
import useClusterStatus from '../hooks/ClusterStatus.jsx'
2-
import { useStateValue } from "../state.js"
3-
41
function LoginCallback(props) {
5-
const { close } = useClusterStatus()
6-
const [{ authChoice }, dispatch] = useStateValue()
7-
console.log("login callback")
8-
if (authChoice != "openid") {
9-
dispatch({type: "setAuthChoice", data: "openid"})
10-
}
11-
close()
12-
return null
2+
console.log("auth completed, returning to application")
133
}
144

155
export default LoginCallback

src/js/components/NotAuthorized.jsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ function NotAuthorized(props) {
3333
OpenId
3434
</Button>
3535
}
36-
<Button onClick={() => dispatch({type: "setAuthChoice", data: "x509"})}>
37-
x509
38-
</Button>
3936
</DialogActions>
4037
</Dialog>
4138
)

src/js/components/User.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ function UserDigest(props) {
5555

5656
function handleLogout(e) {
5757
logout()
58-
dispatch({type: "setAuthChoice", data: ""})
59-
dispatch({type: "setBasicLogin", data: {}})
6058
unloadUser()
6159
close()
6260
}

src/js/hooks/ClusterStatus.jsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const context = {
1616
}
1717

1818
function useClusterStatus(props) {
19-
const [{cstat, user, eventSourceAlive}, dispatch] = useStateValue()
19+
const [{cstat, user, eventSourceAlive, authenticated}, dispatch] = useStateValue()
2020
const { auth } = useUser()
2121
const lastDispatch = useRef(Date.now())
2222
const limit = 1000
@@ -36,6 +36,7 @@ function useClusterStatus(props) {
3636
}
3737

3838
function initEventSource() {
39+
if (!authenticated) {return;}
3940
if (context.eventSource !== null && context.eventSource.readyState != 2) {
4041
return
4142
}
@@ -98,6 +99,7 @@ function useClusterStatus(props) {
9899
}
99100

100101
async function loadCstat() {
102+
if (!authenticated) {return;}
101103
if (!hasAuthorizationHeader(auth)) {
102104
console.log("loadCstat", false, auth)
103105
return
@@ -151,20 +153,22 @@ function useClusterStatus(props) {
151153
}
152154

153155
function init() {
154-
if (!context.cstat) {
156+
if (!authenticated) {return}
157+
if (!context.cstat) {
155158
loadCstat()
156159
}
157160
initEventSource()
158161
}
159162

160163
useEffect(() => {
161-
if (!context.auth || (context.auth.access_token == auth.access_token) && (context.auth.username == auth.username)) {
164+
if (!authenticated) {return}
165+
if (!context.auth || (context.auth.access_token == auth.access_token) && (context.auth.username == auth.username)) {
162166
init()
163167
} else {
164168
reset()
165169
}
166170
context.auth = auth
167-
}, [])
171+
}, [authenticated])
168172

169173
return {
170174
cstat: cstat,

src/js/hooks/NetworksStatus.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { useState, useEffect } from "react";
22
import useUser from "./User.jsx"
33
import { apiGetAny } from "../api.js";
4+
import {useStateValue} from "../state";
45

56
function useNetworksStatus() {
6-
const [data, setData] = useState(null)
7+
const [{authenticated}] = useStateValue()
8+
const [data, setData] = useState(null)
79
const { auth } = useUser()
810

911
function getData() {
@@ -16,8 +18,8 @@ function useNetworksStatus() {
1618
}
1719

1820
useEffect(() => {
19-
getData()
20-
}, [])
21+
if (authenticated) {getData()}
22+
}, [authenticated])
2123

2224
return data
2325
}

src/js/hooks/PoolsStatus.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { useState, useEffect } from "react";
22
import useUser from "./User.jsx"
33
import { apiGetAny } from "../api.js";
4+
import {useStateValue} from "../state";
45

56
function usePoolsStatus() {
6-
const [data, setData] = useState(null)
7+
const [{authenticated}] = useStateValue()
8+
const [data, setData] = useState(null)
79
const { auth } = useUser()
810

911
function getData() {
@@ -16,8 +18,8 @@ function usePoolsStatus() {
1618
}
1719

1820
useEffect(() => {
19-
getData()
20-
}, [])
21+
if (authenticated) {getData()}
22+
}, [authenticated])
2123

2224
return data
2325
}

0 commit comments

Comments
 (0)