Skip to content

Commit

Permalink
Use of OpenID Connect access token in query strings #466 (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr authored Sep 11, 2024
1 parent 8780e95 commit ac82a0c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 44 deletions.
2 changes: 2 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ The redirect URL for the OIDC client must be set as follows:
For a given token `123` this results in the following additional HTTP Header:
`Authorization: Bearer 123`

You can change the default behaviour to send it as a Bearer token by providing `in`, `name` and `format`.

## preprocessSTAC

***experimental***
Expand Down
26 changes: 1 addition & 25 deletions src/auth/apiKey.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Auth from "./index";
import i18n from '../i18n';
import Utils from "../utils";

export default class ApiKey extends Auth {

Expand Down Expand Up @@ -30,30 +29,7 @@ export default class ApiKey extends Auth {
}

updateStore(value) {
if (value) {
if (this.options.formatter === 'Bearer') {
value = `Bearer ${value}`;
}
else if (typeof this.options.formatter === 'function') {
value = this.options.formatter(value);
}
}
if (!Utils.hasText(value)) {
value = undefined;
}

// Set query or request parameters
let key = this.options.name;
if (this.options.in === 'query') {
return {
query: { type: 'private', key, value }
};
}
else if (this.options.in === 'header') {
return {
header: { key, value }
};
}
return this._updateStore(value);
}

}
33 changes: 33 additions & 0 deletions src/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,39 @@ export default class Auth {
return {};
}

_updateStore(value, defaultName = null, defaultIn = null, defaultFormatter = null) {
const formatter = this.options.formatter || defaultFormatter;
const key = this.options.name || defaultName;
const in_ = this.options.in || defaultIn;

// Format the credentials
if (value) {
if (formatter === 'Bearer') {
value = `Bearer ${value}`;
}
else if (typeof formatter === 'function') {
value = formatter(value);
}
}
if (!Utils.hasText(value)) {
value = undefined;
}

// Set cookie, query or request parameters
if (in_ === 'query') {
return { query: { type: 'private', key, value } };
}
else if (in_ === 'cookie') {
return { cookie: { key, value } };
}
else if (in_ === 'header') {
return { header: { key, value } };
}
else {
return {};
}
}

static async create(config, changeListener, router) {
let method = new Auth();
if (Utils.isObject(config)) {
Expand Down
17 changes: 1 addition & 16 deletions src/auth/oidc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import BrowserStorage from "../browser-store";
import Utils from "../utils";
import Auth from "./index";

import { UserManager } from 'oidc-client-ts';
Expand Down Expand Up @@ -72,21 +71,7 @@ export default class OIDC extends Auth {
}

updateStore(value) {
if (value) {
if (typeof this.options.formatter === 'function') {
value = this.options.formatter(value);
}
else {
value = `Bearer ${value}`;
}
}
if (!Utils.hasText(value)) {
value = undefined;
}

return {
header: { key: 'Authorization', value }
};
return this._updateStore(value, 'Authorization', 'header', 'Bearer');
}

}
2 changes: 1 addition & 1 deletion src/browser-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class BrowserStorage {

}

class Cookies {
export class Cookies {

constructor(session = false) {
this.session = session;
Expand Down
8 changes: 6 additions & 2 deletions src/store/auth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Auth from '../auth';
import i18n from '../i18n';
import AuthUtils from '../components/auth/utils';
import BrowserStorage from '../browser-store';
import BrowserStorage, { Cookies } from '../browser-store';

const handleAuthError = async (cx, error) => {
cx.commit('showGlobalError', {
Expand Down Expand Up @@ -128,9 +128,13 @@ export default function getStore(router) {
if (intent.query) {
cx.commit('setQueryParameter', intent.query, { root: true });
}
if (intent.header) {
else if (intent.header) {
cx.commit('setRequestHeader', intent.header, { root: true });
}
else if (intent.cookie) {
const cookie = new Cookies(true);
cookie.setItem(intent.cookie.key, intent.cookie.value);
}
},
async executeActions(cx) {
for (let callback of cx.state.actions) {
Expand Down

0 comments on commit ac82a0c

Please sign in to comment.