-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload authentication #92
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,24 @@ | ||
from theia.api.models import ImageryRequest | ||
from rest_framework import viewsets | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
|
||
from theia.api.serializers import ImageryRequestSerializer | ||
|
||
|
||
class ImageryRequestViewSet(viewsets.ModelViewSet): | ||
queryset = ImageryRequest.objects.all() | ||
serializer_class = ImageryRequestSerializer | ||
|
||
def create(self, request, *args, **kwargs): | ||
copy = request.data.copy() | ||
copy['bearer_token'] = request.session['bearer_token'] | ||
copy['refresh_token'] = request.session['refresh_token'] | ||
copy['bearer_expiry'] = request.session['bearer_expiry'] | ||
|
||
serializer = self.get_serializer(data=copy) | ||
serializer.is_valid(raise_exception=True) | ||
self.perform_create(serializer) | ||
|
||
headers = self.get_success_headers(serializer.data) | ||
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,21 @@ class PanoptesOAuth2(BaseOAuth2): | |
] | ||
|
||
def get_user_details(self, response): | ||
with Panoptes() as p: | ||
p.bearer_token = response['access_token'] | ||
p.logged_in = True | ||
p.refresh_token = response['refresh_token'] | ||
p.bearer_expires = (datetime.now() + timedelta(seconds=response['expires_in'])) | ||
authenticated_panoptes = Panoptes( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noting that this request will return the user details of zooniverse oauth application owner, not the actual user that is initiating the request (unless they own the oauth application). Unless i'm missing how the |
||
endpoint=PanoptesUtils.base_url(), | ||
client_id=PanoptesUtils.client_id(), | ||
client_secret=PanoptesUtils.client_secret() | ||
) | ||
|
||
user = p.get('/me')[0]['users'][0] | ||
authenticated_panoptes.bearer_token = response['access_token'] | ||
authenticated_panoptes.logged_in = True | ||
authenticated_panoptes.refresh_token = response['refresh_token'] | ||
|
||
bearer_expiry = datetime.now() + timedelta(seconds=response['expires_in']) | ||
authenticated_panoptes.bearer_expires = (bearer_expiry) | ||
|
||
with authenticated_panoptes: | ||
user = authenticated_panoptes.get('/me')[0]['users'][0] | ||
|
||
ids = ['admin user'] | ||
if not user['admin']: | ||
|
@@ -38,7 +46,7 @@ def get_user_details(self, response): | |
'username': user['login'], | ||
'email': user['email'], | ||
'is_superuser': user['admin'], | ||
'projects': ids, | ||
'projects': ids | ||
} | ||
|
||
def get_user_id(self, details, response): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's kind of hard to tell--does this actually store the tokens in the db as fields on an imagery_request table? Or are these just built in memory, per-request?