Skip to content

Commit f46a5b5

Browse files
committed
better support for implicit
1 parent a37098d commit f46a5b5

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

src/OAuth2Demo/Server/Controllers/Authorize.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ public function authorize(Application $app)
3131
}
3232

3333
// dispaly the "do you want to authorize?" form
34-
return $app['twig']->render('server/authorize.twig', array('client_id' => $app['request']->query->get('client_id')));
34+
return $app['twig']->render('server/authorize.twig', array(
35+
'client_id' => $app['request']->query->get('client_id'),
36+
'response_type' => $app['request']->query->get('response_type')
37+
));
3538
}
3639

3740
/**

views/client/show_implicit_token.twig

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,22 @@
33
{% block content %}
44
<h3>Token Retrieved!</h3>
55

6-
<pre><code> Access Token: <span id="access_token_display"><a onclick="showAccessToken();">(click here to pull from URL fragment)</a></span></code></pre>
6+
<pre><code> Access Token: <span id="access_token_display"><a onclick="showAccessToken();">(click here to pull from URL fragment)</a></span> </code></pre>
7+
8+
<p>The following code snippet will be run to pull the token data from the URL fragment:</p>
9+
<pre>
10+
<code> // function to parse fragment and return access token
11+
function getAccessToken() {
12+
var queryString = window.location.hash.substr(1);
13+
var queries = queryString.split("&");
14+
var params = {}
15+
for (var i = 0; i < queries.length; i++) {
16+
pair = queries[i].split('=');
17+
params[pair[0]] = pair[1];
18+
}
19+
20+
return params.access_token;
21+
};</code></pre>
722

823
<div id="request_resource" style="display:none">
924

@@ -21,28 +36,21 @@
2136

2237
<!-- Javascript for pulling the access token from the URL fragment -->
2338
<script>
24-
// function to parse fragment parameters
25-
var parseQueryString = function( queryString ) {
26-
var params = {}, queries, temp, i, l;
27-
28-
// Split into key/value pairs
29-
queries = queryString.split("&");
30-
31-
// Convert the array of strings into an object
32-
for ( i = 0, l = queries.length; i < l; i++ ) {
33-
temp = queries[i].split('=');
34-
params[temp[0]] = temp[1];
39+
function getAccessToken() {
40+
var queryString = window.location.hash.substr(1);
41+
var queries = queryString.split("&");
42+
var params = {}
43+
for (var i = 0; i < queries.length; i++) {
44+
pair = queries[i].split('=');
45+
params[pair[0]] = pair[1];
3546
}
3647
37-
return params;
48+
return params.access_token;
3849
};
3950
40-
// get token params from URL fragment
41-
var tokenParams = parseQueryString(window.location.hash.substr(1));
42-
4351
// show the token parsed from the fragment, and show the next step
4452
var showAccessToken = function (e) {
45-
document.getElementById('access_token_display').innerHTML = tokenParams.access_token;
53+
document.getElementById('access_token_display').innerHTML = getAccessToken();
4654
document.getElementById('request_resource').style.display = 'block';
4755
}
4856
</script>

views/server/authorize.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<li>make your life better</li>
2020
<li>miscellaneous nefarious purposes</li>
2121
</ul>
22-
<p>Click the button below to complete the authorize request and grant an <code>Authoriation Code</code> to {{client_id}}.
22+
<p>Click the button below to complete the authorize request and grant an <code>{{ response_type == 'code' ? 'Authoriation Code' : 'Access Token' }}</code> to {{client_id}}.
2323
<ul class="authorize_options">
2424
<li>
2525
<form action="{{ path('authorize_post') ~ '?' ~ app.request.queryString }}" method="post">

0 commit comments

Comments
 (0)