|
1 | 1 | Web App Samples |
2 | 2 | ======================== |
3 | 3 | ### Introduction |
4 | | -These applications demonstrate Spark's cloud based 3D model storage, mesh preparation and 3D printing and can also provide an example of the Spark OAuth 2.0 procedure. |
| 4 | +These applications demonstrate Spark's cloud based 3D model storage, mesh preparation and 3D printing and can also provide an example of the Spark OAuth 2.0 implicit login procedure. |
5 | 5 |
|
6 | 6 | ### Required setup before running the sample code |
7 | 7 | 1. Clone the software repository (copy its files) to a folder on your web server. |
8 | 8 | 2. If you have not already done so, define an app on the Spark Developers portal at https://spark.autodesk.com/developers/myApps. |
9 | | -3. In the API Keys tab of the app registration, enter the fully qualified URL of the sample's plugins/login/login-callback.html file (do not use a relative path). |
| 9 | +3. In the API Keys tab of the app registration, enter the fully qualified URL of the sample's home page (do not use a relative path). |
10 | 10 | 4. Copy the app key for later use. |
11 | | -5. If you are not using the advanced 3-legged auth flow, skip to step 8. |
12 | | -6. Copy the app secret for later use. |
13 | | -7. For the 3-legged authentication flow, you need to run a server. This repo is provided with a nodejs server. To run it you should: |
14 | | - * Copy server/nodejs/config.example.js to server/nodejs/config.js and enter your app key and secret. |
15 | | - * Install nodejs and then: |
16 | | - ```sh |
17 | | - $ sudo npm -g install grunt-cli |
18 | | - $ cd server/nodejs |
19 | | - $ npm install |
20 | | - $ node server.js |
21 | | - ``` |
22 | | - * Now you have a server running on port 3000. You can check it by going to http://your-server.com:3000. |
23 | | -8. Initialize your app - see info in the "Quick Start" section. |
24 | | - |
| 11 | +5. Setup your app with your app key - see info in the "Quick Start" section. |
25 | 12 |
|
26 | 13 | ### Quick Start |
27 | | -* <b>Include the SDK library in your HTML page</b> just before closing the body section (`</body>`). |
28 | | - |
29 | | -```HTML |
30 | | -<script type="text/javascript" src="//code.spark.autodesk.com/autodesk-spark-sdk.min.js"></script> |
31 | | -``` |
32 | | - |
33 | | -* After including the SDK library, the method ADSKSpark.Client.initialize() must be used to initialize and setup the SDK:<br> |
34 | | -For the 3-legged authentication flow, the SDK requires that authentication API requests are called from a server. For example the guest token URL could be <i>http://example.com/guest_token</i>. |
35 | | - |
36 | | -```JavaScript |
37 | | -ADSKSpark.Client.initialize('<your app key>'); //<your app key> is a string containing your Spark app key, provided during registration. |
38 | | -``` |
39 | | - |
40 | | -#### Sample code |
41 | | - |
42 | | -```HTML |
43 | | -<!DOCTYPE html> |
44 | | -<html> |
45 | | - <head> |
46 | | - <title>Sample Code</title> |
47 | | - <meta charset="utf-8"> |
48 | | - </head> |
49 | | - <body> |
50 | | - <div class="content"> |
51 | | - <a onclick="login()">Login</a> |
52 | | - <br/> |
53 | | - <a onclick="getGuestToken()">Get a guest token</a> |
54 | | - </div> |
55 | | - |
56 | | - <script type="text/javascript" src="//code.spark.autodesk.com/autodesk-spark-sdk.min.js"></script> |
57 | | - <script> |
58 | | - //Optional - Provide options |
59 | | - var options = { |
60 | | - isProduction:false, //(Optional - true/false) Whether we work in production or sandbox environment - default is sandbox |
61 | | - redirectUri: 'http://localhost/webapp-samples/plugins/login/login-callback.html',// (Optional) The redirect URI for the auth service (i.e. http://example.com/callback), in cases where it is different than the one that was set for your app's Callback URL |
62 | | - guestTokenUrl: '',//(Optional) The server URL to which guest token requests will be directed, for example http://example.com/guest_token. |
63 | | - accessTokenUrl: '',//(Optional) The server URL to which access token requests will be directed, for example http://example.com/access_token. |
64 | | - refreshTokenUrl: ''//(Optional) The server URL to which refresh access token requests will be directed. |
65 | | - }; |
66 | | -
|
67 | | -
|
68 | | - ADSKSpark.Client.initialize('<your app key>',options); |
69 | | -
|
70 | | - /** |
71 | | - * Open login window |
72 | | - */ |
73 | | - function login() { |
74 | | - ADSKSpark.Client.openLoginWindow(); |
75 | | - } |
76 | | -
|
77 | | - function logout(){ |
78 | | - ADSKSpark.Client.logout(); |
79 | | - location.reload(); |
80 | | - } |
81 | | -
|
82 | | - function getGuestToken(){ |
83 | | - ADSKSpark.Client.getGuestToken().then(function(guestToken) { |
84 | | - console.log('guest token: ',guestToken); |
85 | | - }); |
86 | | - } |
87 | | -
|
88 | | -
|
89 | | - if (ADSKSpark.Client.isAccessTokenValid()) { |
90 | | - console.log('access token: ',ADSKSpark.Client.getAccessToken()); |
91 | | - ADSKSpark.Members.getMyProfile().then(function(response){ |
92 | | - console.log('Current logged in member is: ', response.member); |
93 | | - }); |
94 | | - } |
95 | | -
|
96 | | - </script> |
97 | | - </body> |
98 | | -</html> |
99 | | -``` |
100 | | - |
101 | | -A server side authentication process, fetching an access_token and guest_token, is required |
102 | | -for your application to work. You can utilize one of the server implementations that are supplied in this repository. |
| 14 | +Copy the file "assets/scripts/config.example.js" to "assets/scripts/config.js" and supply these details: |
| 15 | + # **APP_KEY** - paste the app key from step 4 in the previous section |
| 16 | + # **REDIRECT_URI** - The redirect uri the Spark Auth flow will redirect your users after they will complete the login process. |
| 17 | + This repository is provided with a login callback html file that makes this task easy. |
| 18 | + The file is located in "plugins/login/login-callback.html" and you should set your REDIRECT_URI to http://example.com/your-app/plugins/login/login-callback.html |
| 19 | + (assumed the home page of your app is http://example.com/your-app) |
| 20 | + |
| 21 | +### The contents of this repository |
| 22 | +This repository demonstrates sample usages of Spark APIs through these samples: |
| 23 | +1. 3D Models Healing Utility For Printing (healing-utility.html) - Assists in improving 3D printing success rates and minimize printing time with our extensive range of API print-preparation tools. Heal, fix and optimize your model for different materials, textures and file output types. |
| 24 | +2. 3D Models Printing Sample Application (sample-app-print.html) - Shows how to integrate an app with local and network 3D printers, desktop FDM printers and professional grade additive manufacturing systems. |
| 25 | +3. 3D Models Cloud Storage Application (sample-app-storage.html) - Uses Spark's cloud services to easily store 3D models and to create collaborative shared 3D creations. |
| 26 | +4. Public 3D Models Social Application (sample-app-gallery.html) - Demonstrates an online gallery, exhibits app-users' 3D image and digital creations and add social network functions, such as comments and likes. |
| 27 | + |
| 28 | +### Using the SDK |
| 29 | +The samples provided in this repository utilize Spark's JavaScript SDK that is provided through [this link](https://code.spark.autodesk.com/autodesk-spark-sdk.min.js). |
| 30 | + |
| 31 | +To run your own code with the SDK, reference the [JS SDK repository](https://github.com/spark3dp/spark-js-SDK). |
0 commit comments