Skip to content

Commit

Permalink
fix(admin-ui): large header issue #1398
Browse files Browse the repository at this point in the history
Signed-off-by: Jeet Viramgama <jviramgama5@gmail.com>
  • Loading branch information
jv18creator committed Oct 31, 2023
1 parent 15dd362 commit c6d7eab
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
6 changes: 3 additions & 3 deletions admin-ui/app/redux/api/backend-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export const postUserAction = (userAction) => {
}

// Get API Access Token
export const fetchApiAccessToken = (jwt) => {
export const fetchApiAccessToken = (jwt, permissionTag) => {
return axios
.get('/app/admin-ui/oauth2/api-protection-token', { params: { ujwt: jwt } })
.post('/app/admin-ui/oauth2/api-protection-token', { ujwt: jwt, permissionTag: permissionTag || [] })
.then((response) => response.data)
.catch((error) => {
console.error(
Expand All @@ -73,7 +73,7 @@ export const fetchApiAccessToken = (jwt) => {

export const fetchApiTokenWithDefaultScopes = () => {
return axios
.get('/app/admin-ui/oauth2/api-protection-token')
.post('/app/admin-ui/oauth2/api-protection-token', {})
.then((response) => response.data)
.catch((error) => {
console.error(
Expand Down
2 changes: 2 additions & 0 deletions admin-ui/app/utils/PermChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export const AGAMA_DELETE = BASE_URL + '/config/agama.delete'
export const SESSION_READ = BASE_URL + '/jans-auth-server/session.readonly'
export const SESSION_DELETE = BASE_URL + '/jans-auth-server/session.delete'

export const SCOPE_TAGS = ['scopes']

export const hasPermission = (scopes, scope) => {
let available = false
if (scopes) {
Expand Down
10 changes: 7 additions & 3 deletions admin-ui/plugins/auth-server/redux/features/scopeSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ const initialState = {
entriesCount: 0,
clientScopes: [],
loadingClientScopes: false,
selectedClientScopes: []
selectedClientScopes: [],
accessToken: null
}

const scopeSlice = createSlice({
name: 'scope',
initialState,
reducers: {
setAccessToken: (state, action) => {
state.accessToken = action.payload
},
scopeHandleLoading: (state) => {
state.loading = true
state.saveOperationFlag = false
Expand Down Expand Up @@ -115,7 +119,6 @@ const scopeSlice = createSlice({
state.errorInSaveOperationFlag = false
},
getScopeByCreator: () => {},
getScopeByPattern: () => {},
getScopeByInum: (state) => {
state.loading = true
state.saveOperationFlag = false
Expand Down Expand Up @@ -152,7 +155,8 @@ export const {
getScopeByInum,
getClientScopes,
emptyScopes,
setClientSelectedScopes
setClientSelectedScopes,
setAccessToken
} = scopeSlice.actions
export { initialState }
export const { actions, reducer, state } = scopeSlice
Expand Down
45 changes: 20 additions & 25 deletions admin-ui/plugins/auth-server/redux/sagas/OAuthScopeSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,29 @@ import {
getScopeByCreatorResponse,
getClientScopesResponse,
} from '../features/scopeSlice'
import { SCOPE_TAGS } from 'Utils/PermChecker'
import { fetchApiAccessToken } from 'Redux/api/backend-api'
import { setAccessToken } from '../features/scopeSlice'

function* newFunction() {
const token = yield select((state) => state.authReducer.token.access_token)
let token
const scopesToken = yield select((state) => state.scopeReducer.accessToken)

if (!scopesToken) {
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
const scopeApiToken = yield call(fetchApiAccessToken, jwt, SCOPE_TAGS)
if (scopeApiToken.access_token) {
token = scopeApiToken.access_token
yield put(setAccessToken(scopeApiToken.access_token))
} else {
token = yield select((state) => state.authReducer.token.access_token)
}
} else {
token = scopesToken;
}

const issuer = yield select((state) => state.authReducer.issuer)
const api = new JansConfigApi.OAuthScopesApi(
getClient(JansConfigApi, token, issuer)
)
const api = new JansConfigApi.OAuthScopesApi(getClient(JansConfigApi, token, issuer))
return new ScopeApi(api)
}

Expand Down Expand Up @@ -113,23 +129,6 @@ export function* getClientScopes({ payload }) {
}
}

export function* getScopeBasedOnOpts({ payload }) {
const audit = yield* initAudit()
try {
addAdditionalData(audit, FETCH, SCOPE, payload)
const scopeApi = yield* newFunction()
const data = yield call(scopeApi.getScopeByOpts, payload.action.action_data)
yield put(getScopeByPatternResponse({ data }))
yield call(postUserAction, audit)
} catch (e) {
yield put(getScopeByPatternResponse(null))
if (isFourZeroOneError(e)) {
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
yield put(getAPIAccessToken(jwt))
}
}
}

export function* addAScope({ payload }) {
const audit = yield* initAudit()
try {
Expand Down Expand Up @@ -209,9 +208,6 @@ export function* watchGetClientScopes() {
export function* watchSearchScopes() {
yield takeLatest('scope/searchScopes', getScopes)
}
export function* watchGetScopeByOpts() {
yield takeLatest('scope/getScopeByPattern', getScopeBasedOnOpts)
}
export function* watchAddScope() {
yield takeLatest('scope/addScope', addAScope)
}
Expand All @@ -227,7 +223,6 @@ export default function* rootSaga() {
fork(watchGetScopeByInum),
fork(watchGetScopes),
fork(watchSearchScopes),
fork(watchGetScopeByOpts),
fork(watchAddScope),
fork(watchEditScope),
fork(watchDeleteScope),
Expand Down

0 comments on commit c6d7eab

Please sign in to comment.