summaryrefslogtreecommitdiffstats
path: root/samples/OAuthClient/SampleWcf2Javascript.js
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2011-06-20 21:26:56 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2011-06-20 21:26:56 -0700
commit507e88d5c3e8263da48a0b9e695a35bc051f6b56 (patch)
treed5753afe4d0f5be1c652032a5af2751b0de77064 /samples/OAuthClient/SampleWcf2Javascript.js
parent1f77a2b10ed11ac084d1def41b3c891178b0520b (diff)
downloadDotNetOpenAuth-507e88d5c3e8263da48a0b9e695a35bc051f6b56.zip
DotNetOpenAuth-507e88d5c3e8263da48a0b9e695a35bc051f6b56.tar.gz
DotNetOpenAuth-507e88d5c3e8263da48a0b9e695a35bc051f6b56.tar.bz2
We have an implicit grant javascript client that can obtain an access token.
It doesn't know how to use it yet though.
Diffstat (limited to 'samples/OAuthClient/SampleWcf2Javascript.js')
-rw-r--r--samples/OAuthClient/SampleWcf2Javascript.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/samples/OAuthClient/SampleWcf2Javascript.js b/samples/OAuthClient/SampleWcf2Javascript.js
new file mode 100644
index 0000000..dcc8a15
--- /dev/null
+++ b/samples/OAuthClient/SampleWcf2Javascript.js
@@ -0,0 +1,44 @@
+$(document).ready(function () {
+ var requestAuthorizationButton = $('#requestAuthorizationButton');
+
+ function gatherRequestedScopes() {
+ scopes = '';
+ var scopeElements = $("input[name='scope']");
+ for (var i = 0; i < scopeElements.length; i++) {
+ if (scopeElements[i].checked) {
+ if (scopes.length > 0) scopes += ' ';
+ scopes += scopeElements[i].value;
+ }
+ };
+ 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['response_type'] = 'token';
+ args['client_id'] = 'sampleImplicitConsumer';
+
+ var authorizeUrl = "http://localhost:50172/OAuth/Authorize" + assembleQueryString(args);
+ document.location = authorizeUrl;
+ };
+
+ requestAuthorizationButton.click(requestAuthorizationButton_onClick);
+});