-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit uses the Django OAuth toolkit to add an OAuth provider. Django REST Framework and Graphene have both been linked up to this provider. This lays down groundwork for access to APIs via OAuth2.
- Loading branch information
1 parent
7d8d75d
commit dc37a57
Showing
10 changed files
with
142 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import rest_framework | ||
from graphene_django.views import GraphQLView | ||
from rest_framework.decorators import api_view, authentication_classes, permission_classes | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.settings import api_settings | ||
|
||
|
||
class DRFAuthenticatedGraphQLView(GraphQLView): | ||
def parse_body(self, request): | ||
if isinstance(request, rest_framework.request.Request): | ||
return request.data | ||
return super(DRFAuthenticatedGraphQLView, self).parse_body(request) | ||
|
||
@classmethod | ||
def as_view(cls, *args, **kwargs): | ||
view = super(DRFAuthenticatedGraphQLView, cls).as_view(*args, **kwargs) | ||
view = authentication_classes(api_settings.DEFAULT_AUTHENTICATION_CLASSES)(view) | ||
|
||
# it's not possible to use stricter permissions e.g Django Model permissions | ||
# because the GraphQL view cannot be associatded with one queryset | ||
view = permission_classes((IsAuthenticated,))(view) | ||
|
||
view = api_view(["GET", "POST"])(view) | ||
return view |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{% load static i18n compress%} | ||
|
||
<li class="nav-item {% if active == " oauth-nav" %}active{% endif %}" id="oauth-nav"> | ||
<a class="nav-link collapsed" id="oauth-nav-link" href="#" data-toggle="collapse" data-target="#oauth-menu" | ||
aria-expanded="true" aria-controls="oauth-menu"> | ||
<i class="fas fa-fw fa-lock"></i> | ||
<span>OAuth</span> | ||
</a> | ||
<div id="oauth-menu" class="collapse {% if active == " oauth-nav" %}show{% endif %}" | ||
data-parent="#accordionSidebar"> | ||
<div class="bg-white py-2 collapse-inner rounded"> | ||
{% if request.user.is_superuser %} | ||
<a class="collapse-item {% if selected == " applications" %}active {% endif %}" id="applications" | ||
href="{% url 'oauth2_provider:list' %}"> | ||
Applications | ||
</a> | ||
{% endif %} | ||
|
||
<a class="collapse-item {% if selected == " authorized-tokens" %}active {% endif %}" | ||
id="authorized-tokens" href="{% url 'oauth2_provider:authorized-token-list' %}"> | ||
My Tokens | ||
</a> | ||
</div> | ||
</div> | ||
</li> | ||
|
||
<script> | ||
function collapseMenu() { | ||
const facilities_nav_link = document.getElementById("oauth-nav-link"); | ||
facilities_nav_link.className = "nav-link collapsed"; | ||
const facilities_menu = document.getElementById("oauth-menu"); | ||
facilities_menu.className = "collapse"; | ||
} | ||
|
||
const items = document.querySelectorAll('.collapse-item'); | ||
items.forEach(input => input.addEventListener('click', collapseMenu())); | ||
|
||
document.addEventListener("DOMContentLoaded", () => { | ||
collapseMenu() | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block extrastyles %} | ||
<style> | ||
body { | ||
padding-top: 40px; | ||
padding-bottom: 40px; | ||
background-color: #f5f5f5; | ||
} | ||
|
||
.block-center { | ||
max-width: 500px; | ||
padding: 19px 29px 29px; | ||
margin: 0 auto 20px; | ||
background-color: #fff; | ||
border: 1px solid #e5e5e5; | ||
-webkit-border-radius: 5px; | ||
-moz-border-radius: 5px; | ||
border-radius: 5px; | ||
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, .05); | ||
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, .05); | ||
box-shadow: 0 1px 2px rgba(0, 0, 0, .05); | ||
} | ||
|
||
.block-center .block-center-heading { | ||
margin-bottom: 10px; | ||
} | ||
</style> | ||
{% endblock extrastyles %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters