forked from MrSwitch/hello.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
934 lines (784 loc) · 25.9 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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
<!DOCTYPE html>
<html>
<head>
<title>hello.js - Javascript API for OAuth2 authentication and REST services</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<link rel="stylesheet" href="/css-social-buttons/css/zocial.css"/>
<link rel="stylesheet" href="/_packages/document.css" />
<link rel="shortcut icon" href="assets/favicon.ico" type="image/x-icon" />
<script src="demos/client_ids.js"></script>
<script src="/_packages/jquery.js"></script>
<script src="/_packages/document.js"></script>
<link rel="stylesheet" href="assets/index.css"/>
</head>
<body>
<nav class="toc"></nav>
<h1><img src="assets/favicon.ico" width=64 height=64 style="vertical-align:middle;margin-right:20px;"/>hello.js</h1>
<blockquote><p>A client-side Javascript SDK for authenticating with <a href="http://tools.ietf.org/pdf/draft-ietf-oauth-v2-12.pdf" target="_blank">OAuth2</a> (and <b>OAuth1</b> with a <a href="#oauth-proxy">oauth proxy</a>) web services and querying their REST API's. HelloJS standardizes paths and responses to common API's like Google Data Services, Facebook Graph and Windows Live Connect. Its <b>modular</b> so that list is <a href="modules.html">growing</a>. No more spaghetti code!
</blockquote>
<!--NO-MARKDOWN-->
<h2>...I did not understand any of that</h2>
<p>Dont worry, here's a demo that illustrates what HelloJS can do. Connect a user through a service they belong to, e.g.</p>
<div id="profile">
<!-- ko foreach:networks -->
<button data-bind="click:function(){ hello( name ).login();}, attr:{'class':'zocial icon ' + name, title:'Signin to '+ displayName}" title="Signin"></button>
<!-- /ko -->
<br />
</div>
<p id="profile_done" style="text-align:center;display:none;">Hey, we got your details, test done! Choose another service or checkout <a href="#helloapi">what else you can do</a></P>
<!--/NO-MARKDOWN-->
<h2>Features</h2>
<p>Looking for more? HelloJS supports a lot more actions than just getting the users profile. Like, matching users with a users social friends list, sharing events with the users social streams, accessing and playing around with a users photos. Lets see if these whet your appetite ...</p>
<table>
<thead>
<tr>
<th></th>
<th>Windows</th>
<th>FaceBook</th>
<th>Google</th>
<th><a href="#helloapi">More..</th>
</tr>
</thead>
<tbody>
<tr>
<th class="method get"><a href="demos/profile.html">Profile: name, picture (email)</a></th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th class="method get"><a href="demos/friends.html">Friends/Contacts: name, id (email)</a></th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th class="method get">Albums, name, id, web link</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th class="method get"><a href="demos/albums.html">Photos in albums, names, links</a></th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th class="method get">Photo file: url, dimensions</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th class="method post">Create a new album</th>
<td>✓</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<th class="method post"><a href="demos/upload.html">Upload a photo</a></th>
<td>✓</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<th class="method delete">Delete an album</th>
<td>✓</td>
<td>✗</td>
<td></td>
</tr>
<tr>
<th class="method get"><a href="demos/activities.html">Status updates</a></th>
<td>✗</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th class="method post"><a href="demos/share.html">Update Status</a></th>
<td>✓</td>
<td>✓</td>
<td>✗</td>
</tr>
</tbody>
</table>
<ul>
<li>Items marked with a <span>✓</span> are fully working and can be <a href="./tests/">tested here</a>.
<li>Items marked with a <span>✗</span> aren't provided by the provider at this time.
<li>Blank items are work in progress, but there is good evidence that they can be done.
<li>Anything not listed i have no knowledge of and would appreciate input.
</ul>
<h2>Install</h2>
Download: <a class="button green" href="dist/hello.all.js" download="hello.js" target="_blank">HelloJS</a> | <a class="button blue" href="dist/hello.all.min.js" download="hello.min.js" target="_blank">HelloJS (minified)</a>
<p>Compiled source, which combines all the modules can be obtained from <a href="https://github.com/MrSwitch/hello.js/tree/master/dist">Github</a>, and source files can be found in <a href="https://github.com/MrSwitch/hello.js/tree/master/src">Source</a>.
<h3>Bower Package</h3>
<pre type="bash">
# Install the package manager, bower
npm install bower
# Install hello
bower install hello
</pre>
<p>The <a href="http://bower.io/">Bower</a> package shall install the aforementioned "/src" and "/dist" directories. The "/src" directory provides individual modules which can be packaged as desired.</p>
<p><b>Note:</b> Some services require OAuth1 or server-side OAuth2 authorization. In such case HelloJS communicates with an <a href="#oauth-proxy">OAuth Proxy</a>.</p>
<h2>Help & Support</h2>
<ul>
<li><a href="https://github.com/MrSwitch/hello.js/issues">GitHub</a> for reporting bugs and feature requests.
<li><a href="http://stackoverflow.com/questions/tagged/hello.js">Stackoverflow</a> to reach out for help.
</ul>
<h2>Quick Start</h2>
<p>Quick start shows you how to go from zero to loading in the name and picture of a user, like in the demo above.</p>
<ol>
<li><a href="#1-register">Register your app domain</a></li>
<li><a href="#2-include-hellojs-script-in-your-page">Include hello.js script</a></li>
<li><a href="#3-create-the-signin-buttons">Create the signin buttons</a></li>
<li><a href="#4-add-listeners-for-the-user-login">Setup listener for login and retrieve user info.</a></li>
<li><a href="#5-configure-hellojs-with-your-client_ids-and-initiate-all-listeners">Initiate the client_ids and all listeners</a></li>
</ol>
<h3>1. Register</h3>
<p>Register your application with atleast one of the following networks. Ensure you register the correct domain as they can be quite picky</p>
<ul>
<!--
<li><a target="_blank" href="http://msdn.microsoft.com/en-us/library/hh243641.aspx">Windows Live</a></li>
<li><a target="_blank" href="http://code.google.com/apis/accounts/docs/OAuth2UserAgent.html">Google+</a></li>
<li><a target="_blank" href="http://developers.facebook.com/docs/reference/dialogs/oauth/">FaceBook</a></li>
-->
<li><a target="_blank" href="https://developers.facebook.com/apps">FaceBook</a></li>
<li><a target="_blank" href="http://dev.live.com/">Windows Live</a> (click on dashboard)</li>
<li><a target="_blank" href="https://code.google.com/apis/console/b/0/#:access">Google +</a></li>
</ul>
<h3>2. Include Hello.js script in your page</h3>
<script class="pre" src="./dist/hello.all.min.js"></script>
<h3>3. Create the signin buttons</h3>
<p>Just add onclick events to call hello( network ).login(). Style your buttons as you like, i've used <a href="http://zocial.smcllns.com">zocial css</a>, but there are many other icon sets and fonts</p>
<script class="pre" type="html">
<button onclick="hello( 'windows' ).login()">windows</button>
</script>
<h3>4. Add listeners for the user login</h3>
<p>Lets define a simple function, which will load a user profile into the page after they signin and on subsequent page refreshes. Below is our event listener which will listen for a change in the authentication event and make an API call for data.</p>
<script class="pre">
hello.on('auth.login', function(auth){
// call user information, for the given network
hello( auth.network ).api( '/me' ).success(function(r){
var $target = $("#profile_"+ auth.network );
if($target.length==0){
$target = $("<div id='profile_"+auth.network+"'></div>").appendTo("#profile");
}
$target.html('<img src="'+ r.thumbnail +'" /> Hey '+r.name).attr('title', r.name + " on "+ auth.network);
});
});
</script>
<h3>5. Configure hello.js with your client_id's and initiate all listeners</h3>
<p>Now let's wire it up with our registration detail obtained in step 1. By passing a [key:value, ...] list into the <code>hello.init</code> function. e.g....</p>
<script class="pre">
hello.init({
facebook : FACEBOOK_CLIENT_ID,
windows : WINDOWS_CLIENT_ID,
google : GOOGLE_CLIENT_ID
},{redirect_uri:'redirect.html'});
</script>
<p>That's it. The code above actually powers the demo at the start so, no excuses.</p>
<h1>Core Methods</h1>
<h2>hello.init()</h2>
<p>Initiate the environment. And add the application credentials</p>
<h3>hello.init( {facebook: <em>id</em>, windows: <em>id</em>, google: <em>id</em>, .... } )</h3>
<table>
<thead>
<tr>
<th>name</th>
<th>type</th>
</tr>
</thead>
<tbody>
<tr>
<td>credentials</td>
<td><i>object( key => value, ... )</i>
<table>
<thead>
<tr>
<th>name</th>
<th>type</th>
<th>example</th>
<th>description</th>
<th>argument</th>
<th>default</th>
</tr>
</thead>
<tbody>
<tr>
<td>key</td>
<td><i>string</i></td>
<td><q>windows</q>, <q>facebook</q> or <q>google</q></td>
<td>App name"s</td>
<td><em>required</em></td>
<td>n/a</td>
</tr>
<tr>
<td>value</td>
<td><i>string</i></td>
<td><q>0000000AB1234</q></td>
<td>ID of the service to connect to</td>
<td><em>required</em></td>
<td>n/a</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>options</td>
<td>set's default <i>options</i>, as in hello.login()</i></td>
</tr>
</tbody>
</table>
<h3>Example:</h3>
<pre type="js">
hello.init({
facebook : '359288236870',
windows : '000000004403AD10'
});
</pre>
<h2>hello.login()</h2>
<div data-bind="template: { name: 'tests-template', data: { test : $root, filter:'login' } }"></div>
<p>If a network string is provided: A consent window to authenticate with that network will be initiated. Else if no network is provided a prompt to select one of the networks will open. A callback will be executed if the user authenticates and or cancels the authentication flow.</p>
<h3>hello.login( [network] [,options] [, callback() ] )</h3>
<table>
<tr>
<th>name</th>
<th>type</th>
<th>example</th>
<th>description</th>
<th>argument</th>
<th>default</th>
</tr>
<tr>
<td>network</td>
<td><i>string</i></td>
<td><q>windows</q>, <q>facebook</q></td>
<td>One of our services.</td>
<td><em>required</em></td>
<td><em>null</em></td>
</tr>
<tr>
<td>options</td>
<td colspan="5"><i>object</i>
<table>
<tr>
<th>name</th>
<th>type</th>
<th>example</th>
<th>description</th>
<th>argument</th>
<th>default</th>
</tr>
<tr>
<td>display</td>
<td><i>string</i></td>
<td><q>popup</q>, <q>page</q> or <q>none</q></td>
<td>How the signin flow should work, "none" is used to refresh the access_token in the background</td>
<td><em>optional</em></td>
<td><q>popup</q></td>
</tr>
<tr>
<td>scope</td>
<td><i>string</i></td>
<td><q>email</q>, <q>publish</q> or <q>photos</q></td>
<td>Comma separated list of <a href="#scope">scopes</a></td>
<td><em>optional</em></td>
<td><em>null</em></td></tr>
<tr>
<td>redirect_uri</td>
<td><i>string</i></td>
<td><q><a href="redirect.html" target="_blank">redirect.html</a></q></td>
<td>
A full or relative URI of a page which includes this script file hello.js</td>
<td>
<em>optional</em></td>
<td>
<em>window.location.href</em></td>
</tr>
<tr>
<td>response_type</td>
<td><i>string</i></td>
<td><q>token</q>, <q>code</q></td>
<td>Mechanism for skipping auth flow</td>
<td><em>optional</em></td>
<td><q>token</q></td>
</tr>
<tr>
<td>force</td>
<td><i>Boolean</i></td>
<td><i>false</i>: return current session else initiate auth flow; <i>true</i>: Always initiate auth flow</td>
<td>Mechanism for authentication</td>
<td><em>optional</em></td>
<td><i>true</i></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>callback</td>
<td><i>function</i></td>
<td><code>function(){alert("Logged in!");}</code></td>
<td>A callback when the users session has been initiated</td>
<td><em>optional</em></td>
<td><em>null</em></td>
</tr>
</table>
<h3>Examples:</h3>
<pre class="tryitoffline" type="js">
hello( "facebook" ).login( function(){
alert("You are signed in to Facebook");
});
</pre>
<h2>hello.logout()</h2>
<div data-bind="template: { name: 'tests-template', data: { test : $root, filter:'logout' } }"></div>
<p>Remove all sessions or individual sessions.</p>
<h3>hello.logout( [network] [, options ] [, callback() ] )</h3>
<table>
<tr>
<th>name</th>
<th>type</th>
<th>example</th>
<th>description</th>
<th>argument</th>
<th>default</th>
</tr>
<tr>
<td>network</td>
<td><i>string</i></td>
<td>
<q>windows</q>,
<q>facebook</q>
</td>
<td>One of our services.</td>
<td>
<em>optional</em>
</td>
<td>
<em>null</em>
</td>
</tr>
<tr>
<td>options</td>
<td colspan="5"><i>object</i>
<table>
<tr>
<th>name</th>
<th>type</th>
<th>example</th>
<th>description</th>
<th>argument</th>
<th>default</th>
</tr>
<tr>
<td>force</td>
<td><i>boolean</i></td>
<td><i>true</i></td>
<td>If set to true, the user will be logged out of the providers site as well as the local application. By default the user will still be signed into the providers site.</td>
<td>
<em>optional</em>
</td>
<td><i>false</i></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>callback</td>
<td><i>function</i></td>
<td>
<code>function(){alert("Logged in!");}
</code>
</td>
<td>
A callback when the users session has been initiated</td>
<td>
<em>optional</em>
</td>
<td>
<em>null</em>
</td>
</tr>
</table>
<h3>Example:</h3>
<pre class="tryit" type="js">
hello( "facebook" ).logout(function(){
alert("Signed out");
});
</pre>
<h2>hello.getAuthResponse()</h2>
<div data-bind="template: { name: 'tests-template', data: { test : $root, filter:'getAuthResponse' } }"></div>
<p>Get the current status of the session, this is an synchronous request and does not validate any session cookies which may have expired.</p>
<h3>hello.getAuthResponse( network );</h3>
<table>
<tr>
<th>name</th>
<th>type</th>
<th>example</th>
<th>description</th>
<th>argument</th>
<th>default</th>
</tr>
<tr>
<td>network</td>
<td><i>string</i></td>
<td><q>windows</q>, <q>facebook</q></td>
<td>One of our services.</td>
<td><em>optional</em></td>
<td><em>current</em></td>
</tr>
</table>
<h3>Examples:</h3>
<pre class="tryitoffline" type="js">
var online = function(session){
var current_time = (new Date()).getTime() / 1000;
return session && session.access_token && session.expires > current_time;
};
var fb = hello( "facebook" ).getAuthResponse();
var wl = hello( "windows" ).getAuthResponse();
alert(( online(fb) ? "Signed":"Not signed") + " into FaceBook, " + ( online(wl) ? "Signed":"Not signed")+" into Windows Live");
</pre>
<h2>hello.api()</h2>
<div data-bind="template: { name: 'tests-template', data: { test : $root, filter:'api' } }"></div>
<p>Make calls to the API for getting and posting data</p>
<h3>hello.api( [ path ], [ method ], [ data ], [ callback(json) ] )</h3>
<table>
<tr>
<th>name</th>
<th>type</th>
<th>example</th>
<th>description</th>
<th>argument</th>
<th>default</th>
</tr>
<tr>
<td>path</td>
<td><i>string</i></td>
<td>
<q>/me</q>,
<q>/me/friends</q>
</td>
<td>Path or URI of the resource. See <a href="#REST API">REST API</a>, Can be prefixed with the name of the service</td>
<td>
<em>required</em>
</td>
<td>null</td>
</tr>
<tr>
<td>method</td>
<td>
<q>get</q>,
<q>post</q>,
<q>delete</q>,
<q>put</q>
</td>
<td>See
<em>type</em>
</td>
<td>HTTP request method to use.</td>
<td>
<em>optional</em>
</td>
<td>
<q>get</q>
</td>
</tr>
<tr>
<td>data</td>
<td><i>object</i></td>
<td>
<code>{name:<q>Hello</q>, description:<q>Fandelicious</q>}</code>
</td>
<td>
A JSON object of data, FormData, HTMLInputElement, HTMLFormElment to be sent along with a
<q>get</q>,
<q>post</q>or
<q>put</q>request
</td>
<td>
<em>optional</em>
</td>
<td>
<em>null</em>
</td>
</tr>
<tr>
<td>callback</td>
<td><i>function</i></td>
<td>
<code>function(json){console.log(json);}</code>
</td>
<td>
A function to call with the body of the response returned in the first parameter as an object, else boolean false
</td>
<td>
<em>optional</em>
</td>
<td>
<em>null</em>
</td>
</tr>
</table>
<h3>Examples:</h3>
<pre class="tryit" type="js">
hello( "facebook" ).api("me").success(function(json){
alert("Your name is "+ json.name);
}).error(function(){
alert("Whoops!");
});
</pre>
<h1>Event subscription</h1>
<h2>hello.on()</h2>
<p>Bind a callback to an event. An event maybe triggered by a change in user state or a change in some detail. </p>
<h3>hello.on( event, callback );</h3>
<table>
<thead>
<tr>
<th>event</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td>auth</td>
<td>Triggered whenever session changes</td>
</tr>
<tr>
<td>auth.login</td>
<td>Triggered whenever a user logs in</td>
</tr>
<tr>
<td>auth.logout</td>
<td>Triggered whenever a user logs out</td>
</tr>
<tr>
<td>auth.update</td>
<td>Triggered whenever a users credentials change</td>
</tr>
</tbody>
</table>
<h3>Example:</h3>
<pre class="tryit" type="js">
var sessionstart = function(){
alert("Session has started");
};
hello.on("auth.login",sessionstart);
</pre>
<h2>hello.off()</h2>
<p>Remove a callback, both event name and function must exist</p>
<h3>hello.off( event, callback );</h3>
<pre class="tryit" type="js">
hello.off("auth.login",sessionstart);
</pre>
<h1>Misc</h1>
<h2>Pagination, Limit and Next Page</h2>
<p>A convenient function to get the `next` resultset is provided in the second parameter of any <code>GET</code> callback. Calling this function recreates the request with the original parameters and event listeners. Albeit the original path is augmented with the parameters defined in the <code>paging.next</code> property.</p>
<pre class="tryit" type="js">
hello( "facebook" ).api( "me/friends", {limit: 1} ).success( function( json, next ){
if( next ){
if( confirm( "Got friend "+ json.data[0].name + ". Get another?" ) ){
next();
}
}
else{
alert( "Got friend "+ json.data[0].name + ". That's it!" );
}
}).error( function(){
alert("Whoops!");
});
</pre>
<h2>Scope</h2>
<p>The scope property defines which privileges an app requires from a network provider. The scope can be defined globally for a session through <code>hello.init(object, {scope:'string'})</code>, or at the point of triggering the auth flow e.g. <code>hello('network').login({scope:'string'});</code></p>
<p>An app can specify multiple scopes, seperated by commas - as in the example below.</p>
<pre class="tryit" type="js">
hello( "facebook" ).login( {scope: "friends,photos,publish" } );
</pre>
<p>Scopes are tightly coupled with API requests, which will break if the session scope is missing or invalid. The best way to see this is next to the API paths in the <a href="http://adodson.com/hello.js/#helloapi">hello.api reference table</a>.</p>
<p>The table below illustrates some of the default scopes HelloJS exposes. Additional scopes may be added which are proprietary to a service, but take careful not to mix proprietary scopes with other services which dont know how to handle them.</p>
<table>
<thead>
<tr>
<th>Scope</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th><i>default</i></th>
<td>Read basic profile</td>
</tr>
<tr>
<th><q>friends</q></th>
<td>Read friends profiles</td>
</tr>
<tr>
<th><q>photos</q></th>
<td>Read users albums and photos</td>
</tr>
<tr>
<th><q>files</q></th>
<td>Read users files</td>
</tr>
<tr>
<th><q>publish</q></th>
<td>Publish status updates</td>
</tr>
<tr>
<th><q>publish_files</q></th>
<td>Publish photos and files</td>
</tr>
</tbody>
</table>
<p>Its good practice to limit the use of scopes and also to make users aware of why your app needs certain privilieges. Try to update the permissions as a user delves further into your app. For example: If the user would like to share a link with a friend; Include a button which the user has to click to trigger the hello.login with the 'friends' scope, and then the handler triggers the API call after authorisation.</p>
<h2>Error handling</h2>
<p>For hello.api([path], [<em>callback</em>]) the first parameter of <em>callback</em>
upon error will be either <i>boolean (false)</i> or be an error <i>object</i> as
described below.</p>
<h3>Error Object</h3>
<table>
<thead>
<tr>
<th>name</th>
<th>type</th>
</tr>
</thead>
<tbody>
<tr>
<td>error</td>
<td><i>object</i>
<table>
<thead>
<tr>
<th>name</th>
<th>type</th>
<th>example</th>
<th>description</th>
<th>argument</th>
<th>default</th>
</tr>
</thead>
<tbody>
<tr>
<td>code</td>
<td><i>string</i></td>
<td>
<q>request_token_unauthorized</q>
</td>
<td>Code</td>
<td>
<em>required</em>
</td>
<td>n/a</td>
</tr>
<tr>
<td>message</td>
<td><i>string</i></td>
<td class="auto-style2">The provided access token....</td>
<td>
Error message</td>
<td>
<em>required</em>
</td>
<td>n/a</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<h2>Extending the services</h2>
<p>Services are added to HelloJS as "modules" for more information about creating your own modules and examples, go to <a href="./modules.html">Modules</a></p>
<h2>OAuth Proxy</h2>
<div data-bind="template: { name: 'tests-template', data: { test : $root, filter:'oauth' } }">
A list of the service providers OAuth* mechanisms is available at <a href="http://adodson.com/hello.js/#oauth-proxy">Provider OAuth Mechanisms</a>
</div>
<p>For providers which support only OAuth1 and OAuth2 with Authorization Code flows. HelloJS directs the the authentication flow via a webservice to exchange temporary tokens for an access token. In the case of OAuth1, the webservice also signs subsequent API requests.</p>
<b>Quick start</b> Register your app ID's at the beta service, <a class="green button" href="https://auth-server.herokuapp.com/">//auth-server for OAuth1 and OAuth2 (with Authorization Code)</a>
<p>As a shim HelloJS uses a service hosted at <a href="https://auth-server.herokuapp.com/">https://auth-server.herokuapp.com/</a>. Developers may add their own network registration AppID/client_id and secret to this service in order to get up and running.</p>
<p>Alternatively the aforementioned service uses <a href="https://npmjs.org/package/oauth-shim">//node-oauth-shim</a>, so if you want to roll your own please look there for installation instructions and usage. Override the default path for this service in HelloJS at the point of calling hello.init, like so...</p>
<pre type="javascript">
hello.init(
CLIENT_IDS,
{
oauth_proxy : 'https://auth-server.herokuapp.com/proxy'
}
)
</pre>
<h2>Browser Support</h2>
<table>
<thead>
<tr>
<td>Browser</td>
<th><div class="ie9"></div>IE10</th>
<th><div class="ie9"></div>IE9</th>
<th><div class="ie8"></div>IE8</th>
<th><div class="ie7"></div>IE7</th>
<th><div class="ff"></div>FF</th>
<th><div class="cr"></div>CR</th>
<th><div class="sa"></div>SA</th>
<th><div class="op"></div>OP</th>
<th><div class="op"></div>Mob</th>
<th><div class="op"></div>Mini5</th>
<th>iOS</th>
<th>WP 7</th>
</tr>
</thead>
<tbody>
<tr>
<th>hello.js</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓<sup>1,2</sup></td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓<sup>3</sup></td>
<td>✓</td>
<td>✓<sup>4</sup></td>
</tr>
</tbody>
</table>
<ol>
<li><span>IE7</span>: Makes beeping sounds whenever the POST, PUT or DELETE methods are
used - because of the XD, IFrame+Form+hack.</li>
<li><span>IE7</span>: Requires JSON.js and localStorage shims</li>
<li><span>Opera Mini</span>: Supports inline consent only, i.e. reloads original page.</li>
<li><span>WP7</span>: Supports inline consent only, i.e. reloads original page.</li>
</ol>
<h2>Phonegap Support</h2>
<p>HelloJS can also be run on phonegap applications. Checkout the demo <a href="https://github.com/MrSwitch/hellojs-phonegap-demo">hellojs-phonegap-demo</a></p>
<h2>Contributing</h2>
<p><b>"No, It's perfect!"</b>.... If you believe that then give it a <a href="https://github.com/MrSwitch/hello.js">star</a>.</p>
<p>Having read this far you have already invested your time, why not contribute!?</p>
<p>HelloJS is constantly evolving, as are the services which it connects too. So if you think something could be said better, find something buggy or missing from either the code, documentation or demos then please put it in, no matter how trivial.</p>
<h3>Changing code?</h3>
<p>Ensure you setup and test your code on a variety of browsers.</p>
<pre type="bash">
# Using NodeJS on your dev environment
# cd into the project root and install dev dependencies
npm install -l
# run continuous integration tests
grunt test
</pre>
<!--NO-MARKDOWN-->
<script src="/_packages/knockout.js"></script>
<script src="assets/index.js"></script>
<script type="text/html" id="tests-template"></script>
<script>
// Initiate the library
hello.init(CLIENT_IDS_ALL,{redirect_uri: 'redirect.html', oauth_proxy:OAUTH_PROXY_URL});
$('#tests-template').load('assets/test_network.html', function() {
//knockout binding goes here
ko.applyBindings(model);
});
hello.on('auth.login', function(){
$("#profile_done").show();
});
</script>
<!--/NO-MARKDOWN-->
</body>
</html>