Skip to content

Commit fd2b96a

Browse files
committed
feat(token): oauth2 token can be exchanged for a controller token
1 parent fc26cbd commit fd2b96a

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

rootfs/api/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
app_urlpatterns = [
1616
re_path(r'^', include(router.urls)),
1717
re_path(r'auth/login/?$', views.AuthLoginView.as_view({"post": "login"})),
18+
re_path(r'auth/token/?$', views.AuthTokenView.as_view({"post": "token"})),
1819
re_path(r'auth/token/(?P<key>[-_\w]+)/?$', views.AuthTokenView.as_view({"get": "token"})),
1920
# limits
2021
re_path(

rootfs/api/views.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,14 @@ class AuthTokenView(GenericViewSet):
144144
permission_classes = (AllowAny, )
145145

146146
def token(self, request, *args, **kwargs):
147-
oauth = oauth_cache_manager.get_token(self.kwargs['key'])
148-
if oauth:
147+
if 'key' in self.kwargs:
148+
oauth = oauth_cache_manager.get_token(self.kwargs['key'])
149+
else:
150+
try:
151+
oauth = json.loads(request.body.decode("utf8"))
152+
except json.decoder.JSONDecodeError:
153+
return HttpResponse(status=400)
154+
if oauth and 'access_token' in oauth:
149155
user = oauth_cache_manager.get_user(oauth['access_token'])
150156
alias = request.query_params.get('alias', '')
151157
token = models.base.Token(owner=user, alias=alias, oauth=oauth)

0 commit comments

Comments
 (0)