This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
344 lines (335 loc) · 15 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=1024">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>Designing a Mobile-Enabling API | Southern Fried Day of DotNetNuke, Charlotte, April 13, 2013 | by Brian Dukes @BrianDukes</title>
<meta name="description" content="Use the new DotNetNuke Service Framework to enable your modules and other extensions to power mobile applications and other new and unique workflows. While it's always been possible to have various sorts of web services alongside your module, the Service Framework provides a common pattern to enable smart authentication and a clean development model. This presentation will demonstrate what it looks like to use the Service Framework to develop an API that exposes rich functionality to a wide variety of potential clients, including native mobile applications.">
<meta name="author" content="Brian Dukes">
<link href="http://fonts.googleapis.com/css?family=Open+Sans:regular,semibold,italic,italicsemibold" rel="stylesheet">
<link href="css/combined-styles.css" rel="stylesheet">
<link rel="shortcut icon" href="favicon.png">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
</head>
<body class="impress-not-supported">
<div class="fallback-message">
<p>Your browser <strong>doesn't support the features required</strong> by impress.js, so you are presented with a simplified version of this presentation.</p>
<p>For the best experience please use the latest version of one of the following browsers:</p>
<div id="fallback-browsers">
<ul>
<li><a href="http://www.google.com/chrome/">Chrome</a></li>
<li><a href="http://www.apple.com/safari/">Safari</a></li>
<li><a href="http://www.firefox.com/">Firefox</a></li>
</ul>
</div>
</div>
<div id="impress">
<div id="title" class="step slide" data-x="0">
<hgroup>
<h1>Designing a Mobile-Enabling API</h1>
<h2>Brian Dukes, Engage</h2>
<h3>April 13, 2013 Southern Fried Day of DotNetNuke Charlotte NC</h3>
</hgroup>
<p class="sponsors">
<a href="http://www.dotnetnuke.com/"><img src="img/DotNetNuke.png" alt="DotNetNuke" /></a>
<a href="http://www.PowerDNN.com/"><img src="img/PowerDnn.png" alt="PowerDNN" /></a>
<a href="http://www.appliedi.net/"><img src="img/Applied%20Innovations.png" alt="Applied Innovations" /></a>
</p>
</div>
<div id="services-framework" class="step" data-x="1000" data-rotate="90">
<q>What does it <strong>look like</strong> to use the <em>Services Framework?</em></q>
</div>
<div id="agenda" class="step second-step" data-x="1000" data-rotate="90" data-z="-1000">
<h3>Agenda</h3>
<ul>
<li>Implementation</li>
<li>Benefits</li>
<li>Usage</li>
</ul>
</ul>
</div>
<div id="technology-overview" class="step" data-x="2000">
<h3>Technology Overview</h3>
<ul>
<li>
Based on <strong>ASP.NET Web API</strong>
</li>
<li>
Register <strong>routes</strong> to direct requests to controller <strong>actions</strong>
</li>
<li>
Implement <strong>controllers</strong> to process requests
</li>
<li>
Try to let the framework handle <strong>serialization</strong> into <abbr title="JavaScript Object Notation">JSON</abbr> or <abbr title="eXtensible Markup Language">XML</abbr>
</li>
</ul>
</div>
<div id="routes" class="step" data-x="3000">
<h3>Routes</h3>
<ul>
<li>
Implement <code>IServiceRouteMapper</code> interface
<ul><li><code>void RegisterRoutes(IMapRoute)</code></li></ul>
</li>
<li>
Call <code>MapHttpRoute</code> method on <code>IMapRoute</code> argument
</li>
<li>
Services route to <code>/DesktopModules/Module/API/[route]</code>
</li>
<li>
Define <strong>placeholders</strong> or <strong>defaults</strong> for the controller
</li>
<li>
By default, the <strong>action</strong> is determined by the HTTP verb
</li>
</ul>
</div>
<div id="route-example" class="step code-step second-step" data-x="3000" data-z="-1000" data-rotate="90">
<h3>Route Example</h3>
<pre class="brush: csharp">
/*GET /DesktopModules/Example/S/API/Example.ashx*/
namespace Example.Dnn.Services {
using DotNetNuke.Web.Api;
public class Mapperator : IServiceRouteMapper {
public void RegisterRoutes(IMapRoute mapper) {
mapper.MapHttpRoute(
moduleFolderName: "Example/S",
routeName: "default",
url: "{controller}.ashx",
namespaces: new[] {
"Example.Dnn.Services",
});
}
}
}
</pre>
</div>
<div id="controllers" class="step" data-x="4000">
<h3>Controllers</h3>
<ul>
<li>
Inherit from <code>DnnApiController</code>
</li>
<li>
Class name must end with <code>Controller</code>
</li>
<li>
All <code>public</code> methods are actions
</li>
<li>
Actions typically return <code>HttpResponseMessage</code>
</li>
</ul>
</div>
<div id="controller-example" class="step code-step second-step" data-x="4000" data-z="-1000" data-rotate="90">
<h3>Controller Example</h3>
<pre class="brush: csharp">
namespace Example.Dnn.Services {
using System.Net;
using System.Net.Http;
using DotNetNuke.Web.Api;
public class ExampleController : DnnApiController {
public HttpResponseMessage GetHello() {
return this.Request.CreateResponse(
HttpStatusCode.OK,
new {
number = 1,
text = "Hi!",
});
}
}
}
</pre>
</div>
<div id="authorization" class="step" data-x="5000">
<h3>Authorization</h3>
<ul>
<li>Only <strong>host-level</strong> access by default
<ul>
<li>Different than Web API defaults</li>
</ul>
</li>
<li>
<code>AllowAnonymousAttribute</code>
<ul>
<li>Disables all authorization</li>
<li>Only use on <strong>actions</strong>, never at controller level</li>
</ul>
</li>
<li>
<code>DnnAuthorizeAttribute</code>
<ul>
<li>Static list of role names</li>
</ul>
</li>
<li>
<code>RequireHostAttribute</code>
<ul>
<li>Override looser authentication from controller</li>
</ul>
</li>
</ul>
</div>
<div id="authorization-2" class="step second-step" data-x="5000" data-z="-1000">
<h3>Authorization</h3>
<ul>
<li>
<code>SupportedModulesAttribute</code>
<ul>
<li>Comma-separated <strong>desktop module</strong> names</li>
<li>
Requires <code>ModuleId</code> and <code>TabId</code> in request
<ul>
<li>Can be header, query-string, form value or cookie</li>
<li><code>beforeSend: sf.setModuleHeaders</code></li>
</ul>
</li>
</ul>
</li>
<li>
<code>DnnModuleAuthorizeAttribute</code>
<ul>
<li>Define <strong>access level</strong> and/or <strong>permission key</strong></li>
<li>Defaults to <strong>Host</strong> access level</li>
<li>Requires <code>ModuleId</code> and <code>TabId</code> in request</li>
</ul>
</li>
</ul>
</div>
<div id="authentication" class="step" data-x="6000">
<h3>Authentication</h3>
<ul>
<li><strong>Forms</strong> authentication cookie (AJAX)</li>
<li>
<strong>Basic</strong> access authentication
<ul>
<li>Requires <abbr title="Secure HyperText Transport Protocol">HTTPS</abbr>/<abbr title="Secure Sockets Layer">SSL</abbr> for security</li>
<li>Passes credentials on each request</li>
</ul>
</li>
<li>
<strong>Digest</strong> access authentication
<ul>
<li>Uses MD5 for "security"</li>
<li>Passes credentials on each request</li>
</ul>
</li>
<li>Need an OAuth (or other token-passing) solution</li>
<li>Anti-Forgery Token</li>
</ul>
</div>
<div id="dnn-context" class="step" data-x="7000">
<h3><abbr title="DotNetNuke">DNN</abbr> Context</h3>
<ul>
<li><code>UserInfo</code> (and authentication)</li>
<li><code>ActiveModule</code></li>
<li>
<code>PortalSettings</code>
<ul>
<li><code>ActiveTab</code></li>
<li><code>HomeDirectoryMapPath</code></li>
<li><code>AdministratorId</code></li>
<li><code>AdministratorRoleName</code></li>
<li><code>CultureCode</code></li>
<li><code>PortalAlias</code></li>
<li>etc.</li>
</ul>
</li>
</ul>
</div>
<div id="usage-request-scripts" class="step code-step second-step" data-x="8000" data-z="-1000" data-rotate="90">
<h3>Usage – Request Scripts</h3>
<pre class="brush: csharp">
using DotNetNuke.Framework;
public class MyModuleControl : ModuleView<MyViewModel> {
protected MyModuleControl() {
ServicesFramework.Instance.RequestAjaxAntiForgerySupport();
}
}
</pre>
</div>
<div id="usage-ajax-request" class="step code-step second-step" data-x="8000" data-z="-2000" data-rotate="90">
<h3>Usage – Ajax Request</h3>
<pre class="brush: js">
var sf = $.ServicesFramework(<%:ModuleContext.ModuleId%>);
$.ajax({
type: 'GET',
url: sf.getServiceRoot('Example/S') + 'Example.ashx',
beforeSend: sf.setModuleHeaders,
data: {}
}).done(function (data) { /*...*/ })
.fail(function (xhr, status) { /*...*/ });
</pre>
</div>
<div id="usage-phone-request" class="step code-step second-step" data-x="8000" data-z="-3000" data-rotate="90">
<h3>Usage – Phone Request</h3>
<pre class="brush: csharp">
var requestUri = new Uri("http://dnn7.dev/DesktopModules/Example/S/API/Example.ashx");
var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Headers.Add("ModuleId", "1740");
request.Headers.Add("TabId", "56");
var client = new HttpClient(new HttpClientHandler {
Credentials = new NetworkCredential("host", "pa$$")
});
var response = await client.SendAsync(request);
if (!response.IsSuccessStatusCode) {
// TODO: show error
return;
}
var json = await response.Content.ReadAsStringAsync();
</pre>
</div>
<div id="wrap-up" class="step" data-x="9000">
<h3>Wrap Up</h3>
<ul>
<li>Implementation</li>
<li>Benefits</li>
<li>Usage</li>
</ul>
<h3>More Info</h3>
<ul>
<li><a href="http://bit.ly/DNN-Services">http://bit.ly/DNN-Services</a></li>
<li><a href="http://bit.ly/DNN-Services-Pres">http://bit.ly/DNN-Services-Pres</a></li>
</ul>
</div>
<div id="sponsors" class="step" data-x="11000" data-rotate="180">
<h3>Thanks to all our Generous Sponsors!</h3>
<a id="dnn-logo" href="http://www.dotnetnuke.com/"><img src="img/DotNetNuke.png" alt="DotNetNuke" /></a>
<a href="http://www.PowerDNN.com/"><img src="img/PowerDnn.png" alt="PowerDNN" /></a>
<a href="http://www.appliedi.net/"><img src="img/Applied%20Innovations.png" alt="Applied Innovations" /></a>
<a href="http://www.iowacomputergurus.com/"><img src="img/Iowa%20Computer%20Gurus.jpg" alt="Iowa Computer Gurus" /></a>
<a href="http://www.ettaingroup.com"><img src="img/Ettain%20Group.png" alt="ettain group" /></a>
<a href="http://uncc.edu/"><img src="img/UNC%20Charlotte.png" alt="University of North Carolina at Charlotte" /></a>
<a href="http://logicaladvantage.com/"><img src="img/Logical%20Advantage.jpg" alt="Logical Advantage" /></a>
<a href="http://dnnadmins.com/"><img src="img/DNN%20Admins.png" alt="DNN Admins" /></a>
<a href="http://coolcoyotes.com/"><img src="img/Cool%20Coyotes.png" alt="Cool Coyotes" /></a>
<a href="http://www.engagesoftware.com/"><img src="img/Engage.png" alt="Engage Software" /></a>
<a href="http://www.aspose.com/"><img src="img/Aspose.png" alt="Aspose" /></a>
<a href="http://www.arrowdesigns.com/"><img src="img/Arrow%20Consulting%20%26%20Design.png" alt="Arrow Consulting & Design" /></a>
<a href="http://www.spiffywebteam.com/"><img src="img/Spiffy.png" alt="Spiffy Web Team" /></a>
<a href="http://www.pointclick.net/"><img src="img/PointClick%20Technologies.png" alt="PointClick Technologies" /></a>
<a href="http://2dnn.com/"><img src="img/2DNN.png" alt="2DNN" /></a>
<a href="http://www.websitescreative.com/"><img src="img/WSC.png" alt="Web Sites Creative" /></a>
<a href="http://www.moorecreative.com/"><img src="img/Moore%20Creative%20Company.png" alt="Moore Creative Company" /></a>
</div>
</div>
<div class="hint">
<p>Use a spacebar or arrow keys to navigate</p>
</div>
<script src="js/LAB.min.js"></script>
<script>
$LAB
.script("js/impress.js")
.script("js/shCore.js").wait()
.script("js/shBrushCSharp.js")
.script("js/shBrushJScript.js")
.wait(function () {
SyntaxHighlighter.highlight();
window.h5pCaniuse = function(a) { document.getElementById("fallback-browsers").innerHTML=a.html; };
}).script("http://api.html5please.com/csstransforms3d+classlist+dataset.json?callback=h5pCaniuse&texticon&nocss&html");
</script>
</body>
</html>