Skip to content

Commit c1edc04

Browse files
committed
Finished implicit grant sample. Yay.
1 parent f6581ea commit c1edc04

12 files changed

Lines changed: 9005 additions & 14362 deletions

samples/OAuthClient/OAuthClient.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@
6565
<Content Include="images\Sign-in-with-Twitter-darker.png" />
6666
<Content Include="SampleWcf2Javascript.html" />
6767
<Content Include="SampleWcf2Javascript.js" />
68-
<Content Include="Scripts\jquery-1.4.1-vsdoc.js" />
69-
<Content Include="Scripts\jquery-1.4.1.js" />
70-
<Content Include="Scripts\jquery-1.4.1.min.js" />
68+
<Content Include="Scripts\jquery-1.6.1.js" />
69+
<Content Include="Scripts\jquery-1.6.1.min.js" />
7170
<Content Include="Yammer.aspx" />
7271
<None Include="Service References\SampleResourceServer\DataApi.disco" />
7372
<None Include="Service References\SampleResourceServer\configuration91.svcinfo" />

samples/OAuthClient/SampleWcf2Javascript.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<title>OAuth 2.0 client (implicit grant)</title>
55

6-
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
6+
<script src="Scripts/jquery-1.6.1.js" type="text/javascript"></script>
77
<script src="SampleWcf2Javascript.js" type="text/javascript"></script>
88
</head>
99
<body>
@@ -23,31 +23,31 @@ <h1>
2323
<table border="0">
2424
<tr>
2525
<td>
26-
<input type="checkbox" name='scope' value='http://tempuri.org/IDataApi/GetName' id="getNameScopeCheckbox" /><label for="getNameScopeCheckbox">GetName</label>
26+
<input type="checkbox" name='scope' value='/DataApi.svc/web/name' id="getNameScopeCheckbox" /><label for="getNameScopeCheckbox">GetName</label>
2727
</td>
2828
</tr>
2929
<tr>
3030
<td>
31-
<input type="checkbox" name='scope' value='http://tempuri.org/IDataApi/GetAge' id="getAgeScopeCheckbox" /><label for="getAgeScopeCheckbox">GetAge</label>
31+
<input type="checkbox" name='scope' value='/DataApi.svc/web/age' id="getAgeScopeCheckbox" /><label for="getAgeScopeCheckbox">GetAge</label>
3232
</td>
3333
</tr>
3434
<tr>
3535
<td>
36-
<input type="checkbox" name='scope' value='http://tempuri.org/IDataApi/GetFavoriteSites' id="getFavoriteSitesScopeCheckbox" /><label for="getFavoriteSitesScopeCheckbox">GetFavoriteSites</label>
36+
<input type="checkbox" name='scope' value='/DataApi.svc/web/favoritesites' id="getFavoriteSitesScopeCheckbox" /><label for="getFavoriteSitesScopeCheckbox">GetFavoriteSites</label>
3737
</td>
3838
</tr>
3939
</table>
4040
<input type="submit" id="requestAuthorizationButton" value="Request Authorization" />
4141
<span id="authorizationLabel" />
4242
</fieldset>
4343
<br />
44-
<input type="button" value="Get Name" id="getNameButton" operation='http://tempuri.org/IDataApi/GetName' disabled="disabled" />
45-
<span id="nameLabel"></span>
44+
<input type="button" value="Get Name" id="getNameButton" operation='/DataApi.svc/web/name' disabled="disabled" />
45+
<span id="nameLabel" operation='/DataApi.svc/web/name' ></span>
4646
<br />
47-
<input type="button" value="Get Age" id="getAgeButton" operation='http://tempuri.org/IDataApi/GetAge' disabled="disabled" />
48-
<span id="ageLabel"></span>
47+
<input type="button" value="Get Age" id="getAgeButton" operation='/DataApi.svc/web/age' disabled="disabled" />
48+
<span id="ageLabel" operation='/DataApi.svc/web/age' ></span>
4949
<br />
50-
<input type="button" value="Get Favorite Sites" id="getFavoriteSitesButton" operation='http://tempuri.org/IDataApi/GetFavoriteSites' disabled="disabled" />
51-
<span id="favoriteSitesLabel"></span>
50+
<input type="button" value="Get Favorite Sites" id="getFavoriteSitesButton" operation='/DataApi.svc/web/favoritesites' disabled="disabled" />
51+
<span id="favoriteSitesLabel" operation='/DataApi.svc/web/favoritesites' ></span>
5252
</body>
5353
</html>

samples/OAuthClient/SampleWcf2Javascript.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ $(document).ready(function () {
5858
});
5959

6060
$(document).ready(function () {
61+
$.support.cors = true; // force cross-site scripting (as of jQuery 1.5)
62+
function serviceCall(operation, accessToken, label) {
63+
label.text('fetching...');
64+
$.ajax({
65+
url: "http://localhost:65169" + encodeURI(operation),
66+
headers: {
67+
"Authorization": "Bearer " + accessToken
68+
},
69+
cache: false,
70+
success: function (data, textStatus, jqXHR) { label.text(data.toString()); },
71+
error: function (jqXHR, textStatus, errorThrown) { label.text(textStatus + ": " + errorThrown); }
72+
});
73+
};
74+
6175
var fragmentIndex = document.location.href.indexOf('#');
6276
if (fragmentIndex > 0) {
6377
var fragment = document.location.href.substring(fragmentIndex + 1);
@@ -69,13 +83,19 @@ $(document).ready(function () {
6983
authorizationLabel.text('Authorization received! ' + suffix);
7084

7185
var scopes = args['scope'].split(' ');
72-
for (var scope in scopes) {
73-
var button = $('input[operation="' + scopes[scope] + '"]')[0];
74-
button.disabled = false;
75-
76-
var checkbox = $('input[value="' + scopes[scope] + '"]')[0];
86+
for (var scopeIndex in scopes) {
87+
var scope = scopes[scopeIndex];
88+
var button = $('input[operation="' + scope + '"]');
89+
button[0].disabled = false;
90+
button.click((function (value) {
91+
return function () {
92+
var label = $('span[operation="' + value + '"]');
93+
serviceCall(value, args['access_token'], label);
94+
};
95+
})(scope));
96+
var checkbox = $('input[value="' + scope + '"]')[0];
7797
checkbox.checked = true;
78-
}
98+
};
7999
}
80100
}
81101
});

0 commit comments

Comments
 (0)