summaryrefslogtreecommitdiffstats
path: root/samples/OAuthClient
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2011-06-21 17:07:45 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2011-06-21 17:07:45 -0700
commit98216166e5a9cf40cc2f829dfb95e8536cd3152f (patch)
tree165a8ddd935df3248e4ca8e5f5a01eec77c892ea /samples/OAuthClient
parent507e88d5c3e8263da48a0b9e695a35bc051f6b56 (diff)
downloadDotNetOpenAuth-98216166e5a9cf40cc2f829dfb95e8536cd3152f.zip
DotNetOpenAuth-98216166e5a9cf40cc2f829dfb95e8536cd3152f.tar.gz
DotNetOpenAuth-98216166e5a9cf40cc2f829dfb95e8536cd3152f.tar.bz2
javascript client now parses the implicit grant response enough to enable the right buttons and re-check checkboxes.
Diffstat (limited to 'samples/OAuthClient')
-rw-r--r--samples/OAuthClient/SampleWcf2Javascript.html7
-rw-r--r--samples/OAuthClient/SampleWcf2Javascript.js75
2 files changed, 60 insertions, 22 deletions
diff --git a/samples/OAuthClient/SampleWcf2Javascript.html b/samples/OAuthClient/SampleWcf2Javascript.html
index 9ce3814..bc4d466 100644
--- a/samples/OAuthClient/SampleWcf2Javascript.html
+++ b/samples/OAuthClient/SampleWcf2Javascript.html
@@ -38,15 +38,16 @@
</tr>
</table>
<input type="submit" id="requestAuthorizationButton" value="Request Authorization" />
+ <span id="authorizationLabel" />
</fieldset>
<br />
- <input type="submit" value="Get Name" id="getNameButton" disabled="disabled" />
+ <input type="button" value="Get Name" id="getNameButton" operation='http://tempuri.org/IDataApi/GetName' disabled="disabled" />
<span id="nameLabel"></span>
<br />
- <input type="submit" value="Get Age" id="getAgeButton" disabled="disabled" />
+ <input type="button" value="Get Age" id="getAgeButton" operation='http://tempuri.org/IDataApi/GetAge' disabled="disabled" />
<span id="ageLabel"></span>
<br />
- <input type="submit" value="Get Favorite Sites" id="getFavoriteSitesButton" disabled="disabled" />
+ <input type="button" value="Get Favorite Sites" id="getFavoriteSitesButton" operation='http://tempuri.org/IDataApi/GetFavoriteSites' disabled="disabled" />
<span id="favoriteSitesLabel"></span>
</body>
</html>
diff --git a/samples/OAuthClient/SampleWcf2Javascript.js b/samples/OAuthClient/SampleWcf2Javascript.js
index dcc8a15..9eb945e 100644
--- a/samples/OAuthClient/SampleWcf2Javascript.js
+++ b/samples/OAuthClient/SampleWcf2Javascript.js
@@ -1,4 +1,34 @@
-$(document).ready(function () {
+var utilities = {
+ assembleQueryString: function(args) {
+ var query = '?';
+ for (var key in args) {
+ if (query.length > 1) query += '&';
+ query += encodeURIComponent(key) + '=' + encodeURIComponent(args[key])
+ };
+ return query;
+ },
+
+ parseQueryString: function (query) {
+ var result = new Array();
+ var pairs = query.split('&');
+ for (var i = 0; i < pairs.length; i++) {
+ var pair = pairs[i].split('=');
+ var key = decodeURIComponent(pair[0]);
+ var value = decodeURIComponent(pair[1]);
+ result[key] = value;
+ };
+ return result;
+ },
+
+ stripQueryAndFragment: function (url) {
+ var index = url.indexOf('?');
+ if (index < 0) index = url.indexOf('#');
+ url = index < 0 ? url : url.substring(0, index);
+ return url;
+ }
+};
+
+$(document).ready(function () {
var requestAuthorizationButton = $('#requestAuthorizationButton');
function gatherRequestedScopes() {
@@ -13,32 +43,39 @@
return scopes;
};
- function assembleQueryString(args) {
- var query = '?';
- for (var key in args) {
- if (query.length > 1) query += '&';
- query += encodeURIComponent(key) + '=' + encodeURIComponent(args[key])
- };
- return query;
- };
-
- function stripQueryAndFragment(url) {
- var index = url.indexOf('?');
- if (index < 0) index = url.indexOf('#');
- url = index < 0 ? url : url.substring(0, index);
- return url;
- };
-
function requestAuthorizationButton_onClick(evt) {
var args = new Array();
args['scope'] = gatherRequestedScopes();
- args['redirect_uri'] = stripQueryAndFragment(document.location.href);
+ args['redirect_uri'] = utilities.stripQueryAndFragment(document.location.href);
args['response_type'] = 'token';
args['client_id'] = 'sampleImplicitConsumer';
- var authorizeUrl = "http://localhost:50172/OAuth/Authorize" + assembleQueryString(args);
+ var authorizeUrl = "http://localhost:50172/OAuth/Authorize" + utilities.assembleQueryString(args);
document.location = authorizeUrl;
};
requestAuthorizationButton.click(requestAuthorizationButton_onClick);
});
+
+$(document).ready(function () {
+ var fragmentIndex = document.location.href.indexOf('#');
+ if (fragmentIndex > 0) {
+ var fragment = document.location.href.substring(fragmentIndex + 1);
+ var args = utilities.parseQueryString(fragment);
+ if (args['access_token']) {
+ var authorizationLabel = $('#authorizationLabel');
+ var lifetimeInSeconds = args['expires_in'];
+ var suffix = '(access token expires in ' + lifetimeInSeconds + ' seconds)';
+ authorizationLabel.text('Authorization received! ' + suffix);
+
+ var scopes = args['scope'].split(' ');
+ for (var scope in scopes) {
+ var button = $('input[operation="' + scopes[scope] + '"]')[0];
+ button.disabled = false;
+
+ var checkbox = $('input[value="' + scopes[scope] + '"]')[0];
+ checkbox.checked = true;
+ }
+ }
+ }
+}); \ No newline at end of file