forked from theinterned/batucada
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working OAuth2 provider support. Uses oauth2app to implement service …
…provider support and provides a test endpoint for bearer token authentication
- Loading branch information
Showing
8 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
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,16 @@ | ||
from django.conf.urls.defaults import patterns, url | ||
|
||
|
||
urlpatterns = patterns('', | ||
url(r'^missing_redirect_uri/?$', 'oauth.views.missing_redirect_uri', | ||
name='oauth_missing_redirect_uri'), | ||
|
||
url(r'^authorize/?$', 'oauth.views.authorize', | ||
name='oauth_authorize'), | ||
|
||
url(r'^token/?$', 'oauth2app.token.handler', | ||
name='oauth_token_handler'), | ||
|
||
url(r'^test/$', 'oauth.views.test', | ||
name='oauth_test'), | ||
) |
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,54 @@ | ||
from django import forms | ||
from django.core.urlresolvers import reverse | ||
from django.http import HttpResponse, HttpResponseRedirect | ||
from django.template import RequestContext | ||
from django.shortcuts import render_to_response | ||
|
||
from users.decorators import login_required | ||
from oauth2app.authorize import Authorizer, MissingRedirectURI, AuthorizationException | ||
from oauth2app.authenticate import JSONAuthenticator, AuthenticationException | ||
|
||
|
||
class AuthorizeForm(forms.Form): | ||
pass | ||
|
||
def test(request): | ||
"""Test authentication""" | ||
authenticator = JSONAuthenticator() | ||
try: | ||
authenticator.validate(request) | ||
except AuthenticationException: | ||
return authenticator.error_response() | ||
return authenticator.response({"secret": "information"}) | ||
|
||
@login_required | ||
def missing_redirect_uri(request): | ||
return render_to_response('oauth2/missing_redirect_uri.html', {}, | ||
context_instance=RequestContext(request)) | ||
|
||
@login_required | ||
def authorize(request): | ||
authorizer = Authorizer() | ||
|
||
try: | ||
authorizer.validate(request) | ||
except MissingRedirectURI, e: | ||
return HttpResponseRedirect(reverse('oauth_missing_redirect_uri')) | ||
except AuthorizationException, e: | ||
return authorizer.error_redirect() | ||
|
||
if request.method == 'GET': | ||
return render_to_response('oauth/authorize.html', { | ||
'form': AuthorizeForm(), | ||
'form_action': '%s?%s' % (reverse('oauth_authorize'), authorizer.query_string) | ||
}, context_instance=RequestContext(request)) | ||
elif request.method == 'POST': | ||
form = AuthorizeForm(request.POST) | ||
if form.is_valid(): | ||
print request.POST.get('connect') | ||
if request.POST.get('connect') == "on": | ||
return authorizer.grant_redirect() | ||
else: | ||
return authorizer.error_redirect() | ||
|
||
return HttpResponseRedirect('/') |
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,12 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %}Authorize{% endblock %} | ||
|
||
{% block bodyclasses %}signin{% endblock %} | ||
{% block body %} | ||
<form action="{{ form_action }}" method="post"> | ||
{% csrf_token %} | ||
<input type="checkbox" name="connect"> Yes, please allow access | ||
<input type="submit" value="Submit" /> | ||
</form> | ||
{% endblock %} |
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,9 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %}Missing Redirect URI{% endblock %} | ||
|
||
{% block body %} | ||
<h1>Missing Redirect URI</h1> | ||
|
||
<p>The client requesting authorization did not specify a redirect URI so we are unable to complete this request.</p> | ||
{% endblock %} |
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