Skip to content

Commit

Permalink
feat: design of API key page
Browse files Browse the repository at this point in the history
  • Loading branch information
mjatin-dev committed Apr 21, 2022
1 parent 1fd036d commit 57807c1
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 35 deletions.
16 changes: 8 additions & 8 deletions admin-ui/app/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import "@babel/polyfill";
import React from "react";
import { render } from "react-dom";
import App from "./components/App";
import { I18nextProvider } from "react-i18next";
import i18n from "./i18n";
import '@babel/polyfill'
import React from 'react'
import { render } from 'react-dom'
import App from './components/App'
import { I18nextProvider } from 'react-i18next'
import i18n from './i18n'

render(
<I18nextProvider i18n={i18n}>
<App />
</I18nextProvider>,
document.querySelector("#root")
);
document.querySelector('#root'),
)
45 changes: 34 additions & 11 deletions admin-ui/app/redux/api/backend-api.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import axios from '../api/axios'
import axios_instance from 'axios'

const JansConfigApi = require('jans_config_api')
import { useSelector } from 'react-redux'
// Get OAuth2 Configuration
const licenceApi = new JansConfigApi.AdminUILicenseApi()

export const fetchServerConfiguration = async (token) => {
const headers = { Authorization: `Bearer ${token}`};
const headers = { Authorization: `Bearer ${token}` }
return axios
.get('/oauth2/config', {headers})
.get('/oauth2/config', { headers })
.then((response) => response.data)
.catch((error) => {
console.error(
Expand Down Expand Up @@ -86,15 +89,35 @@ export const fetchApiTokenWithDefaultScopes = async () => {
}

// Check License present

export const checkLicensePresent = async (token) => {
const headers = { Authorization: `Bearer ${token}`};
return axios
.get('/license/checkLicense', {headers})
.then((response) => response.data)
.catch((error) => {
console.error('Error checking license of admin-ui', error)
return false
console.log('checkLicensePresentcheckLicensePresent')
const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers':
'Origin, X-Requested-With, Content-Type, Accept',
'Content-Type': 'application/json',
'Access-Control-Allow-Credentials': true,
// issuer: token,
Authorization: `Bearer ${token}`,
}
console.log('HEADERS', headers)
licenceApi
.isLicenseActive({ headers })
.then((data) => {
console.log('data', data)
})
.catch((err) => {
console.log('err', err)
})
return false
// return axios
// .get('/license/checkLicense', { headers })
// .then((response) => response.data)
// .catch((error) => {
// console.error('Error checking license of admin-ui', error)
// return false
// })
}

// Activate license using key
Expand All @@ -104,7 +127,7 @@ export const activateLicense = async (licenseKey, token) => {
.post('/license/activateLicense', data, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
Authorization: `Bearer ${token}`,
},
})
.then((response) => response.data)
Expand Down
20 changes: 13 additions & 7 deletions admin-ui/app/redux/sagas/LicenseSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
activateLicenseResponse,
} from '../actions'

import { checkLicensePresent, activateLicense, fetchApiTokenWithDefaultScopes } from '../api/backend-api'
import {
checkLicensePresent,
activateLicense,
fetchApiTokenWithDefaultScopes,
} from '../api/backend-api'

function* getApiTokenWithDefaultScopes() {
const response = yield call(fetchApiTokenWithDefaultScopes)
Expand All @@ -17,12 +21,14 @@ function* getApiTokenWithDefaultScopes() {

function* checkLicensePresentWorker() {
try {
const token = yield* getApiTokenWithDefaultScopes();
// const issuer = yield select((state) => state.authReducer.issuer)
const token = yield* getApiTokenWithDefaultScopes()
const response = yield call(checkLicensePresent, token)
if (response) {
yield put(checkLicensePresentResponse(response))
return
}
// if (response) {
// yield put(checkLicensePresentResponse(response))
// return
// }
yield put(checkLicensePresentResponse(false))
} catch (error) {
console.log('Error in checking License present.', error)
}
Expand All @@ -31,7 +37,7 @@ function* checkLicensePresentWorker() {

function* activateLicenseWorker({ payload }) {
try {
const token = yield* getApiTokenWithDefaultScopes();
const token = yield* getApiTokenWithDefaultScopes()
const response = yield call(activateLicense, payload.licenseKey, token)
if (response) {
yield put(activateLicenseResponse(response))
Expand Down
83 changes: 83 additions & 0 deletions admin-ui/app/utils/ApiKeyRedirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from 'react'
import { Container } from './../components'
import GluuNotification from './../routes/Apps/Gluu/GluuNotification'
import GluuCommitDialog from '../../app/routes/Apps/Gluu/GluuCommitDialog'
import { useTranslation } from 'react-i18next'
import ApiKey from './LicenseScreens/ApiKey'
function ApiKeyRedirect({
backendIsUp,
isLicenseValid,
activateLicense,
redirectUrl,
islicenseCheckResultLoaded,
isLicenseActivationResultLoaded,
}) {
const { t } = useTranslation()
function submitForm(message) {
activateLicense(message.trim())
}

function toggle() {
window.location.href = redirectUrl
}

return (
<React.Fragment>
<Container>
{/* <div
style={{
backgroundColor: 'white',
margin: 'auto',
marginTop: '20%',
}}
>
<img
style={{
display: 'block',
marginLeft: 'auto',
marginTop: 'auto',
marginRight: 'auto',
width: '100%',
height: '100%',
}}
src={require('../images/gif/npe-redirecting.gif')}
alt="loading..."
/>
</div> */}
{!isLicenseValid && islicenseCheckResultLoaded && <ApiKey />}
{/* <GluuCommitDialog
handler={toggle}
modal={!isLicenseValid && islicenseCheckResultLoaded}
onAccept={submitForm}
isLoading={false}
label={t(
'License key required to access Gluu Admin UI. Please enter license key.',
)}
placeholderLabel={t('Enter license key')}
inputType={'text'}
/> */}
{!backendIsUp && (
<GluuNotification
type="error"
message={t('The UI backend service is down')}
description={t(
'Please contact the side administrator or make sure it is up and running.',
)}
show={true}
/>
)}
{isLicenseActivationResultLoaded && !isLicenseValid && (
<GluuNotification
type="error"
message={t('Invalid License')}
description={t(
'License has been not enabled for this application. Please contact support and confirm if license-key is correct.',
)}
show={true}
/>
)}
</Container>
</React.Fragment>
)
}
export default ApiKeyRedirect
4 changes: 3 additions & 1 deletion admin-ui/app/utils/AppAuthProvider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react'
import ViewRedirect from './ViewRedirect'
import ApiKeyRedirect from './ApiKeyRedirect'
import { withRouter } from 'react-router'
import { saveState } from './TokenController'
import queryString from 'query-string'
Expand Down Expand Up @@ -100,12 +101,13 @@ class AppAuthProvider extends Component {
}
render() {
const { showContent } = this.state
console.log(showContent)
return (
<React.Fragment>
<SessionTimeout isAuthenticated={showContent} />
{showContent && this.props.children}
{!showContent && (
<ViewRedirect
<ApiKeyRedirect
backendIsUp={this.props.backendIsUp}
isLicenseValid={this.props.isLicenseValid}
activateLicense={this.props.activateLicense}
Expand Down
89 changes: 89 additions & 0 deletions admin-ui/app/utils/LicenseScreens/ApiKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React, { useState } from 'react'
import logo from './../../images/logos/logo192.png'
function ApiKey() {
let params = {
apiKey: '',
productCode: '',
sharedKey: '',
managementKey: '',
}

const [values, setValues] = useState(params)

const handleChange = (e) => {
const { name, value } = e.target
setValues((prevState) => ({
...prevState,
[name]: value,
}))
}

const submitValues = () => {
console.log(values)
}

return (
<div>
<div className="container text-dark">
<div className="row">
<div className="col-md-12 text-center my-5">
<img
src={logo}
style={{ maxWidth: '200px' }}
className="img-fluid"
/>
</div>
</div>
<div className="row">
<div className="col-md-8 text-center h2 mx-auto mb-3">
Please enter details to activate
</div>
</div>
<div className="row">
<div className="col-md-8 mx-auto">
<label>Api Keys</label>
<input
type="text"
className="form-control"
value={values.apiKey}
name="apiKey"
onChange={handleChange}
/>
<label>Product Code</label>
<input
type="text"
className="form-control"
value={values.productCode}
name="productCode"
onChange={handleChange}
/>
<label>Shared Key</label>
<input
type="text"
className="form-control"
value={values.sharedKey}
name="sharedKey"
onChange={handleChange}
/>
<label>Management Key</label>
<input
type="text"
className="form-control"
value={values.managementKey}
name="managementKey"
onChange={handleChange}
/>
<input
type="button"
value={'Submit'}
onClick={() => submitValues()}
className="btn mt-3"
style={{ backgroundColor: '#00a361', color: 'white' }}
/>
</div>
</div>
</div>
</div>
)
}
export default ApiKey
39 changes: 31 additions & 8 deletions admin-ui/app/utils/ViewRedirect.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
//ToDo :: Delete This page once auth things works fine

import React from 'react'
import { Container } from './../components'
import GluuNotification from './../routes/Apps/Gluu/GluuNotification'
import GluuCommitDialog from '../../app/routes/Apps/Gluu/GluuCommitDialog'
import { useTranslation } from 'react-i18next'

function ViewRedirect({ backendIsUp, isLicenseValid, activateLicense, redirectUrl, islicenseCheckResultLoaded, isLicenseActivationResultLoaded }) {
function ViewRedirect({
backendIsUp,
isLicenseValid,
activateLicense,
redirectUrl,
islicenseCheckResultLoaded,
isLicenseActivationResultLoaded,
}) {
const { t } = useTranslation()
function submitForm(message) {
activateLicense(message.trim());
activateLicense(message.trim())
}

function toggle() {
window.location.href = redirectUrl;
window.location.href = redirectUrl
}

return (
Expand Down Expand Up @@ -39,20 +48,34 @@ function ViewRedirect({ backendIsUp, isLicenseValid, activateLicense, redirectUr
{!backendIsUp && (
<GluuNotification
type="error"
message={t("The UI backend service is down")}
description={t("Please contact the side administrator or make sure it is up and running.")}
message={t('The UI backend service is down')}
description={t(
'Please contact the side administrator or make sure it is up and running.',
)}
show={true}
/>
)}
{isLicenseActivationResultLoaded && !isLicenseValid && (
<GluuNotification
type="error"
message={t("Invalid License")}
description={t("License has been not enabled for this application. Please contact support and confirm if license-key is correct.")}
message={t('Invalid License')}
description={t(
'License has been not enabled for this application. Please contact support and confirm if license-key is correct.',
)}
show={true}
/>
)}
<GluuCommitDialog handler={toggle} modal={!isLicenseValid && islicenseCheckResultLoaded} onAccept={submitForm} isLoading={false} label={t("License key required to access Gluu Admin UI. Please enter license key.")} placeholderLabel={t("Enter license key")} inputType={"text"} />
<GluuCommitDialog
handler={toggle}
modal={!isLicenseValid && islicenseCheckResultLoaded}
onAccept={submitForm}
isLoading={false}
label={t(
'License key required to access Gluu Admin UI. Please enter license key.',
)}
placeholderLabel={t('Enter license key')}
inputType={'text'}
/>
</div>
</Container>
</React.Fragment>
Expand Down

0 comments on commit 57807c1

Please sign in to comment.