Skip to content

Commit

Permalink
upgrade libs - add support for custom bearer
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmars committed Jun 20, 2024
1 parent 36fece8 commit 42e7409
Show file tree
Hide file tree
Showing 24 changed files with 16,335 additions and 2,580 deletions.
6 changes: 2 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"editor.tabSize": 2,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"[javascript]": {
"editor.formatOnSave": false
Expand All @@ -17,9 +17,7 @@
"javascript.format.semicolons": "insert",
"typescript.preferences.quoteStyle": "single",
"typescript.format.semicolons": "insert",
"eslint.validate": [
"javascript"
],
"eslint.validate": ["javascript"],
"vetur.format.defaultFormatter.js": "none",
"vetur.format.defaultFormatter.less": "none",
"vetur.format.defaultFormatter.html": "none",
Expand Down
38 changes: 19 additions & 19 deletions docs/demos/frgov/pega-govfr.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions docs/demos/ukgds/pega-govuk.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions docs/demos/uswds/pega-govus.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ <h2 class='sr-only'>Settings</h2>
<option value="oauth2password">OAuth 2.0 Password Grant Type</option>
<option value="oauth2clientcredentials">OAuth 2.0 Client Credentials Type</option>
<option value="authorizationcode">OAuth 2.0 Authorization Code (login page)</option>
<option value="custombearer">Custom Bearer</option>
</select>
</div>
<div class='flex flex-col'>
Expand Down
9 changes: 9 additions & 0 deletions docs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ function createMashup() {
mytag.password = document.getElementById('password').value;
mytag.clientid = document.getElementById('clientid').value;
mytag.clientsecret = document.getElementById('clientsecret').value;
} else if (authenticationType === 'custombearer') {
mytag.username = document.getElementById('username').value;
mytag.clientid = document.getElementById('clientid').value;
} else if (authenticationType === 'authorizationcode') {
mytag.clientid = document.getElementById('clientid').value;
} else {
Expand Down Expand Up @@ -235,6 +238,12 @@ function showAuthentication(event) {
jwttoken.style.display = 'none';
clientid.style.display = '';
clientsecret.style.display = '';
} else if (action === 'custombearer') {
username.style.display = '';
password.style.display = 'none';
jwttoken.style.display = 'none';
clientid.style.display = '';
clientsecret.style.display = 'none';
} else if (action === 'authorizationcode') {
username.style.display = 'none';
password.style.display = 'none';
Expand Down
28 changes: 14 additions & 14 deletions docs/pega-mashup-light-webcomponent.js

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions docs/pega-mashup-light-webcomponentv2.js

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions docs/pega-mashup-webcomponent-all.js

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions docs/pega-mashup-webcomponent-light-all.js

Large diffs are not rendered by default.

18,596 changes: 16,158 additions & 2,438 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
"name": "root",
"private": true,
"devDependencies": {
"@axe-core/puppeteer": "^4.6.0",
"@babel/eslint-parser": "^7.19.1",
"@babel/preset-env": "^7.20.2",
"@rollup/plugin-eslint": "^9.0.1",
"@rollup/plugin-terser": "^0.4.0",
"eslint": "^8.31.0",
"@axe-core/puppeteer": "^4.9.1",
"@babel/eslint-parser": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@rollup/plugin-eslint": "^9.0.5",
"@rollup/plugin-terser": "^0.4.4",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.2.0",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"lerna": "^8.1.2",
"nunjucks": "^3.2.3",
"puppeteer": "^22.0.0",
"rollup": "^4.10.0",
"rollup-plugin-copy": "^3.3.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.6.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"lerna": "^8.1.3",
"nunjucks": "^3.2.4",
"puppeteer": "^22.11.2",
"rollup": "^4.18.0",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-serve": "^1.1.1"
},
"dependencies": {
"lit": "^3.1.2"
"lit": "^3.1.4"
},
"scripts": {
"dev:core": "lerna run dev --scope pega-mashup-web-component",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"test:coverage": "jest --coverage --colors"
},
"dependencies": {
"lit": "^3.1.2"
"lit": "^3.1.4"
}
}
1 change: 1 addition & 0 deletions packages/core/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ <h2 class='sr-only'>Settings</h2>
<option value="oauth2password">OAuth 2.0 Password Grant Type</option>
<option value="oauth2clientcredentials">OAuth 2.0 Client Credentials Type</option>
<option value="authorizationcode">OAuth 2.0 Authorization Code (login page)</option>
<option value="custombearer">Custom Bearer</option>
</select>
</div>
<div class='flex flex-col'>
Expand Down
9 changes: 9 additions & 0 deletions packages/core/public/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ function createMashup() {
mytag.password = document.getElementById('password').value;
mytag.clientid = document.getElementById('clientid').value;
mytag.clientsecret = document.getElementById('clientsecret').value;
} else if (authenticationType === 'custombearer') {
mytag.username = document.getElementById('username').value;
mytag.clientid = document.getElementById('clientid').value;
} else if (authenticationType === 'authorizationcode') {
mytag.clientid = document.getElementById('clientid').value;
} else {
Expand Down Expand Up @@ -235,6 +238,12 @@ function showAuthentication(event) {
jwttoken.style.display = 'none';
clientid.style.display = '';
clientsecret.style.display = '';
} else if (action === 'custombearer') {
username.style.display = '';
password.style.display = 'none';
jwttoken.style.display = 'none';
clientid.style.display = '';
clientsecret.style.display = 'none';
} else if (action === 'authorizationcode') {
username.style.display = 'none';
password.style.display = 'none';
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/interpreter/v1/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,10 @@ export default class PegaServices extends PegaElement {
}
reqHeaders.headers['Content-Type'] = 'application/x-www-form-urlencoded';
apiurl = `${this.url}/PRRestService/oauth2/v1/token`;
const prwebIndex = this.url.indexOf('/prweb');
if (prwebIndex !== -1) {
apiurl = `${this.url.substring(0, prwebIndex + 6)}/PRRestService/oauth2/v1/token`;
}
break;
case 'newwork':
apiurl += 'cases';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/interpreter/v2/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class PegaBase extends PegaServices {
if (window.history.state && window.history.state.token) {
this.token = window.history.state.token;
}
if ((this.authentication === 'oauth2password' || this.authentication === 'oauth2clientcredentials') && this.token === '') {
if ((this.authentication === 'oauth2password' || this.authentication === 'oauth2clientcredentials' || this.authentication === 'custombearer') && this.token === '') {
this.sendData('authenticate', {});
return null;
}
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/interpreter/v2/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,16 +531,22 @@ export default class PegaServices extends PegaElement {
switch (type) {
case 'authenticate':
if (this.authentication === 'oauth2password') {
reqHeaders.body = `grant_type=password&client_id=${this.clientid}&client_secret=${this.clientsecret}` +
reqHeaders.body = `grant_type=password&client_id=${this.clientid}&client_secret=${this.clientsecret}&enable_psyncId=true` +
`&username=${this.username}&password=${this.password}`;
} else if (this.authentication === 'oauth2clientcredentials') {
reqHeaders.body = `grant_type=client_credentials&client_id=${this.clientid}&client_secret=${this.clientsecret}`;
reqHeaders.body = `grant_type=client_credentials&client_id=${this.clientid}&client_secret=${this.clientsecret}&enable_psyncId=true`;
} else if (this.authentication === 'authorizationcode') {
reqHeaders.body = `grant_type=authorization_code&client_id=${this.clientid}` +
`&code_verifier=${window.history.state.verifier}&code=${window.history.state.code}&redirect_uri=${encodeURIComponent(GetRedirectURL())}`;
} if (this.authentication === 'custombearer') {
reqHeaders.body = `grant_type=custom-bearer&client_id=${this.clientid}&enable_psyncId=true&userIdentifier=${this.username}`;
}
reqHeaders.headers['Content-Type'] = 'application/x-www-form-urlencoded';
apiurl = `${this.url}/PRRestService/oauth2/v1/token`;
const prwebIndex = this.url.indexOf('/prweb');
if (prwebIndex !== -1) {
apiurl = `${this.url.substring(0, prwebIndex + 6)}/PRRestService/oauth2/v1/token`;
}
break;
case 'newwork':
apiurl += 'cases?viewType=form';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/main/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class PegaElement extends LitElement {
bShowAttachments: {}, /* Show or hide the attachments button */
bShowSave: {}, /* Show or hide the save action (v1 only) */
bShowActions: {}, /* Show or hide the actions menu button when opening an assignment */
authentication: {}, /* Authentication type - supported values: basic, jwttoken, oauth2password, oauth2clientcredentials */
authentication: {}, /* Authentication type - supported values: basic, jwttoken, oauth2password, oauth2clientcredentials, custombearer */
token: {}, /* JWT Token for authentication */
clientid: {}, /* oAuth clientid for authentication */
clientsecret: {}, /* oAuth clientsecret for authentication */
Expand Down
13 changes: 10 additions & 3 deletions packages/core/src/views/oauthprovider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import { genOAuthURL } from '../utils/form-utils';

export const GetRedirectURL = () => `${window.location.href.substring(0, window.location.href.lastIndexOf('/'))}/auth.html`;

export const ShowOAuthProvider = (url, clientid) => html`<div class='flex flex-col'><h2>${i18n.t('Log in to the application with one of the following:')}</h2>
export const ShowOAuthProvider = (url, clientid) => {
let apiurl = `${url}/PRRestService/oauth2/v1/authorize`;
const prwebIndex = url.indexOf('/prweb');
if (prwebIndex !== -1) {
apiurl = `${url.substring(0, prwebIndex + 6)}/PRRestService/oauth2/v1/authorize`;
}
return html`<div class='flex flex-col'><h2>${i18n.t('Log in to the application with one of the following:')}</h2>
<div class='flex layout-content-inline_middle'>${until(
genOAuthURL().then((res) => {
const { verifier, challenge } = res;
const urlparam = `response_type=code&scope=openid&code_challenge=${challenge}` +
'&code_challenge_method=S256&response_mode=query&authentication_service=pega';
const clickurl = `${url}/PRRestService/oauth2/v1/authorize?` +
'&code_challenge_method=S256&response_mode=query&enable_psyncId=true&authentication_service=pega';
const clickurl = `${apiurl}?` +
`client_id=${clientid}&redirect_uri=${encodeURIComponent(GetRedirectURL())}&${urlparam}&state=${verifier}`;
const button1 = html`<Button class="pzhc pzbutton" onclick="window.location='${clickurl}'; return false;">
${i18n.t('Pega with full page redirect')}</Button>`;
Expand All @@ -21,3 +27,4 @@ export const ShowOAuthProvider = (url, clientid) => html`<div class='flex flex-c
}),
html`Loading...`,
)}</div></div>`;
};
2 changes: 1 addition & 1 deletion packages/govfr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"lint": "eslint src/**/*.js --fix; exit 0"
},
"dependencies": {
"lit": "^3.1.2"
"lit": "^3.1.4"
}
}
2 changes: 1 addition & 1 deletion packages/govfr/src/v2/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class PegaBase extends PegaServices {
return showErrorMessage(this.errorMsg, this.bShowCancel === 'true' ? this.resetError : null);
}
/* No need to continue if authentication has not be done */
if ((this.authentication === 'oauth2password' || this.authentication === 'oauth2clientcredentials') && this.token === '') {
if ((this.authentication === 'oauth2password' || this.authentication === 'oauth2clientcredentials' || this.authentication === 'custombearer') && this.token === '') {
this.sendData('authenticate', {});
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/govuk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"lint": "eslint src/**/*.js --fix; exit 0"
},
"dependencies": {
"lit": "^3.1.2"
"lit": "^3.1.4"
}
}
2 changes: 1 addition & 1 deletion packages/govus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"lint": "eslint src/**/*.js --fix; exit 0"
},
"dependencies": {
"lit": "^3.1.2"
"lit": "^3.1.4"
}
}

0 comments on commit 42e7409

Please sign in to comment.