Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set consumer key in external config vars #2

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b5e713d
edit gitignore to include credentials
duchangyu May 7, 2015
1d3dfc3
add credential.js
duchangyu May 7, 2015
82b66be
a running version
duchangyu May 7, 2015
002447a
merge from master for the latest changes
duchangyu May 7, 2015
60d0d86
add credential keys
duchangyu May 7, 2015
357752a
another minor change
duchangyu May 7, 2015
b3a0336
use conf vars
duchangyu May 7, 2015
a31a52e
bug fix
duchangyu May 7, 2015
50f6deb
bug fix
duchangyu May 7, 2015
552f4b0
bug fix
duchangyu May 7, 2015
140583f
bug fix
duchangyu May 7, 2015
c5011aa
clean up
duchangyu May 7, 2015
d400c54
credential at run time
duchangyu May 7, 2015
a086d06
update readme
duchangyu May 7, 2015
494f36a
Update run.bat
duchangyu May 7, 2015
44a6a5b
Update README.md
duchangyu May 7, 2015
4e0bad4
Update README.md
duchangyu May 7, 2015
803fe07
Update README.md
duchangyu May 7, 2015
2e31662
update readme
duchangyu May 8, 2015
c347374
update readme formating
duchangyu May 8, 2015
38d9a43
formating
duchangyu May 8, 2015
4bb6945
formating
duchangyu May 8, 2015
8b9ccd0
formarting
duchangyu May 8, 2015
70447da
formating
duchangyu May 8, 2015
fc7ffb9
formating
duchangyu May 8, 2015
ece0b66
renaming
duchangyu May 8, 2015
849a8e6
edit gitignore
duchangyu May 11, 2015
469c106
secure token
duchangyu May 11, 2015
77e71e9
hardcode host
duchangyu May 11, 2015
04e2632
registric
duchangyu May 11, 2015
ee0ee16
restrict host
duchangyu May 11, 2015
10784ce
update
duchangyu May 11, 2015
1c1da0d
token restriction
duchangyu May 11, 2015
2be1235
add cors preflight
duchangyu May 12, 2015
53a1f5f
add cors
duchangyu May 12, 2015
80347ed
add travis cI
duchangyu May 12, 2015
8d74721
update
duchangyu May 12, 2015
89d7a5a
update travis.yml
duchangyu May 12, 2015
ac1ce0d
update readme
duchangyu May 12, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ node_modules
.lock-wscript

# API credentials file
credentials.js
run.bat
run.sh

# webstorm project files
.idea
credentials_.js

6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- "0.12"
- "0.11"
- "0.10"

12 changes: 1 addition & 11 deletions README-option.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,7 @@ get model URNs - as explained in the Setup/Usage Instructions.

## Setup/Usage Instructions

