Add Out Of Band auth token support

Fixes #216
This commit is contained in:
Andrew Godwin 2022-12-21 16:42:44 +00:00
parent d3b9db581e
commit bbe60202e7
2 changed files with 11 additions and 0 deletions

View file

@ -3,6 +3,7 @@ from urllib.parse import urlparse, urlunparse
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponseRedirect, JsonResponse from django.http import HttpResponseRedirect, JsonResponse
from django.shortcuts import render
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.generic import TemplateView, View from django.views.generic import TemplateView, View
@ -67,6 +68,9 @@ class AuthorizationView(LoginRequiredMixin, TemplateView):
code=secrets.token_urlsafe(16), code=secrets.token_urlsafe(16),
scopes=scope.split(), scopes=scope.split(),
) )
# If it's an out of band request, show the code
if redirect_uri == "urn:ietf:wg:oauth:2.0:oob":
return render(request, "api/oauth_code.html", {"code": token.code})
# Redirect with the token's code # Redirect with the token's code
return OauthRedirect(redirect_uri, "code", token.code) return OauthRedirect(redirect_uri, "code", token.code)

View file

@ -0,0 +1,7 @@
{% extends "base.html" %}
{% block title %}Authorization Code{% endblock %}
{% block content %}
<p>To continue, provide this code to your application: <tt>{{ code }}</tt></p>
{% endblock %}