From 030f47072245d6e80df43704961c609912340440 Mon Sep 17 00:00:00 2001 From: Vadzim Hvazdovich Date: Tue, 9 Apr 2024 12:30:33 +0300 Subject: [PATCH 1/3] EPMRPP-89400 || Set bearer token in api doc --- app/src/controllers/auth/index.js | 2 ++ app/src/controllers/auth/selectors.js | 4 ++-- app/src/pages/inside/apiPage/apiPage.jsx | 19 +++++++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/controllers/auth/index.js b/app/src/controllers/auth/index.js index b18010084b..a6122e5893 100644 --- a/app/src/controllers/auth/index.js +++ b/app/src/controllers/auth/index.js @@ -26,6 +26,8 @@ export { authReducer } from './reducer'; export { isAuthorizedSelector, tokenSelector, + tokenTypeSelector, + tokenValueSelector, lastFailedLoginTimeSelector, badCredentialsSelector, } from './selectors'; diff --git a/app/src/controllers/auth/selectors.js b/app/src/controllers/auth/selectors.js index 7cd2d1c7f3..f0ebc33979 100644 --- a/app/src/controllers/auth/selectors.js +++ b/app/src/controllers/auth/selectors.js @@ -19,8 +19,8 @@ const authSelector = (state) => state.auth || {}; export const isAuthorizedSelector = (state) => !!authSelector(state).authorized; const userTokenSelector = (state) => authSelector(state).token; -const tokenTypeSelector = (state) => userTokenSelector(state).type; -const tokenValueSelector = (state) => userTokenSelector(state).value; +export const tokenTypeSelector = (state) => userTokenSelector(state).type; +export const tokenValueSelector = (state) => userTokenSelector(state).value; const tokenStringSelector = (state) => `${tokenTypeSelector(state)} ${tokenValueSelector(state)}`; export const tokenSelector = (state) => tokenStringSelector(state); diff --git a/app/src/pages/inside/apiPage/apiPage.jsx b/app/src/pages/inside/apiPage/apiPage.jsx index cca862bce2..1581a9c6fc 100644 --- a/app/src/pages/inside/apiPage/apiPage.jsx +++ b/app/src/pages/inside/apiPage/apiPage.jsx @@ -22,7 +22,7 @@ import PropTypes from 'prop-types'; import SwaggerUI from 'swagger-ui-react'; import 'swagger-ui-react/swagger-ui.css'; import { URLS, DEFAULT_API_URL_PREFIX, UAT_API_URL_PREFIX } from 'common/urls'; -import { tokenSelector } from 'controllers/auth'; +import { tokenSelector, tokenTypeSelector, tokenValueSelector } from 'controllers/auth'; import { PageLayout, PageHeader, PageSection } from 'layouts/pageLayout'; import { ToggleButton } from 'components/buttons/toggleButton'; import track from 'react-tracking'; @@ -45,14 +45,18 @@ const OPTION_BLOCK_TAG_OPEN = '.opblock.is-open'; const OPTION_BLOCK_SUMMARY = '.opblock-summary'; @connect((state) => ({ - token: tokenSelector(state), + tokenString: tokenSelector(state), + tokenType: tokenTypeSelector(state), + tokenValue: tokenValueSelector(state), })) @injectIntl @track() export class ApiPage extends Component { static propTypes = { intl: PropTypes.object.isRequired, - token: PropTypes.string.isRequired, + tokenString: PropTypes.string.isRequired, + tokenType: PropTypes.string.isRequired, + tokenValue: PropTypes.string.isRequired, tracking: PropTypes.shape({ trackEvent: PropTypes.func, getTrackingData: PropTypes.func, @@ -63,6 +67,10 @@ export class ApiPage extends Component { apiType: DEFAULT_API_URL_PREFIX, }; + onSwaggerRendering = (system) => { + system.preauthorizeApiKey(this.props.tokenType, this.props.tokenValue); + }; + getBreadcrumbs = () => [{ title: this.props.intl.formatMessage(messages.apiPageTitle) }]; getAPIName = (apiType) => apiType.split('/')[1]; @@ -78,7 +86,9 @@ export class ApiPage extends Component { }; setAuth = (request) => { - request.headers.Authorization = this.props.token; + if (!request.headers.Authorization) { + request.headers.Authorization = this.props.tokenString; + } return request; }; @@ -178,6 +188,7 @@ export class ApiPage extends Component { 'head', 'options', ]} + onComplete={this.onSwaggerRendering} /> From 3d05e7738a01e1be5583184624504a39784d6477 Mon Sep 17 00:00:00 2001 From: Vadzim Hvazdovich Date: Wed, 10 Apr 2024 00:01:04 +0300 Subject: [PATCH 2/3] EPMRPP-89400 || preauthorizations fix --- app/src/pages/inside/apiPage/apiPage.jsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/src/pages/inside/apiPage/apiPage.jsx b/app/src/pages/inside/apiPage/apiPage.jsx index 1581a9c6fc..d34e94eea8 100644 --- a/app/src/pages/inside/apiPage/apiPage.jsx +++ b/app/src/pages/inside/apiPage/apiPage.jsx @@ -22,7 +22,7 @@ import PropTypes from 'prop-types'; import SwaggerUI from 'swagger-ui-react'; import 'swagger-ui-react/swagger-ui.css'; import { URLS, DEFAULT_API_URL_PREFIX, UAT_API_URL_PREFIX } from 'common/urls'; -import { tokenSelector, tokenTypeSelector, tokenValueSelector } from 'controllers/auth'; +import { tokenTypeSelector, tokenValueSelector } from 'controllers/auth'; import { PageLayout, PageHeader, PageSection } from 'layouts/pageLayout'; import { ToggleButton } from 'components/buttons/toggleButton'; import track from 'react-tracking'; @@ -43,9 +43,16 @@ const OPTION_BLOCK_TAG_SECTION_OPEN = '.opblock-tag-section.is-open'; const OPTION_BLOCK_TAG = '.opblock-tag'; const OPTION_BLOCK_TAG_OPEN = '.opblock.is-open'; const OPTION_BLOCK_SUMMARY = '.opblock-summary'; +const TOKEN_TYPE = { + BEARER: 'bearer', + APIKEY: 'apikey', // TODO check this value after apikey authorisation implementation +}; +const SECURITY_SCHEMES_KEYS_NAME = { + BEARER: 'bearerAuth', + APIKEY: 'api_key', +}; @connect((state) => ({ - tokenString: tokenSelector(state), tokenType: tokenTypeSelector(state), tokenValue: tokenValueSelector(state), })) @@ -54,7 +61,6 @@ const OPTION_BLOCK_SUMMARY = '.opblock-summary'; export class ApiPage extends Component { static propTypes = { intl: PropTypes.object.isRequired, - tokenString: PropTypes.string.isRequired, tokenType: PropTypes.string.isRequired, tokenValue: PropTypes.string.isRequired, tracking: PropTypes.shape({ @@ -68,7 +74,11 @@ export class ApiPage extends Component { }; onSwaggerRendering = (system) => { - system.preauthorizeApiKey(this.props.tokenType, this.props.tokenValue); + if (this.props.tokenType === TOKEN_TYPE.BEARER) { + system.preauthorizeApiKey(SECURITY_SCHEMES_KEYS_NAME.BEARER, this.props.tokenValue); + } else if (this.props.tokenType === TOKEN_TYPE.APIKEY) { + system.preauthorizeApiKey(SECURITY_SCHEMES_KEYS_NAME.APIKEY, this.props.tokenValue); + } }; getBreadcrumbs = () => [{ title: this.props.intl.formatMessage(messages.apiPageTitle) }]; @@ -87,7 +97,7 @@ export class ApiPage extends Component { setAuth = (request) => { if (!request.headers.Authorization) { - request.headers.Authorization = this.props.tokenString; + request.headers.Authorization = `${this.props.tokenType} ${this.props.tokenValue}`; } return request; }; From 6153e31be56e0f90341959b867a3df3f5589803b Mon Sep 17 00:00:00 2001 From: Vadzim Hvazdovich Date: Wed, 10 Apr 2024 16:44:12 +0300 Subject: [PATCH 3/3] EPMRPP-89400 || apikey refactoring --- app/src/pages/inside/apiPage/apiPage.jsx | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/app/src/pages/inside/apiPage/apiPage.jsx b/app/src/pages/inside/apiPage/apiPage.jsx index d34e94eea8..aecf86da64 100644 --- a/app/src/pages/inside/apiPage/apiPage.jsx +++ b/app/src/pages/inside/apiPage/apiPage.jsx @@ -43,14 +43,7 @@ const OPTION_BLOCK_TAG_SECTION_OPEN = '.opblock-tag-section.is-open'; const OPTION_BLOCK_TAG = '.opblock-tag'; const OPTION_BLOCK_TAG_OPEN = '.opblock.is-open'; const OPTION_BLOCK_SUMMARY = '.opblock-summary'; -const TOKEN_TYPE = { - BEARER: 'bearer', - APIKEY: 'apikey', // TODO check this value after apikey authorisation implementation -}; -const SECURITY_SCHEMES_KEYS_NAME = { - BEARER: 'bearerAuth', - APIKEY: 'api_key', -}; +const SECURITY_SCHEMES_BEARER_NAME = 'bearerAuth'; @connect((state) => ({ tokenType: tokenTypeSelector(state), @@ -74,11 +67,7 @@ export class ApiPage extends Component { }; onSwaggerRendering = (system) => { - if (this.props.tokenType === TOKEN_TYPE.BEARER) { - system.preauthorizeApiKey(SECURITY_SCHEMES_KEYS_NAME.BEARER, this.props.tokenValue); - } else if (this.props.tokenType === TOKEN_TYPE.APIKEY) { - system.preauthorizeApiKey(SECURITY_SCHEMES_KEYS_NAME.APIKEY, this.props.tokenValue); - } + system.preauthorizeApiKey(SECURITY_SCHEMES_BEARER_NAME, this.props.tokenValue); }; getBreadcrumbs = () => [{ title: this.props.intl.formatMessage(messages.apiPageTitle) }];