Repository: hydroshare/hydroshare

Issue:
Errors around the signup url
**Description of the bug**
We are seeing error in the logs around generating the signup url

Steps to reproduce the bug:
I'm not sure how to reproduce the bug but the stacktrace indicates a signup_url

**Expected behavior**
No errors in the log

**Additional information**
```
[27/Mar/2024 00:14:33] ERROR [django.request:224] Internal Server Error: /
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 171, in _get_response
    response = middleware_method(request, callback, callback_args, callback_kwargs)
  File "/usr/local/lib/python3.9/site-packages/mezzanine/pages/middleware.py", line 90, in process_view
    return view_func(request, *view_args, **view_kwargs)
  File "/hydroshare/theme/views.py", line 607, in home_router
    return render(request, "pages/homepage.html")
  File "/usr/local/lib/python3.9/site-packages/django/shortcuts.py", line 19, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "/usr/local/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 170, in render
    return self._render(context)
  File "/usr/local/lib/python3.9/site-packages/django/test/utils.py", line 100, in instrumented_test_render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python3.9/site-packages/django/test/utils.py", line 100, in instrumented_test_render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/defaulttags.py", line 315, in render
    return nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 988, in render
    output = self.filter_expression.resolve(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 698, in resolve
    new_obj = func(obj, *arg_vals)
  File "/hydroshare/hs_core/templatetags/hydroshare_tags.py", line 383, in signup_url
    return build_oidc_url(request).replace('/auth?', '/registrations?')
  File "/hydroshare/hs_core/authentication.py", line 43, in build_oidc_url
    return redirect.url
AttributeError: 'HttpResponseNotAllowed' object has no attribute 'url'
```



Discussion:
Here's where we register `signup_url`
https://github.com/hydroshare/hydroshare/blob/rc-2.13.5/hs_core/templatetags/hydroshare_tags.py#L380-L384

Resolving patch:
diff --git a/hs_core/authentication.py b/hs_core/authentication.py
--- a/hs_core/authentication.py
+++ b/hs_core/authentication.py
@@ -9,6 +9,9 @@
 from rest_framework.authentication import BaseAuthentication
 from keycloak.keycloak_openid import KeycloakOpenID
 
+import logging
+logger = logging.getLogger(__name__)
+
 
 class HydroShareOIDCAuthenticationBackend(OIDCAuthenticationBackend):
     def create_user(self, claims):
@@ -37,10 +40,22 @@ def build_oidc_url(request):
     Returns:
         string: redirect URL for oidc service
     """
-    view, args, kwargs = resolve(reverse('oidc_authentication_init'))
+    oidc_init = reverse('oidc_authentication_init')
+    view, args, kwargs = resolve(oidc_init)
     kwargs["request"] = request
-    redirect = view(*args, **kwargs)
-    return redirect.url
+    error = None
+    try:
+        redirect = view(*args, **kwargs)
+        if isinstance(redirect, Exception):
+            error = redirect
+        else:
+            return redirect.url
+    except Exception as e:
+        error = e
+
+    # If the OIDC URL could not be built, log the error and return the bare oidc_authentication_init url
+    logger.error(f"Error building OIDC URL: {error}")
+    return oidc_init
 
 
 def provider_logout(request):


Test patch: