summaryrefslogtreecommitdiff
path: root/postgresqleu/util/views.py
diff options
context:
space:
mode:
authorMagnus Hagander2024-05-18 08:23:43 +0000
committerMagnus Hagander2024-05-18 09:59:43 +0000
commit069d67880b67b1b6b29cd935b7366bf284aa27e4 (patch)
treeb4afa6bd82b3c7475efe22fe07243f9634620aca /postgresqleu/util/views.py
parent18514284c1f618285c22aadd14e191d6ff0a2f06 (diff)
Add basic Linkedin messaging provider
For now, this provider only supports basic publishing of entries as post. It does not support any polling, and it does not support collecting sponsor/speaker id's and highlighting them in notices. This can be added later, but it can't be done properly without linkedin app credentials that are not rate limited (the default), and you can't get those credentials without already having an app. As linkedin doesn't support the offline code flow for logins, this also implements an oauth endpoint for incoming oauth flows for messaging provider. Finally, unlike the other messaging providers, linkedin actually expire their oauth tokens - 2 months for the access token and 12 months for the refresh token. To handle that, implement token refresh as part of the validation flow, and simply flag that one as failed if the login doesn't work.
Diffstat (limited to 'postgresqleu/util/views.py')
-rw-r--r--postgresqleu/util/views.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/postgresqleu/util/views.py b/postgresqleu/util/views.py
index 5d36d310..9ec82e0b 100644
--- a/postgresqleu/util/views.py
+++ b/postgresqleu/util/views.py
@@ -26,6 +26,34 @@ def markdown_preview(request):
@csrf_exempt
+def oauth_return(request, providerid):
+ if 'code' not in request.GET:
+ raise Http404('Code missing')
+
+ provider = get_object_or_404(MessagingProvider, id=providerid)
+ impl = get_messaging(provider)
+ if hasattr(impl, 'oauth_return'):
+ err = impl.oauth_return(request)
+ if err:
+ return HttpResponse(err)
+ else:
+ if povider.series__id:
+ return HttpResponseRedirect('{}/events/admin/_series/{}/messaging/{}/'.format(
+ settings.SITEBASE,
+ provider.series_id,
+ provider.id,
+ ))
+ else:
+ return HttpResponseRedirect('{}/events/admin/news/messagingproviders/{}/'.format(
+ settings.SITEBASE,
+ provider.id,
+ ))
+
+ else:
+ return HttpResponse('Unconfigured')
+
+
+@csrf_exempt
def messaging_webhook(request, providerid, token):
provider = get_object_or_404(MessagingProvider, id=providerid, config__webhook__token=token)
impl = get_messaging(provider)