Skip to content

Commit

Permalink
BC-6011 - try bettermarks uri config (#4628)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: SevenWaysDP <[email protected]>
  • Loading branch information
virgilchiriac and SevenWaysDP authored Dec 12, 2023
1 parent cbd4f87 commit 827052f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ data:
# Perform the final Bettermarks config data init if client secret and URL has been properly set.
if [ -n "$BETTERMARKS_CLIENT_SECRET" ] && [ -n "$BETTERMARKS_URL" ]; then
# Add document to the 'ltitools' collection with Bettermarks tool configuration.
mongosh $DATABASE__URL --eval 'db.ltitools.replaceOne(
mongosh $DATABASE__URL --eval 'db.getCollection("ltitools").replaceOne(
{
"name": "bettermarks",
"isTemplate": true
Expand Down Expand Up @@ -391,7 +391,7 @@ data:

# Add Bettermarks' tools configuration as an external tool
# (stored in the 'external-tools' collection) that uses OAuth.
mongosh $DATABASE__URL --eval 'db.external-tools.replaceOne(
mongosh $DATABASE__URL --eval 'db.getCollection("external-tools").replaceOne(
{
"name": "bettermarks",
"config_type": "oauth2"
Expand Down Expand Up @@ -428,7 +428,7 @@ data:
if [ -n "$NEXTCLOUD_CLIENT_SECRET" ] && [ -n "$NEXTCLOUD_SOCIALLOGIN_OIDC_INTERNAL_NAME" ]; then
echo "Inserting nextcloud to ltitools..."
# Add document to the 'ltitools' collection
mongosh $DATABASE__URL --eval 'db.ltitools.update(
mongosh $DATABASE__URL --eval 'db.getCollection("ltitools").update(
{
"name": "'$NEXTCLOUD_SOCIALLOGIN_OIDC_INTERNAL_NAME'",
"isTemplate": true
Expand Down Expand Up @@ -488,7 +488,7 @@ data:
# Add Nextcloud' tools configuration as an external tool
# (stored in the 'external-tools' collection) that uses OAuth.
echo "Inserting nextcloud to external-tools..."
mongosh $DATABASE__URL --eval 'db.external-tools.update(
mongosh $DATABASE__URL --eval 'db.getCollection("external-tools").update(
{
"name": "nextcloud",
"config_type": "oauth2"
Expand Down
4 changes: 2 additions & 2 deletions src/services/oauth2/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ const setIdToken = (hook) => {
};

const injectLoginRequest = (hook) =>
Hydra(hook.app.settings.services.hydra)
Hydra(Configuration.get('HYDRA_URI'))
.getLoginRequest(hook.id)
.then((loginRequest) => {
hook.params.loginRequest = loginRequest;
return hook;
});

const injectConsentRequest = (hook) =>
Hydra(hook.app.settings.services.hydra)
Hydra(Configuration.get('HYDRA_URI'))
.getConsentRequest(hook.id)
.then((consentRequest) => {
hook.params.consentRequest = consentRequest;
Expand Down
7 changes: 5 additions & 2 deletions src/services/oauth2/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { static: staticContent } = require('@feathersjs/express');
const path = require('path');
const { Configuration } = require('@hpi-schul-cloud/commons');

const hooks = require('./hooks');
const Hydra = require('./hydra.js');
Expand All @@ -13,8 +14,10 @@ const setClientDefaults = (data) => {
};

module.exports = function oauth2() {
const hydraUri = Configuration.get('HYDRA_URI');

const app = this;
const hydraAdmin = Hydra(app.settings.services.hydra);
const hydraAdmin = Hydra(hydraUri);

// hydra.isInstanceAlive()
// .then(res => { logger.log('info', 'Hydra status is: ' + res.statusText) })
Expand All @@ -24,7 +27,7 @@ module.exports = function oauth2() {

app.use('/oauth2/baseUrl', {
find() {
return Promise.resolve(app.settings.services.hydra);
return Promise.resolve(hydraUri);
},
});

Expand Down
15 changes: 8 additions & 7 deletions test/services/oauth2/mock.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const assert = require('assert');
const chai = require('chai');
const chaiHttp = require('chai-http');

const { Configuration } = require('@hpi-schul-cloud/commons');
// proxyserver
const oauth2Server = require('./oauth2MockServer');
const oauth2 = require('../../../src/services/oauth2');
Expand Down Expand Up @@ -50,6 +50,12 @@ describe('oauth2 service mock', function oauthTest() {
let beforeHydraUri;
before(async function before() {
this.timeout(10000);

beforeHydraUri = Configuration.get('HYDRA_URI');

const o2mock = await oauth2Server({});
Configuration.set('HYDRA_URI', o2mock.url);

app = await appPromise();

baseUrlService = app.service('oauth2/baseUrl');
Expand All @@ -58,11 +64,6 @@ describe('oauth2 service mock', function oauthTest() {
introspectService = app.service('oauth2/introspect');
consentService = app.service('oauth2/auth/sessions/consent');

beforeHydraUri = app.settings.services.hydra;

const o2mock = await oauth2Server({});
app.settings.services.hydra = o2mock.url;

app.unuse('oauth2/baseUrl');
app.unuse('oauth2/clients');
app.unuse('oauth2/loginRequest');
Expand All @@ -78,7 +79,7 @@ describe('oauth2 service mock', function oauthTest() {

after(async () => {
// sets uri back to original uri
app.settings.services.hydra = beforeHydraUri;
Configuration.set('HYDRA_URI', beforeHydraUri);
await server.close();
await closeNestServices(nestServices);
});
Expand Down

0 comments on commit 827052f

Please sign in to comment.