Skip to content

Commit 4cea46f

Browse files
author
Mohamed Nur
committed
feat: ability to enable xhr creds when cross-site
Signed-off-by: Mohamed Nur <[email protected]>
1 parent 4db104c commit 4cea46f

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

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": false,
34
"OIDC_ISSUER": "",
45
"OIDC_CLIENT_ID": "",
56
"OIDC_SCOPE": "openid email profile",

src/App.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@
3838
3939
setJwtForAjax(getToken());
4040
41+
// Enable credentialed cross-site Access-Control requests
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+
}
50+
4151
// debug logging of ajax requests/responses
4252
if (getUrlVar('debug')) {
4353
$(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+
// XHR cross-site cookie credentials
49+
Vue.prototype.$api.WITH_CREDENTIALS = response.data.API_WITH_CREDENTIALS;
50+
4751
// OpenID Connect
4852
Vue.prototype.$oidc.ISSUER = response.data.OIDC_ISSUER;
4953
Vue.prototype.$oidc.CLIENT_ID = response.data.OIDC_CLIENT_ID;

0 commit comments

Comments
 (0)