-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdocumentation.html
1397 lines (855 loc) · 56.2 KB
/
documentation.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
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Grasshopper - Documentation</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="A CMS for the people, a great experience for developers, users and customers. Use Grasshopper to drastically speed up development for distributed systems. Support your clients better." />
<meta property="og:title" content="Grasshopper - Documentation"/>
<meta property="og:type" content="website"/>
<meta property="og:image" content="https://solid-interactive.github.io/grasshopper-core-nodejs/images/Grasshopper-icon.png" />
<meta property="og:url" content="https://solid-interactive.github.io/grasshopper-core-nodejs/documentation.html"/>
<meta property="og:description" content="A CMS for the people, a great experience for developers, users and customers. Use Grasshopper to drastically speed up development for distributed systems. Support your clients better." />
<meta name="twitter:image" content="https://solid-interactive.github.io/grasshopper-core-nodejs/images/Grasshopper-icon.png" />
<!-- stylesheets -->
<link rel="canonical" href="https://solid-interactive.github.io/grasshopper-core-nodejs/documentation.html" />
<link rel="stylesheet" href="/grasshopper-core-nodejs/css/vendor/animate.css" />
<link rel="stylesheet" href="/grasshopper-core-nodejs/css/vendor/flexslider.css" />
<link rel="stylesheet" href="/grasshopper-core-nodejs/css/vendor/brankic.css" />
<link rel="stylesheet" href="/grasshopper-core-nodejs/css/compiled/theme.css" />
<link rel="stylesheet" type="text/css" href="https://yandex.st/highlightjs/8.0/styles/default.min.css" />
<!-- javascript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="/grasshopper-core-nodejs/js/bootstrap/bootstrap.min.js"></script>
<script src="/grasshopper-core-nodejs/js/vendor/jquery.flexslider.min.js"></script>
<script type="text/javascript" src="/grasshopper-core-nodejs/js/vendor/jwplayer/jwplayer.js"></script>
<script src="/grasshopper-core-nodejs/js/theme.js"></script>
<script src="https://yandex.st/highlightjs/8.0/highlight.min.js"></script>
<!--[if lt IE 9]>
<script src="https://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body id="docs" data-spy="scroll" data-target="#guide">
<div id="guide">
<h1 class="logo">
<a href="index.html">Grasshopper</a>
</h1>
<ul class="menu nav">
<li>
<a href="#gettingstarted">Getting Started</a>
<ul class="nav">
<li><a href="#stack">Stack</a></li>
<li><a href="#requirements">Requirements</a></li>
<li><a href="#installation">Installation</a></li>
<li><a href="#projectconfiguration">Project Configuration</a></li>
</ul>
</li>
<li>
<a href="#authentication">Authentication</a>
<ul class="nav">
<li><a href="#google-auth-setup">Setup Google Login</a></li>
</ul>
</li>
<li>
<a href="#users">Users</a>
<ul class="nav">
<li><a href="#user-properties">User Properties</a></li>
<li><a href="#user-roles">User Roles</a></li>
<li><a href="#user-methods">User Methods</a></li>
</ul>
</li>
<li>
<a href="#content">Content</a>
<ul class="nav">
<li><a href="#queries">Queries</a></li>
</ul>
</li>
<li>
<a href="#contributing">Contributing</a>
<ul class="nav">
<li><a href="#environment-setup">Setting up your development environment</a></li>
<li><a href="#testing-deployment">Deploy to a test environment</a></li>
</ul>
</li>
</ul>
</div>
<div id="api-docs">
<div id="methods">
<div class="languages">
<a class="language selected" data-lang="javascript" href="#">Examples</a>
</div>
<div class="method" id="gettingstarted">
<div class="method-section clearfix">
<div class="method-description">
<h3>Getting started</h3>
<p>You will find that many concepts that modern applications need are built right into Grasshopper. User management, flexible data storage, permissions, plus much more are bundled into the framework.</p>
<p>Grasshopper is modular and built on top of a modern web development stack. It was written entirely in JavaScript and it uses a NoSQL database system. File storage can either be local or in the cloud on a CDN. As the project matures, more database systems and CDN options will become available.</p>
<p>Currently, Grasshopper will run in any environment that supports Node.js and MongoDB. This is great news since loading Node.js apps into modern cloud containers is very simple. Users hosting the application themselves or using services like Heroku, Engine Yard or any other PaaS (Platform as a Service) are fully supported.</p>
<p>Every implementation of the system is different but keep reading and you will start to get a sense of how the project is organized.</p>
</div>
<div class="method-example">
<pre>
<code class="asciidoc"><p>Definitions</p>
<ul>
<li><p><a href="https://nodejs.org/">Node.js</a> is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications.</p></li>
<li><p><a href="https://en.wikipedia.org/wiki/Npm_(software)">npm</a> npm is the official package manager for Node.js. npm is bundled and installed automatically with the environment.</p></li>
<li><p><a href="https://gruntjs.com/">GruntJS</a> is a JavaScript based command line build tool that helps developers automate repetitive tasks.</p></li>
<li><p><a href="https://expressjs.com/">ExpressJS</a> is a minimal and flexible node.js web application framework, providing a robust set of features for building single and multi-page, and hybrid web applications.</p></li>
<li><p><a href="https://www.mongodb.org">MongoDB</a> is an open-source document database, and the leading NoSQL database.</p></li>
<li><p><a href="https://www.mongodb.com/nosql-explained">NoSQL</a> databases explained.</p></li>
<li><p><a href="https://en.wikipedia.org/wiki/Content_delivery_network">CDN</a> or content delivery network is a large distributed system of servers deployed in multiple data centers across the Internet.</p></li>
<li><p><a href="https://en.wikipedia.org/wiki/Platform_as_a_service">PaaS</a> or Platform as a Service provides a solution stack as a service. IE: Heroku or others like it.</p></li>
</ul>
</code>
</pre>
</div>
</div>
</div>
<div class="method" id="stack">
<div class="method-section clearfix">
<div class="method-description">
<h4>Grasshopper Stack</h4>
<p>Typical Grasshopper Application Stack
<img src="images/stack.png" alt="Stack"></p>
</div>
<div class="method-example">
<pre>
<code class=""><ul>
<li><p>Grasshopper Core is responsible for all the heavy lifting of the framework. Core includes methods for managing users (data and access), content types, content, nodes (or folders) and assets.</p></li>
<li><p>Grasshopper API is an HTTP wrapper of core designed to run on HTTP or HTTPS protocols.</p></li>
<li><p>Grasshopper Admin is a fully functional administration application that uses the API to manage your applications.</p></li>
<li><p>Proxy is an optional express application that can site along side the Grasshopper API to extend the base functionality.</p></li>
</ul>
</code>
</pre>
</div>
</div>
</div>
<div class="method" id="requirements">
<div class="method-section clearfix">
<div class="method-description">
<h4>Requirements</h4>
<p>The Grasshopper framework uses all of the below software/services:</p>
<ul>
<li><p><a href="https://git-scm.com/">Git</a> version control system.</p></li>
<li><p><a href="https://nodejs.org/download/">Node.js</a>, a platform for easily building fast, scalable network applications.</p></li>
<li><p><a href="https://www.mongodb.org/">MongoDB</a>, an open-source document database that Grasshopper uses for data storage.</p></li>
<li><p><a href="https://gruntjs.com/">Grunt</a>, the JavaScript task runner</p></li>
<li><p><a href="https://bower.io/">bower</a>, a package manager for the web</p></li>
<li><p><a href="https://sass-lang.com">Sass</a>, Syntactically Awesome Style Sheets.</p></li>
<li><p><a href="https://bundler.io/">Bundler</a>: Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed. </p></li>
<li><p>Sass Globbing Plugin (used to compile the admin), Sass globbing allows you to import many sass or scss files in a single import statement.</p></li>
<li><p>Sass CSS Importer (used to compile the admin): The Sass CSS Importer allows you to import a CSS file into Sass.</p></li>
<li><p>Access to local file system or CDN like <a href="https://aws.amazon.com/s3/">Amazon S3</a>.</p></li>
</ul>
</div>
<div class="method-example">
<pre>
<code class=""><ul>
<li><p><a href="https://nodejs.org/download/">https://nodejs.org/download/</a></p></li>
<li><p>npm install -g grunt-cli</p></li>
<li><p>npm install -g bower</p></li>
<li><p><a href="https://sass-lang.com/install">Sass installation instruction</a></p></li>
<li><p>gem install sass-globbing</p></li>
<li><p>gem install sass-css-importer</p></li>
<li><p><a href="https://www.mongodb.org/downloads">https://www.mongodb.org/downloads</a></p></li>
</ul>
</code>
</pre>
</div>
</div>
</div>
<div class="method" id="installation">
<div class="method-section clearfix">
<div class="method-description">
<h4>Installation</h4>
<p>Installing Grasshopper is super simple. Once your machine is configured, creating a new project is as easy as typing <code>grasshopper fly</code>.</p>
<p>The installation process fully configures working instances of <a href="https://github.com/Solid-Interactive/grasshopper-core-nodejs">core</a>, <a href="https://github.com/Solid-Interactive/grasshopper-api-js">api</a> and <a href="https://github.com/Solid-Interactive/grasshopper-admin">admin</a> for you.</p>
<p>See the example of how to install the NPM and setup a new project. We assume that all of the prerequisite software is already installed.</p>
<p>Watch a video of an installation (less than a minute):</p>
<div id="container">Loading the player ...</div>
<script type="text/javascript">
jwplayer("container").setup({
flashplayer: "js/vendor/jwplayer/player.swf",
file: "https://s3.amazonaws.com/SolidInteractive/images/grasshopper/grasshopper-cli-fly.mp4",
height: 270,
poster: "https://s3.amazonaws.com/SolidInteractive/images/grasshopper/grasshopper-cli-fly.png",
width: 480 });
</script>
</div>
<div class="method-example">
<pre>
<code class="bash"><p>npm install -g grasshopper-cli</p>
<p>mkdir myproject</p>
<p>cd myproject</p>
<p>grasshopper fly</p>
<p>-- That's it, you have a working site. Just make whatever configuration changes you need to the project and you are on your way.</p>
</code>
</pre>
</div>
</div>
</div>
<div class="method" id="projectconfiguration">
<div class="method-section clearfix">
<div class="method-description">
<h4>Configuring your project</h4>
<p>When you run the <code>grasshopper fly</code> command, you get a fully functional application, but you may want to change some of the configuration values.
The configuration values are passed into <code>grasshopper-api</code>.</p>
<h5>Api / Core</h5>
<p>Start grasshopper api is done by requiring it in and passing in an options object. A convenient way to do this is to create
a JSON config file and use it as the options object as follows:</p>
<div class="highlight"><pre><code class="language-javascript" data-lang="javascript"><span class="kd">var</span> <span class="nx">ghapi</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'grasshopper-api'</span><span class="p">),</span>
<span class="nx">options</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'./grasshopper-config.json'</span><span class="p">),</span>
<span class="nx">ghcore</span><span class="p">,</span>
<span class="nx">ghapiRouter</span><span class="p">,</span>
<span class="nx">returnedObject</span><span class="p">;</span>
<span class="nx">returnedObject</span> <span class="o">=</span> <span class="nx">ghapi</span><span class="p">(</span><span class="nx">options</span><span class="p">);</span>
<span class="c1">// the router should be used in conjunction with express</span>
<span class="c1">// it can be added directly to the app or piggy backed on another router</span>
<span class="c1">// e.g. expressApp.use('/api', ghapiRouter);</span>
<span class="nx">ghapiRouter</span> <span class="o">=</span> <span class="nx">returnedObject</span><span class="p">.</span><span class="nx">router</span><span class="p">;</span>
<span class="c1">// ghcore can be used to make queries, etc.</span>
<span class="nx">ghcore</span> <span class="o">=</span> <span class="nx">returnedObject</span><span class="p">.</span><span class="nx">core</span><span class="p">;</span>
</code></pre></div>
<p>Here is an example file:</p>
<div class="highlight"><pre><code class="language-json" data-lang="json"><span class="p">{</span>
<span class="nt">"server"</span><span class="p">:</span> <span class="p">{</span>
<span class="nt">"https"</span><span class="p">:{</span>
<span class="nt">"key"</span><span class="p">:</span><span class="s2">"{full path to key}"</span><span class="p">,</span>
<span class="nt">"cert"</span><span class="p">:</span><span class="s2">"{full path to cert}"</span>
<span class="p">},</span>
<span class="nt">"proxy"</span> <span class="p">:</span> <span class="kc">false</span><span class="p">,</span>
<span class="nt">"maxFilesSize"</span><span class="p">:</span> <span class="mi">2000000</span><span class="p">,</span>
<span class="nt">"maxFieldsSize"</span><span class="p">:</span> <span class="mi">2000000</span><span class="p">,</span>
<span class="nt">"maxFields"</span><span class="p">:</span> <span class="mi">1000</span>
<span class="p">},</span>
<span class="nt">"crypto"</span><span class="p">:</span> <span class="p">{</span>
<span class="nt">"secret_passphrase"</span> <span class="p">:</span> <span class="s2">"{unique term per project}"</span>
<span class="p">},</span>
<span class="nt">"db"</span><span class="p">:</span> <span class="p">{</span>
<span class="nt">"type"</span><span class="p">:</span> <span class="s2">"mongodb"</span><span class="p">,</span>
<span class="nt">"host"</span><span class="p">:</span> <span class="s2">"mongodb://localhost/{database name}"</span><span class="p">,</span>
<span class="nt">"shorthost"</span><span class="p">:</span><span class="s2">"localhost"</span><span class="p">,</span>
<span class="nt">"database"</span><span class="p">:</span> <span class="s2">"{database name}"</span><span class="p">,</span>
<span class="nt">"username"</span><span class="p">:</span> <span class="s2">""</span><span class="p">,</span>
<span class="nt">"password"</span><span class="p">:</span> <span class="s2">""</span><span class="p">,</span>
<span class="nt">"defaultPageSize"</span> <span class="p">:</span> <span class="s2">"10000"</span><span class="p">,</span>
<span class="nt">"debug"</span><span class="p">:</span> <span class="kc">false</span>
<span class="p">},</span>
<span class="nt">"assets"</span><span class="p">:</span> <span class="p">{</span>
<span class="nt">"default"</span> <span class="p">:</span> <span class="s2">"local"</span><span class="p">,</span>
<span class="nt">"tmpdir"</span> <span class="p">:</span> <span class="s2">"{absolute path to tmp directory}"</span><span class="p">,</span>
<span class="nt">"engines"</span><span class="p">:</span> <span class="p">{</span>
<span class="nt">"local"</span><span class="p">:{</span>
<span class="nt">"path"</span><span class="p">:</span><span class="s2">"{absolute path to public asset folder from the root of your comp}"</span><span class="p">,</span>
<span class="nt">"urlbase"</span><span class="p">:</span><span class="s2">"{full url base to serve files from}"</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">},</span>
<span class="nt">"logger"</span> <span class="p">:</span> <span class="p">{</span>
<span class="nt">"adapters"</span><span class="p">:</span> <span class="p">[{</span>
<span class="nt">"type"</span><span class="p">:</span><span class="s2">"console"</span><span class="p">,</span>
<span class="nt">"application"</span><span class="p">:</span><span class="s2">"{application name}"</span><span class="p">,</span>
<span class="nt">"machine"</span><span class="p">:</span><span class="s2">"{machine name}"</span>
<span class="p">}]</span>
<span class="p">},</span>
<span class="nt">"identities"</span> <span class="p">:</span> <span class="p">{</span>
<span class="nt">"google"</span> <span class="p">:</span> <span class="p">{</span>
<span class="nt">"appId"</span> <span class="p">:</span> <span class="s2">"{ your google app id }"</span><span class="p">,</span>
<span class="nt">"secret"</span> <span class="p">:</span> <span class="s2">"{ your google secret id }"</span><span class="p">,</span>
<span class="nt">"scopes"</span> <span class="p">:</span> <span class="p">[</span> <span class="s2">"{ array of scopes you want to authorize }"</span> <span class="p">],</span>
<span class="nt">"redirectUrl"</span> <span class="p">:</span> <span class="s2">"{ the url you want to redirect to after successful auth, the users token will be appended to this route ex. '/login' entered here will send the user to '/login/googleToken' }"</span>
<span class="p">}</span>
<span class="p">},</span>
<span class="nt">"bodyParser"</span> <span class="p">:</span> <span class="p">{</span>
<span class="nt">"limit"</span> <span class="p">:</span> <span class="s2">"5m"</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre></div>
</div>
<div class="method-example">
<pre>
<code class="asciidoc"><p>Definitions for all possible config values</p>
<ul>
<li>server (optional)
<ul>
<li><em>https</em>: If you need to run the API over https then you should include the server configuration
<ul>
<li><em>key</em>: Absolute path to SSL private key</li>
<li><em>cert</em> Absolute path to SSL certificate</li>
</ul></li>
<li><em>proxy</em>: Defaults to false. Boolean indicating whether you are going to proxy the api onto another express server. If False, when you initialize API, it will create a server for you.</li>
<li><em>maxFilesSize</em>: Defaults to 2 megabytes. The Maximum file size you are allowed to upload. In bytes.</li>
<li><em>maxFieldsSize</em>: Defaults to 2 megabytes. The maximum field size you are allowed to have. In bytes.</li>
<li><em>maxFields</em>: Defaults to 1000. The maximum number of fields you are allowed to have.</li>
</ul></li>
<li><p>crypto (required)</p>
<ul>
<li><em>secret_passphrase</em>: Unique key that will be used when encrypting/decrypting values using the utils/crypto module.</li>
</ul></li>
<li><p>db (required)</p>
<ul>
<li><em>type</em>: Always should be 'mongodb' until more database storage engines are supported.</li>
<li><p><em>host</em>: Full URL of your mongo database connection</p>
<p><a href="https://mongodb.github.io/node-mongodb-native/driver-articles/mongoclient.html#basic-parts-of-the-url">FORMAT</a></p>
<p>mongodb://[username:password@]host[:port]/[database][?options]</p></li>
<li><p><em>shorthost</em>: Identifies either a hostname, IP address, or unix domain socket</p></li>
<li><p><em>database</em>: Name of the database to login to</p></li>
<li><p><em>username</em>: (optional) If given, it will attempt to login after connecting to a database server</p></li>
<li><p><em>password</em>: (optional) If given, it will attempt to login after connecting to a database server</p></li>
<li><p><em>defaultPageSize</em>: The number of results to be included in a "page." This value can be customized per your application</p></li>
<li><p><em>debug</em>: (true/false) Debug mode of "true" will turn on db logging</p></li>
</ul></li>
<li><p>assets (at least 1 engine is required)</p>
<ul>
<li><em>default</em>: local/amazon</li>
<li><em>tmpdir</em>: Absolute path on your local system where temporary files will be saved</li>
<li><em>engines</em>: One or more ways to store assets that are posted to Grasshopper
<ul>
<li><em>local</em>: Engine needed if you plan on storing files locally on your server
<ul>
<li><em>path</em>: Absolute path to the "publically" browsable asset folder</li>
<li><em>urlbase</em>: The base URL that will be serving the files (ex: https://yoursite.com/assets)</li>
</ul></li>
<li><em><a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html">amazon</a></em>: If you are going to use Amazon's S3 to store your files then you will need to define the amazon engine.
<ul>
<li><em>accessKeyId</em>: Your AWS access key ID</li>
<li><em>secretAccessKey</em>: Your AWS secret access key</li>
<li><em><a href="https://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region">region</a></em>: The region to send service requests to</li>
<li><em>bucket</em>: Buckets partition the namespace of objects stored in Amazon S3 at the top level</li>
<li><em>urlbase</em>: The base URL that will be serving the files (could be your own or amazon's)</li>
<li><em>assetsDir</em>: A prefix (folder) to add to your s3 keys. The keys are the node id combined with the file name.</li>
<li><em>archiveDeletionsTo</em>: A folder to move items to instead of deleting them. Impacts individual asset deletions and node deletions. If falsey, then items will really be deleted instead of just moved.</li>
</ul></li>
</ul></li>
<li>IMPORTANT : Each defined engine will run (saving, updating, etc), but the engine set to default will serve the files.</li>
</ul></li>
<li><p>identities (optional)</p>
<ul>
<li><em><a href="https://developers.google.com/accounts/docs/OAuth2">google</a></em> Google Oath integration
<ul>
<li><em><a href="https://support.google.com/a/answer/162105?hl=en">appId</a></em>: The client ID is considered public information, and is used to build login URLs, or included in Javascript source code on a page.</li>
<li><em><a href="https://support.google.com/a/answer/162105?hl=en">secret</a></em>: The client secret must be kept confidential. If a deployed app cannot keep the secret confidential, such as Javascript or native apps, then the secret is not used.</li>
<li><em>redirectUrl</em>: The service will only redirect users to a registered URI, which helps prevent some attacks. Any HTTP redirect URIs must be protected with TLS security, so the service will only redirect to URIs beginning with "https". This prevents tokens from being intercepted during the authorization process.</li>
<li><em><a href="https://developers.google.com/+/api/oauth#scopes">scopes</a></em>: Scopes are strings that enable access to particular resources, such as user data. (https://www.googleapis.com/auth/userinfo.profile', https://www.googleapis.com/auth/userinfo.email)</li>
<li><em>tokenEndpoint</em>: Location that will generate an access token in the Google system</li>
<li><em>oauthCallback</em>: If the user grants the permission, the Google Authorization Server sends your application an access token (or an authorization code that your application can use to obtain an access token). If the user does not grant the permission, the server returns an error</li>
</ul></li>
</ul></li>
<li><p>bodyParser (optional)</p>
<ul>
<li><code>bodyParser.limit</code> is passed directly to the <a href="https://github.com/expressjs/body-parser">body-parser express middleware</a></li>
<li>the default value is, <code>2mb</code></li>
</ul></li>
</ul>
</code>
</pre>
</div>
</div>
</div>
<div class="method" id="authentication">
<div class="method-section clearfix">
<div class="method-description">
<h4>Authentication</h4>
<p>Membership is a critical component to almost all applications. Grasshopper's authentication methods are fully extensible, and it contains a robust permissions mechanism that allows you to protect data based off of the application’s requirements.</p>
<p>Supported Authentication Methods</p>
<ul>
<li>Basic: This is the typical username and password method</li>
<li>Google: Allows you to authenticate with your Gmail account.</li>
</ul>
</div>
<div class="method-example">
<pre>
<code class="javascript"><p>// Basic Authentication Example
grasshopper.auth( 'basic', { username: '', password: '' } ).then( function( token ) {
// Store user's token somewhere
} ).done();</p>
<p>// Google Authentication Example
grasshopper.auth( 'google', { code: 'TMP GOOGLE TOKEN' } ).then( function( token ) {
// Store user's token somewhere
} ).done();</p>
</code>
</pre>
</div>
</div>
</div>
<div class="method" id="google-auth-setup">
<div class="method-section clearfix">
<div class="method-description">
<h5>Setup Google Login</h5>
<ol>
<li>Ensure that the <a href="https://solid-interactive.github.io/grasshopper-core-nodejs/documentation.html#projectconfiguration">identities.google object on your ghapi.json</a> is correctly setup.</li>
<li>Ensure that you have added both a a redirect uri and a javascript origin to your <a href="https://developers.google.com/console">Google Developer Console OAuth configuration</a>.
<ul>
<li>The javascript origin is the root of your website. For example:
<ul>
<li><code>http://localhost:3000</code></li>
<li><code>https://www.grasshopper-admin-sample.herokuapp.com</code></li>
</ul></li>
<li>The redirect uri should be the root of your website with the following append to the end <code>/oauth2callback</code>. This endpoint is where google will send the authenticated users temporary token. This endpoint already exists in Grasshopper-Api.
This would create the following url's from the examples mentioned above:
<ul>
<li><code>http://localhost:3000/auth2Callback</code></li>
<li><code>https://www.grasshopper-admin-sample.herokuapp.com/oauth2callback</code></li>
</ul></li>
</ul></li>
<li>Setup the methods to get the googleAuthUrl from API then send the user there.
The <code>GET /googleurl</code> endpoint is already available on Api.
<ul>
<li>This endpoint is not authenticated.</li>
<li>This endpoint can also take an override redirect url. If you use this override, it will redirect the user back to that url with the grasshopper token in the url after all auth work is done.</li>
</ul></li>
<li>Modify your applications routes to collect the grasshopper token from the redirected route.
Grasshopper API will redirect the user back to your app with the grasshopper token appended to the redirectUrl you specified in your config. If you overrode this by passing it as a header in the <code>/geturl</code> request, then it will be appended to that url.
<ul>
<li>If your redirectUrl in your config was: <code>/login</code>, then the user is redirected to <code>/login/{ grasshopperToken }</code>.</li>
<li>If you overrode your redirectUrl then you will see: <code>/someOtherPage/{ grasshopperToken }</code>.</li>
<li>Your route will need to be able to accept the returned url, in backbone, this might look like: <code>'login(/:token)'</code>.
Where the <code>()</code> signifies an optional param. Then a <code>/</code>. Then a <code>:token</code>. The word 'token' in the example is important as this will be passed the the route function as a parameter.</li>
</ul></li>
<li>Once you have a handle on the grasshopper token, save it to local storage, prepended with 'Google '.</li>
</ol>
<p>Check out our sample projects for examples of both of these authentication methods in working applications.</p>
</div>
<div class="method-example">
<pre>
<code class="javascript"><p>// Get Google Oauth Url Example
$.ajax({
dataType : 'json',
url : yourApiEndpoint + '/googleurl',
type : 'GET'
})
.done(function(url) {
window.location.href = url;
});</p>
<p>// Get Google Oauth Url while override the redirectUrl
$.ajax({
dataType : 'json',
url : yourApiEndpoint + '/googleurl',
type : 'GET',
headers : {'redirectUrl' : '/someOtherPage'}
})
.done(function(url) {
window.location.href = url;
});</p>
<p>// If Using Backbone, your router might look like
Router.extend({
routes : {
'login(/:token)' : 'displayLogin'
}
});</p>
<p>// Accept the token
function doGoogleLogin(token) {
// Do something with google token.
};</p>
</code>
</pre>
</div>
</div>
</div>
<div class="method" id="users">
<div class="method-section clearfix">
<div class="method-description">
<h4>Users</h4>
</div>
<div class="method-example">
</div>
</div>
</div>
<div class="method" id="user-properties">
<div class="method-section clearfix">
<div class="method-description">
<h5>User Properties</h5>
<div class="highlight"><pre><code class="language-javascript" data-lang="javascript"> <span class="p">{</span>
<span class="nx">_id</span><span class="o">:</span> <span class="mi">12345657</span><span class="p">,</span>
<span class="nx">role</span><span class="o">:</span> <span class="s1">'admin'</span><span class="p">,</span>
<span class="nx">enabled</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
<span class="nx">firstname</span><span class="o">:</span> <span class="s1">'firstname'</span><span class="p">,</span>
<span class="nx">lastname</span><span class="o">:</span> <span class="s1">'lastname'</span><span class="p">,</span>
<span class="nx">identities</span><span class="o">:</span> <span class="p">{</span>
<span class="nx">basic</span><span class="o">:</span> <span class="p">{</span>
<span class="nx">username</span><span class="o">:</span> <span class="s1">'admin'</span><span class="p">,</span>
<span class="nx">salt</span><span class="o">:</span> <span class="s1">'111111111'</span><span class="p">,</span>
<span class="nx">hash</span><span class="o">:</span> <span class="s1">'282828282828282828'</span>
<span class="p">},</span>
<span class="nx">google</span><span class="o">:</span> <span class="p">{</span>
<span class="nx">id</span><span class="o">:</span> <span class="s1">'292929292929292'</span><span class="p">,</span>
<span class="nx">accessToken</span><span class="o">:</span> <span class="s1">'474747474747'</span>
<span class="nx">refreshToken</span><span class="o">:</span> <span class="s1">'4098409874'</span>
<span class="p">}</span>
<span class="p">},</span>
<span class="nx">displayname</span> <span class="o">:</span> <span class="s1">'admin'</span><span class="p">,</span>
<span class="nx">linkedidentities</span> <span class="o">:</span> <span class="p">[</span><span class="s1">'basic'</span><span class="p">],</span>
<span class="nx">email</span><span class="o">:</span> <span class="s1">'[email protected]'</span><span class="p">,</span>
<span class="nx">profile</span> <span class="o">:</span> <span class="p">{}</span>
<span class="p">}</span>
</code></pre></div>
</div>
<div class="method-example">
<pre>
<code class="asciidoc"><ul>
<li><em>_id</em>: Valid Mongo Object Id</li>
<li><em>role</em>: The users role, see below for more information on roles.</li>
<li><em>enabled</em>: Boolean indicating if the user is currently enabled or not.</li>
<li><em>firstname</em>: The users First Name.</li>
<li><em>lastname</em>: The users Last Name.</li>
<li><em>identities</em>: The Identities object represents the identities that the user has, this is private and will never be returned.
<ul>
<li><em>basic</em>: The basic identity represents the most simple form of auth.
<ul>
<li><em>username</em>: The Users username that they would use to login.</li>
<li><em>salt</em>: Salt for password.</li>
<li><em>hash</em>: Hash for password.</li>
</ul></li>
<li><em>google</em>: The Identity object representing google auth.
<ul>
<li><em>id</em>: The users google id. Unique to all google users.</li>
<li><em>accessToken</em>: An access token used to auth the user for google services. This token expires.</li>
<li><em>refreshToken</em>: A token given by google to refresh the users access token.</li>
</ul></li>
</ul></li>
<li><em>displayname</em>: The users display name, if not set when creating a user, it will default to the login for basic auth, and the email address for google auth.</li>
<li><em>linkedidentities</em>: Array representing the identities the user has.</li>
<li><em>email</em>: The users email address.</li>
<li><em>profile</em>: The users profile, This can be an object containing anything.</li>
</ul>
</code>
</pre>
</div>
</div>
</div>
<div class="method" id="user-roles">
<div class="method-section clearfix">
<div class="method-description">
<h5>User Roles</h5>
<p>Roles (in order of power) :</p>
<ol>
<li>Admin - Can do anything.</li>
<li>Editor - Can create and edit content and content types.</li>
<li>Author - Can only create content.</li>
<li>Reader - Can only read content.</li>
<li>External - Cannot access the admin in any way.</li>
</ol>
</div>
<div class="method-example">
</div>
</div>
</div>
<div class="method" id="user-methods">
<div class="method-section clearfix">
<div class="method-description">
<h5>User methods</h5>
<ul>
<li><p>users.query</p>
<ul>
<li>middleware.identity,</li>
<li>middleware.role(roles.ADMIN),</li>
<li>middleware.event('parse'),</li>
<li>middleware.event('validate'),</li>
<li>middleware.users.query,</li>
<li>middleware.event('out')</li>
</ul></li>
<li><p>users.insert</p>
<ul>
<li>middleware.identity,</li>
<li>middleware.role(roles.ADMIN),</li>
<li>middleware.users.linkedidentities.create,</li>
<li>middleware.users.parse,</li>
<li>middleware.event('parse'),</li>
<li>middleware.event('validate'),</li>
<li>middleware.users.validate,</li>
<li>middleware.users.insert,</li>
<li>middleware.event('out'),</li>
<li>middleware.event('save')</li>
</ul></li>
<li><p>users.update</p>
<ul>
<li>middleware.identity,</li>
<li>setDefaultUser,</li>
<li>roleOrSelf(roles.ADMIN),</li>
<li>middleware.users.parse,</li>
<li>middleware.event('parse'),</li>
<li>middleware.event('validate'),</li>
<li>middleware.users.validate,</li>
<li>middleware.users.update,</li>
<li>middleware.event('out'),</li>
<li>middleware.event('save')</li>
</ul></li>
<li><p>users.getById</p>
<ul>
<li>middleware.identity,</li>
<li>setDefaultUser,</li>
<li>roleOrSelf(roles.ADMIN),</li>
<li>middleware.event('parse'),</li>
<li>middleware.event('validate'),</li>
<li>middleware.users.getById,</li>
<li>middleware.event('out')</li>
</ul></li>
<li><p>users.getByEmail</p>
<ul>
<li>middleware.identity,</li>
<li>middleware.role(roles.ADMIN),</li>
<li>middleware.event('parse'),</li>
<li>middleware.event('validate'),</li>
<li>middleware.users.getByEmail,</li>
<li>middleware.event('out')</li>
</ul></li>
<li><p>users.deleteById</p>
<ul>
<li>middleware.identity,</li>
<li>middleware.role(roles.ADMIN),</li>
<li>middleware.event('parse'),</li>
<li>middleware.event('validate'),</li>
<li>middleware.users.deleteById,</li>
<li>middleware.event('out'),</li>
<li>middleware.event('delete')</li>
</ul></li>
<li><p>users.savePermissions</p>
<ul>
<li>middleware.event('parse'),</li>
<li>middleware.event('validate'),</li>
<li>middleware.identity,</li>
<li>middleware.role(roles.ADMIN)</li>
</ul></li>
<li><p>users.deletePermissions</p>
<ul>
<li>middleware.event('parse'),</li>
<li>middleware.event('validate'),</li>
<li>middleware.identity,</li>
<li>middleware.role(roles.ADMIN)</li>
</ul></li>
<li><p>users.linkIdentity</p>
<ul>
<li>middleware.event('parse'),</li>
<li>middleware.event('validate'),</li>
<li>middleware.identity,</li>
<li>middleware.users.linkIdentity,</li>
<li>middleware.event('out'),</li>
<li>middleware.event('save')</li>
</ul></li>
<li><p>users.unlinkIdentity</p>
<ul>
<li>middleware.event('parse'),</li>