* From the sample root folder, rename or copy the ./credentials_.js file into ./credentials.js <br />
* Windows <br />
```
copy credentials_.js credentials.js
```
* OSX/Linux <br />
```
cp credentials_.js credentials.js
```
* The [upload tool](http://still-spire-1606.herokuapp.com) provides some existing models. Choose any one of them, or upload one of your own
models with [upload tool](http://still-spire-1606.herokuapp.com). The [upload tool](http://still-spire-1606.herokuapp.com) will generate a URN of the model that you need later.
* The [upload tool](http://still-spire-1606.herokuapp.com) provides some existing models. Choose any one of them, or upload one of your own models with [upload tool](http://still-spire-1606.herokuapp.com). The [upload tool](http://still-spire-1606.herokuapp.com) will generate a URN of the model that you need later.
* Copy the URN which was generated in the previous step in file /www/index.js at line #18 <br />
```
var defaultUrn = '<replace with your encoded urn>';
Expand Down
43 changes: 22 additions & 21 deletions README-stg.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,21 @@ get model URNs - as explained in the Setup/Usage Instructions.
## Setup/Usage Instructions

* Apply for your own credentials (API keys) from [http://developer-stg.autodesk.com](http://developer-stg.autodesk.com)
* From the sample root folder, rename or copy the ./credentials_.js file into ./credentials.js <br />
* Windows <br />
```
copy credentials_.js credentials.js
```
* OSX/Linux <br />
```
cp credentials_.js credentials.js
```
* Replace the placeholder with your own keys in credentials.js, line #23 and #24 <br />
```
credentials.ClientId = '<replace with your consumer key>';

credentials.ClientSecret = '<replace with your consumer secret>';
```
* In file credentials.js line #26, replace the BaseUrl address by the staging server address <br />
* Replace the placeholder with your own keys in run.sh(for Mac/Linux) or run.bat(for Windows),

```
credentials.BaseUrl = 'https://developer-stg.api.autodesk.com' ;
ConsumerKey=replace_with_your_consumer_key \
ConsumerSecret=replace_with_your_secret_key \
BaseUrl=https://developer-stg.api.autodesk.com \
node server.js
```

* Upload one of your models to your account and get its URN using another workflow sample, for example,
- [this workflow sample in .Net WPF application](https://github.com/Developer-Autodesk/workflow-wpf-view.and.data.api) if you are using windows
- or [this workflow sample in Mac OS Swift](https://github.com/Developer-Autodesk/workflow-macos-swift-view.and.data.api) if you are using Mac
- or this [WEB page](http://javalmvwalkthrough-vq2mmximxb.elasticbeanstalk.com/)
- or [this workflow sample in Mac OS Swift](https://github.com/Developer-Autodesk/workflow-macos-swift-view.and.data.api) if you are using Mac.

Please note that you also need to change the base url to https://developer-stg.api.autodesk.com and replace your consumer key and secret on staging.

* Copy the URN which was generated in the previous step in file /www/index.js at line #18 <br />
```
var defaultUrn = '<replace with your encoded urn>';
Expand All @@ -68,10 +60,19 @@ get model URNs - as explained in the Setup/Usage Instructions.
<script src="https://developer-stg.api.autodesk.com/viewingservice/v1/viewers/viewer3D.min.js"></script>
```
* In file /www/index.js, comment out line #23, and uncomment line #24
* Run the server from the Node.js console, by running the following command: <br />
* Run the server from the Node.js console, by running the following command(For Mac):

```
$ chmod +x run.sh
$ ./run.sh
```

For windows, run the "run.bat" from command window

```
node server.js
run.bat
```

* Connect to you local server using a WebGL-compatible browser: [http://localhost:3000/](http://localhost:3000/)


Expand Down
48 changes: 27 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Autodesk View and Data API Node.js Basic Sample

[![build status](https://api.travis-ci.org/duchangyu/workflow-node.js-view.and.data.api.png)](https://api.travis-ci.org/duchangyu/workflow-node.js-view.and.data.api)



## Description
A sample demonstrating how to view a model in a web application with the Autodesk View & Data API. This web application has a basic Node.js
Expand All @@ -25,32 +28,35 @@ get model URNs - as explained in the Setup/Usage Instructions.
## Setup/Usage Instructions

* Apply for your own credentials (API keys) from [http://developer.autodesk.com](http://developer.autodesk.com)
* From the sample root folder, rename or copy the ./credentials_.js file into ./credentials.js <br />
* Windows <br />
```
copy credentials_.js credentials.js
```
* OSX/Linux <br />
```
cp credentials_.js credentials.js
```
* Replace the placeholder with your own keys in credentials.js, line #23 and #24 <br />

* Replace the placeholder with your own keys in run.sh(for Mac/Linux) or run.bat(for Windows),

```
credentials.ClientId = '<replace with your consumer key>';

credentials.ClientSecret = '<replace with your consumer secret>';
ConsumerKey=replace_with_your_consumer_key \
ConsumerSecret=replace_with_your_secret_key \
BaseUrl=https://developer.api.autodesk.com \
node server.js
```
* Upload one of your models to your account and get its URN using another workflow sample, for example,
- [this workflow sample in .Net WPF application](https://github.com/Developer-Autodesk/workflow-wpf-view.and.data.api) if you are using windows
- or [this workflow sample in Mac OS Swift](https://github.com/Developer-Autodesk/workflow-macos-swift-view.and.data.api) if you are using Mac
- or this [WEB page](http://javalmvwalkthrough-vq2mmximxb.elasticbeanstalk.com/)
* Copy the URN which was generated in the previous step in file /www/index.js at line #18 <br />
- or this [WEB page](http://models.autodesk.io)
* Copy the URN which was generated in the previous step in file /www/index.js at line #18

```
var defaultUrn = '<replace with your encoded urn>';
var defaultUrn = 'replace with your encoded urn';
```
* Run the server from the Node.js console, by running the following command: <br />
* Run the server from the Node.js console, by running the following command(For Mac):

```
$ chmod +x run.sh
$ ./run.sh
```

For windows, run the "run.bat" from command window

```
node server.js
run.bat
```
* Connect to you local server using a WebGL-compatible browser: [http://localhost:3000/](http://localhost:3000/)

Expand All @@ -62,12 +68,12 @@ By default, the project is setup with the production server, and use your own cr

You can work with production or staging Autodesk View and Data environments. By default, the project is setup with the production server.

* Instructions to setup this sample to use the Autodesk View & Data staging server are [here](https://github.com/Developer-Autodesk/workflow-node.js-view.and.data.api/blob/master/README-stg.md)
* Instructions to setup this sample to use the Autodesk View & Data staging server are [here](README-stg.md)


You can also use someone else credentials to view models using this sample.
If you are in a hurry, do not want to translate your own models, you can try our prepared models. You need use the access token generated from someone else credentials to view models using this sample.

* Instructions to setup this sample using someone else credentials are available [here](https://github.com/Developer-Autodesk/workflow-node.js-view.and.data.api/blob/master/README-option.md)
* Instructions to setup this sample using someone else credentials are available [here](README-option.md)


## License
Expand Down
29 changes: 0 additions & 29 deletions credentials_.js

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"serve-favicon": "*",
"stringstream": "0.0.4",
"tough-cookie": "^0.13.0",
"tunnel-agent": "^0.4.0"
"tunnel-agent": "^0.4.0",
"cors" : "*"
}
}
53 changes: 48 additions & 5 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,72 @@
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
/////////////////////////////////////////////////////////////////////////////////
var credentials = require('../credentials');

var express = require('express');
var request = require('request');

var router = express.Router();

var cors = require('cors');

var corsOptions = {
origin: 'http://secure-token.herokuapp.com'
};

router.get('/tokenadsk', function (req, res) {

//steals access token from http://secure-token.herokuapp.com
request('http://secure-token.herokuapp.com/api/token',
function (error, response, body) {
if (!error && response.statusCode == 200) {
res.send(body);
}
});
});



///////////////////////////////////////////////////////////////////////////////
// Generates access token
///////////////////////////////////////////////////////////////////////////////
router.get('/token', function (req, res) {
router.get('/token', cors(corsOptions),function (req, res) {
var params = {
client_id: credentials.ClientId,
client_secret: credentials.ClientSecret,
client_id: process.env.ConsumerKey ,
client_secret: process.env.ConsumerSecret,
grant_type: 'client_credentials'
}

// var thisHost = req.headers.refer;//req.protocol + '://' + req.get('host');
//var appHost = 'http://secure-token.herokuapp.com';

// if (thisHost != appHost) {
// var strMsg = ' request host: ' + thisHost;
// strMsg = strMsg + ' app host: ' + appHost;
// res.send('host restricted.' + strMsg);
// return;
// }


request.post(
credentials.BaseUrl + '/authentication/v1/authenticate',
process.env.BaseUrl + '/authentication/v1/authenticate',
{ form: params },

function (error, response, body) {
if (!error && response.statusCode == 200) {

// Website you wish to allow to connect
//res.setHeader('Access-Control-Allow-Origin', appHost);

// Request methods you wish to allow
//res.setHeader('Access-Control-Allow-Methods', 'GET');

// // Request headers you wish to allow
// res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');

// // Set to true if you need the website to include cookies in the requests sent
// // to the API (e.g. in case you use sessions)
// res.setHeader('Access-Control-Allow-Credentials', true);

res.send(body);
}
});
Expand Down
4 changes: 4 additions & 0 deletions run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set ConsumerKey=<replace_with_your_consummer_key>
set ConsumerSecret=<replace_with_your_secret_key>
set BaseUrl=https://developer.api.autodesk.com
node server.js
4 changes: 4 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ConsumerKey=VAgANZ4aiHITHoGeGLzv0oBtMAlFBeUa \
ConsumerSecret=9kfkcETJZI4Blre2 \
BaseUrl=https://developer.api.autodesk.com \
node server.js
3 changes: 3 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
/////////////////////////////////////////////////////////////////////////////////

var favicon = require('serve-favicon');
var api = require('./routes/api');
var express = require('express');
var cors = require('cors');

var app = express();

app.use('/', express.static(__dirname + '/www'));
app.use(favicon(__dirname + '/www/images/favicon.ico'));
app.use('/api', api);
app.use(cors);

app.set('port', process.env.PORT || 3000);

Expand Down
2 changes: 1 addition & 1 deletion www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
/////////////////////////////////////////////////////////////////////////////////
var defaultUrn = '<replace with your encoded urn>';
var defaultUrn = 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bW9kZWwyMDE1LTA1LTExLTA5LTE2LTEwLWdlN3B4aXNzNDF0eGRqdHhxa3R4eTN3MWc2emUvUm9ib3RBcm0uZHdmeA==';

$(document).ready(function () {
var tokenurl = 'http://' + window.location.host + '/api/token';
Expand Down