Skip to content

Commit

Permalink
Merge pull request #164 from fhswf/master
Browse files Browse the repository at this point in the history
Make OAuth redirect url configurable
  • Loading branch information
moorepants authored Dec 15, 2023
2 parents d6ae9a6 + fcbecff commit 32e6f81
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
20 changes: 20 additions & 0 deletions docs/user_guide/install_jupyterhub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ You may want to check the `list of command line arguments <cmdline.html>`_ for f

After you restart JupyterHub, you can verify the service is working as intended by logging into JupyterHub, clicking "Control Panel", then "Services -> ngshare". If you see the ``ngshare`` welcome page, you may proceed.

Environment variables
~~~~~~~~~~~~~~~~~~~~~

Like other Services and JupyterHub itself ngsahre support some configuration via the environment.

The follwing configuration might be necessary in case the JupyterHub is running behindd a reverse proxy.
``JUPYTERHUB_SERVICE_REDIRECT_URL`` is the URL that ``ngshare`` calles after the oauth authentication with the hub. For example: ``/my_hub_proxy_prefix/services/ngshare/```. The default values is ``/services/ngshare/```.

Example for hub-managed-services:
.. code:: python
c.JupyterHub.services.append(
{
'name': 'ngshare',
'url': 'http://127.0.0.1:10101',
'command': ['python3', '-m', 'ngshare', '--admins', 'admin,admin2'],
'environment': { 'JUPYTERHUB_SERVICE_REDIRECT_URL': '/my_hub_proxy_prefix/services/ngshare/'}
}
)
Installing ngshare_exchange
---------------------------

Expand Down
5 changes: 5 additions & 0 deletions docs/user_guide/install_unmanaged.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Mocking Required Environment Variables

``JUPYTERHUB_SERVICE_URL`` is the URL that ``ngshare`` should be accessible on. For example, if ``ngshare`` has IP ``10.1.2.3`` and you want ``ngshare`` to listen on port 1234, this should be ``http://10.1.2.3:1234``. Changing this will affect ``ngshare``'s port.

Additional Environment Variables for ngshare
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The follwing variable might be necessary in case the JupyterHub is running behindd a reverse proxy.
``JUPYTERHUB_SERVICE_REDIRECT_URL`` is the URL that ``ngshare`` calles after the oauth authentication with the hub. For example: ``/my_hub_proxy_prefix/services/ngshare/```. The default values is ``/services/ngshare/```.

Running ``ngshare``
^^^^^^^^^^^^^^^^^^^
After configuring the environment variables, you may start ngshare as a service. You should also take a look at the `list of command line arguments <cmdline.html>`_ for further configuration.
Expand Down
3 changes: 2 additions & 1 deletion ngshare/database/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.sql import text

Session = None
test_storage = None
Expand All @@ -31,7 +32,7 @@ def clear_db(db, storage_path):
'submission_files_assoc_table',
'feedback_files_assoc_table',
]:
db.execute('DELETE FROM %s' % table_name)
db.execute(text('DELETE FROM %s' % table_name))
db.commit()
if storage_path is not None:
shutil.rmtree(storage_path, ignore_errors=True)
Expand Down
2 changes: 1 addition & 1 deletion ngshare/ngshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async def get(self):
token = await self.token_for_code(code)
# login successful, set cookie and redirect back to home
self.set_secure_cookie('ngshare-oauth-token', token)
self.redirect('/services/ngshare/')
self.redirect(os.environ.get("JUPYTERHUB_SERVICE_REDIRECT_URL", '/services/ngshare/'))
else:
# we are the login handler,
# begin oauth process which will come back later with an
Expand Down

0 comments on commit 32e6f81

Please sign in to comment.