Skip to content

Commit 24e3f76

Browse files
committed
Merge branch 'playground-update'
2 parents da56a7b + ab981cd commit 24e3f76

File tree

14 files changed

+666
-527
lines changed

14 files changed

+666
-527
lines changed

example/example/api_v1.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from oauth2_provider.decorators import protected_resource
2-
from oauth2_provider import VERSION
2+
from oauth2_provider import VERSION as DOT_VERSION
33

44
import json
5-
from django.http import HttpResponse
65
from django import get_version
7-
from django.views.decorators.csrf import csrf_exempt
6+
from django.http import HttpResponse
7+
from django.http import HttpResponseBadRequest, HttpResponseNotFound
88
from django.core import serializers
9+
from django.views.decorators.csrf import csrf_exempt
910
from django.views.decorators.http import require_http_methods
10-
from django.http import HttpResponseBadRequest, HttpResponseNotFound
1111

12+
from oauthlib import __version__ as OAUTHLIB_VERSION
1213
from oauthlib.oauth2 import Server
1314

1415
from .models import MyApplication
@@ -32,8 +33,8 @@ def get_system_info(request, *args, **kwargs):
3233
A simple "read only" api endpoint, unprotected
3334
"""
3435
data = {
35-
'DOT version': VERSION,
36-
'oauthlib version': '0.5.1',
36+
'DOT version': DOT_VERSION,
37+
'oauthlib version': OAUTHLIB_VERSION,
3738
'Django version': get_version(),
3839
}
3940

example/example/context_processors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from oauth2_provider import VERSION
2+
3+
4+
def dot_version(request):
5+
return {'version': VERSION}

example/example/settings/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102

103103
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
104104
"django.core.context_processors.request",
105+
"example.context_processors.dot_version",
105106
)
106107

107108
ROOT_URLCONF = 'example.urls'

example/example/templates/example/api-client.html

Lines changed: 148 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -2,166 +2,165 @@
22
{% load url from future %}
33

44
{% block content %}
5-
<h2>Play with the API</h2>
6-
7-
<div class="row">
8-
<div class="span5">
9-
<form class="form-horizontal" id="idForm">
10-
<div class="control-group">
11-
<label class="control-label" for="idEndpoint">API endpoint</label>
12-
<div class="controls">
13-
<select id="idEndpoint" class="span3">
14-
{% for endpoint in endpoints %}
15-
<option>{{ endpoint.url }}</option>
16-
{% endfor %}
17-
</select>
18-
</div>
19-
</div>
20-
<div class="control-group">
21-
<label class="control-label" for="idLookup">pk (if needed)</label>
22-
<div class="controls">
23-
<input type="text" id="idLookup" class="span3">
24-
</div>
25-
</div>
26-
<div class="control-group">
27-
<label class="control-label" for="idToken">Access Token</label>
28-
<div class="controls">
29-
<input type="text" id="idToken" class="span3">
30-
<span class="help-block">
31-
If you have not registered an Application, try using this builtin token: <em>test_access_token</em>
32-
</span>
33-
</div>
34-
</div>
35-
<div class="control-group">
36-
<label class="control-label" for="idData">Payload</label>
37-
<div class="controls">
38-
<textarea rows="3" id="idData" class="span3"></textarea>
39-
<span class="help-block">
40-
Use JSON format, e.g. <em>{"param":"value"}</em>
41-
</span>
42-
</div>
43-
</div>
44-
<div class="control-group">
45-
<button type="submit" class="btn btn-inverse" id="idGET">GET</button>
46-
<button type="submit" class="btn btn-primary" id="idPOST">POST</button>
47-
<button type="submit" class="btn btn-warning" id="idPUT">PUT</button>
48-
<button type="submit" class="btn btn-danger" id="idDELETE">DELETE</button>
49-
</div>
50-
</form>
5+
<h2>Play with the API</h2>
6+
7+
<div class="row">
8+
<div class="col-sm-5">
9+
<form id="idForm" class="form-horizontal" role="form">
10+
<div class="form-group">
11+
<label class="col-sm-4 control-label">API endpoint</label>
12+
<div class="col-sm-8">
13+
<select id="idEndpoint" class="form-control">
14+
{% for endpoint in endpoints %}
15+
<option>{{ endpoint.url }}</option>
16+
{% endfor %}
17+
</select>
18+
</div>
19+
</div>
20+
<div class="form-group">
21+
<label class="col-sm-4 control-label">pk (if needed)</label>
22+
<div class="col-sm-8">
23+
<input type="text" id="idLookup" class="form-control">
24+
</div>
25+
</div>
26+
<div class="form-group">
27+
<label class="col-sm-4 control-label">Access Token</label>
28+
<div class="col-sm-8">
29+
<input type="text" id="idToken" class="form-control">
30+
<span class="help-block">
31+
If you have not registered an Application, try using this builtin token: <em>test_access_token</em>
32+
</span>
33+
</div>
34+
</div>
35+
<div class="form-group">
36+
<label class="col-sm-4 control-label">Payload</label>
37+
<div class="col-sm-8">
38+
<textarea rows="3" id="idData" class="form-control"></textarea>
39+
<span class="help-block">
40+
Use JSON format, e.g. <em>{"param":"value"}</em>
41+
</span>
42+
</div>
43+
</div>
44+
<div class="control-group">
45+
<button type="submit" class="btn btn-success" id="idGET">GET</button>
46+
<button type="submit" class="btn btn-primary" id="idPOST">POST</button>
47+
<button type="submit" class="btn btn-warning" id="idPUT">PUT</button>
48+
<button type="submit" class="btn btn-danger" id="idDELETE">DELETE</button>
49+
</div>
50+
</form>
5151
</div>
52-
<div class="span7">
53-
<p>Response: <span id="idStatus"></span></p>
54-
<pre id="idResponse"></pre>
52+
<div class="col-sm-7">
53+
<p>Response: <span id="idStatus"></span></p>
54+
<pre id="idResponse"></pre>
5555
</div>
56-
</div>
57-
58-
<h2>API Cheat Sheet</h2>
59-
60-
<div class="row"><div class="span12">
61-
62-
<h3>GET /system_info</h3>
63-
<p>Show simple system informations, this resource is not protected in any way.</p>
64-
<p><strong>Authentication:</strong> none</p>
65-
66-
<h3>GET /applications</h3>
67-
<p>Retrieve the list of Applications present in the playground</p>
68-
<p><strong>Authentication:</strong> none</p>
69-
70-
<h3>POST /applications</h3>
71-
<p>Create a new Application</p>
72-
<p><strong>Authentication:</strong> OAuth2, scopes required: can_create_application</p>
73-
<p>Parameters:</p>
74-
<ul>
56+
</div>
57+
58+
<h2>API Cheat Sheet</h2>
59+
<div class="row">
60+
<div class="col-sm-12">
61+
<h3>GET /system_info</h3>
62+
<p>Show simple system informations, this resource is not protected in any way.</p>
63+
<p><strong>Authentication:</strong> none</p>
64+
65+
<h3>GET /applications</h3>
66+
<p>Retrieve the list of Applications present in the playground</p>
67+
<p><strong>Authentication:</strong> none</p>
68+
69+
<h3>POST /applications</h3>
70+
<p>Create a new Application</p>
71+
<p><strong>Authentication:</strong> OAuth2, scopes required: can_create_application</p>
72+
<p>Parameters:</p>
73+
<ul>
7574
<li>name (optional) - Friendly name for the Application</li>
7675
<li>client_id (optional) - The client identifier issued to the client during the registration</li>
7776
<li>client_secret (optional) - Confidential secret issued to the client duringthe registration</li>
7877
<li>client_type (required, values: [public,private]) - Confidential secret issued to the client duringthe registration</li>
7978
<li>authorization_grant_type (required, values: [authorization-code,implicit,passwordl,client-credentials,all-in-one]) - Authorization flow</li>
80-
</ul>
81-
82-
<h3>GET /applications/:lookup</h3>
83-
<p>Retrieve Application detail</p>
84-
<p><strong>Authentication:</strong> OAuth2</p>
79+
</ul>
8580

86-
<h3>PUT /applications/:lookup</h3>
87-
<p>Update Application details</p>
88-
<p><strong>Authentication:</strong> OAuth2</p>
89-
<p>Parameters: same as application creation</p>
81+
<h3>GET /applications/:lookup</h3>
82+
<p>Retrieve Application detail</p>
83+
<p><strong>Authentication:</strong> OAuth2</p>
9084

91-
<h3>DELETE /applications/:lookup</h3>
92-
<p>Delete application</p>
93-
<p><strong>Authentication:</strong> OAuth2</p>
85+
<h3>PUT /applications/:lookup</h3>
86+
<p>Update Application details</p>
87+
<p><strong>Authentication:</strong> OAuth2</p>
88+
<p>Parameters: same as application creation</p>
9489

95-
</div></div>
96-
{% endblock %}
90+
<h3>DELETE /applications/:lookup</h3>
91+
<p>Delete application</p>
92+
<p><strong>Authentication:</strong> OAuth2</p>
93+
</div>
94+
</div>
95+
{% endblock content %}
9796

9897

9998
{% block javascript %}
100-
<script type="text/javascript">
101-
(function() {
102-
103-
$('#idForm').submit(function() {
104-
return false;
105-
});
106-
107-
var showMsg = function(status, msg) {
108-
$('#idStatus').html(status);
109-
$('#idResponse').text('').text(msg);
110-
};
111-
112-
var getUrl = function() {
113-
var url = $('#idEndpoint').val();
114-
url = url.replace('lookup', $('#idLookup').val());
115-
return url;
116-
};
117-
118-
var callAPI = function(url, reqType, token, data) {
119-
if(typeof(token)==='undefined') token = '';
120-
if(typeof(data)==='undefined') data = '';
121-
122-
var req = $.ajax({
123-
url: url,
124-
type: reqType,
125-
contentType: 'application/json',
126-
data: data,
127-
beforeSend: function(request){
128-
request.setRequestHeader("Authorization", "Bearer " + token);
129-
}
130-
});
131-
132-
req.done(function(data, textStatus, jqXHR) {
133-
var status = 'HTTP ' + jqXHR.status;
134-
showMsg(status, JSON.stringify(data, null, 4));
135-
});
136-
137-
req.fail(function(jqXHR){
138-
var status = 'HTTP ' + jqXHR.status;
139-
showMsg(status, "Request failed: " + jqXHR.statusText);
140-
});
141-
};
142-
143-
$('#idGET').click(function() {
144-
var token = $("#idToken").val();
145-
callAPI(getUrl(), 'GET', token);
146-
});
147-
148-
$('#idPOST').click(function() {
149-
var token = $("#idToken").val();
150-
var data = $("#idData").val();
151-
callAPI(getUrl(), 'POST', token, data);
152-
});
153-
154-
$('#idPUT').click(function() {
155-
var token = $("#idToken").val();
156-
var data = $("#idData").val();
157-
callAPI(getUrl(), 'PUT', token, data);
158-
});
159-
160-
$('#idDELETE').click(function() {
161-
var token = $("#idToken").val();
162-
callAPI(getUrl(), 'DELETE', token);
163-
});
164-
165-
})();
166-
</script>
99+
<script type="text/javascript">
100+
(function() {
101+
102+
$('#idForm').submit(function() {
103+
return false;
104+
});
105+
106+
var showMsg = function(status, msg) {
107+
$('#idStatus').html(status);
108+
$('#idResponse').text('').text(msg);
109+
};
110+
111+
var getUrl = function() {
112+
var url = $('#idEndpoint').val();
113+
url = url.replace('lookup', $('#idLookup').val());
114+
return url;
115+
};
116+
117+
var callAPI = function(url, reqType, token, data) {
118+
if(typeof(token) === 'undefined') token = '';
119+
if(typeof(data) === 'undefined') data = '';
120+
121+
var req = $.ajax({
122+
url: url,
123+
type: reqType,
124+
contentType: 'application/json',
125+
data: data,
126+
beforeSend: function(request){
127+
request.setRequestHeader("Authorization", "Bearer " + token);
128+
}
129+
});
130+
131+
req.done(function(data, textStatus, jqXHR) {
132+
var status = 'HTTP ' + jqXHR.status;
133+
showMsg(status, JSON.stringify(data, null, 4));
134+
});
135+
136+
req.fail(function(jqXHR){
137+
var status = 'HTTP ' + jqXHR.status;
138+
showMsg(status, "Request failed: " + jqXHR.statusText);
139+
});
140+
};
141+
142+
$('#idGET').click(function() {
143+
var token = $("#idToken").val();
144+
callAPI(getUrl(), 'GET', token);
145+
});
146+
147+
$('#idPOST').click(function() {
148+
var token = $("#idToken").val();
149+
var data = $("#idData").val();
150+
callAPI(getUrl(), 'POST', token, data);
151+
});
152+
153+
$('#idPUT').click(function() {
154+
var token = $("#idToken").val();
155+
var data = $("#idData").val();
156+
callAPI(getUrl(), 'PUT', token, data);
157+
});
158+
159+
$('#idDELETE').click(function() {
160+
var token = $("#idToken").val();
161+
callAPI(getUrl(), 'DELETE', token);
162+
});
163+
164+
})();
165+
</script>
167166
{% endblock javascript %}

0 commit comments

Comments
 (0)