Skip to content

Commit 700b145

Browse files
authored
Merge pull request #149 from mohamed-cds/feat/toggle_xhr_cookie_credentials
feat: support xhr cross-site cookie credentials
2 parents 508c1ef + 36c4a2a commit 700b145

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

docker/docker-entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if mount | grep '/static/config.json'; then
88
else
99
# Apply ENV vars to temporary config.json
1010
jq '.API_BASE_URL = env.API_BASE_URL
11+
| .API_WITH_CREDENTIALS = env.API_WITH_CREDENTIALS
1112
| .OIDC_ISSUER = env.OIDC_ISSUER
1213
| .OIDC_CLIENT_ID = env.OIDC_CLIENT_ID
1314
| .OIDC_SCOPE = env.OIDC_SCOPE

public/static/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"API_BASE_URL": "",
3+
"API_WITH_CREDENTIALS": "",
34
"OIDC_ISSUER": "",
45
"OIDC_CLIENT_ID": "",
56
"OIDC_SCOPE": "openid email profile",

src/App.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@
3838
3939
setJwtForAjax(getToken());
4040
41+
// Send XHR cross-site cookie credentials
42+
if (this.$api.WITH_CREDENTIALS){
43+
this.axios.interceptors.request.use(
44+
function(config) {
45+
config.withCredentials = true;
46+
return config;
47+
}
48+
);
49+
$.ajaxSettings.xhrFields = { withCredentials: true };
50+
}
51+
4152
// debug logging of ajax requests/responses
4253
if (getUrlVar('debug')) {
4354
$(document).ajaxComplete((event, xhr) => {

src/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ axios.get(contextPath + "/static/config.json").then(response => {
4444
} else {
4545
Vue.prototype.$api.BASE_URL = contextPath;
4646
}
47+
48+
// Send XHR cross-site cookie credentials
49+
Vue.prototype.$api.WITH_CREDENTIALS = response.data.API_WITH_CREDENTIALS && response.data.API_WITH_CREDENTIALS.toLowerCase() === "true";
50+
4751
// OpenID Connect
4852
Vue.prototype.$oidc.ISSUER = response.data.OIDC_ISSUER;
4953
Vue.prototype.$oidc.CLIENT_ID = response.data.OIDC_CLIENT_ID;

src/shared/api.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"METHOD_PUT": "PUT",
1010
"METHOD_DELETE": "DELETE",
1111
"FORCE_PASSWORD_CHANGE": "FORCE_PASSWORD_CHANGE",
12+
"WITH_CREDENTIALS": "",
1213

1314
"BASE_URL": "",
1415
"URL_ABOUT": "api/version",

0 commit comments

Comments
 (0)