Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
Converted to hard tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Emily Rose committed Feb 28, 2015
1 parent bbcd1c4 commit a162b21
Show file tree
Hide file tree
Showing 15 changed files with 1,766 additions and 1,766 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ An API compatible open source server for interacting with devices speaking the [
<pre>
__ __ __ __ __ ____
/ /_/ /_ ___ / /___ _________ _/ / _____/ /___ __ ______/ / /
/ __/ __ \/ _ \ / / __ \/ ___/ __ `/ / / ___/ / __ \/ / / / __ / /
/ /_/ / / / __/ / / /_/ / /__/ /_/ / / / /__/ / /_/ / /_/ / /_/ /_/
\__/_/ /_/\___/ /_/\____/\___/\__,_/_/ \___/_/\____/\__,_/\__,_(_)
/ __/ __ \/ _ \ / / __ \/ ___/ __ `/ / / ___/ / __ \/ / / / __ / /
/ /_/ / / / __/ / / /_/ / /__/ /_/ / / / /__/ / /_/ / /_/ / /_/ /_/
\__/_/ /_/\___/ /_/\____/\___/\__,_/_/ \___/_/\____/\__,_/\__,_(_)
</pre>


Expand All @@ -28,7 +28,7 @@ node main.js
How do I get started?
=====================

1.) Run the server with:
1.) Run the server with:

```
node main.js
Expand All @@ -51,14 +51,14 @@ spark keys server default_key.pub.pem 192.168.1.10

Note! The CLI will turn your PEM file into a DER file, but you can also do that yourself with the command:
```
openssl rsa -in default_key.pem -pubin -pubout -outform DER -out default_key.der
openssl rsa -in default_key.pem -pubin -pubout -outform DER -out default_key.der
```

4.) Edit your Spark-CLI config file to point at your Spark-server. Open ~/.spark/spark.config.json in your favorite text editor, and add:

```
{
"apiUrl": "http://192.168.1.10:8080"
"apiUrl": "http://192.168.1.10:8080"
}
```
For beginners: note that you have to add in a `,` at the end of the previous line
Expand All @@ -69,20 +69,20 @@ For beginners: note that you have to add in a `,` at the end of the previous lin
6.) Create a user and login with the Spark-CLI

```
spark setup
spark setup
```

7.) Create and provision access on your local cloud with the keys doctor:

```
spark keys doctor your_core_id
spark keys doctor your_core_id
```


7.) See your connected cores!

```
spark list
spark list
```


Expand Down Expand Up @@ -156,10 +156,10 @@ What features will be added soon?
====================================

- Release a Core
DELETE /v1/devices/:coreid
DELETE /v1/devices/:coreid

- Claim a core
POST /v1/devices
POST /v1/devices

- per-user / per-core ownership and access restrictions. Right now ANY user on your local cloud can access ANY device.

Expand All @@ -169,8 +169,8 @@ What features will be added soon?
What API features are missing
================================

- the build IDE is not part of this release, but may be released separately later
- massive enterprise magic super horizontal scaling powers
- the build IDE is not part of this release, but may be released separately later
- massive enterprise magic super horizontal scaling powers


Known Limitations
Expand Down
124 changes: 62 additions & 62 deletions lib/AccessTokenViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,79 +25,79 @@ var PasswordHasher = require('./PasswordHasher.js');
var roles = require('./RolesController.js');

var AccessTokenViews = function (options) {
this.options = options;
this.options = options;
};

AccessTokenViews.prototype = {
loadViews: function (app) {
app.get('/v1/access_tokens', this.index.bind(this));
app.delete('/v1/access_tokens/:token', this.destroy.bind(this));
},
index: function (req, res) {
var credentials = AccessTokenViews.basicAuth(req);
if (!credentials) {
return res.json(401, {
ok: false,
errors: ["Unauthorized. You must send username and password in HTTP Basic Auth to view your access tokens."]
});
}
loadViews: function (app) {
app.get('/v1/access_tokens', this.index.bind(this));
app.delete('/v1/access_tokens/:token', this.destroy.bind(this));
},
index: function (req, res) {
var credentials = AccessTokenViews.basicAuth(req);
if (!credentials) {
return res.json(401, {
ok: false,
errors: ["Unauthorized. You must send username and password in HTTP Basic Auth to view your access tokens."]
});
}

//if successful, should return something like:
// [ { token: d.token, expires: d.expires, client: d.client_id } ]
//if successful, should return something like:
// [ { token: d.token, expires: d.expires, client: d.client_id } ]

when(roles.validateLogin(credentials.username, credentials.password))
.then(
function (userObj) {
res.json(userObj.access_tokens);
},
function () {
res.json(401, { ok: false, errors: ['Bad password']});
});
},
when(roles.validateLogin(credentials.username, credentials.password))
.then(
function (userObj) {
res.json(userObj.access_tokens);
},
function () {
res.json(401, { ok: false, errors: ['Bad password']});
});
},

destroy: function (req, res) {
var credentials = AccessTokenViews.basicAuth(req);
if (!credentials) {
return res.json(401, {
ok: false,
errors: ["Unauthorized. You must send username and password in HTTP Basic Auth to delete an access token."]
});
}
destroy: function (req, res) {
var credentials = AccessTokenViews.basicAuth(req);
if (!credentials) {
return res.json(401, {
ok: false,
errors: ["Unauthorized. You must send username and password in HTTP Basic Auth to delete an access token."]
});
}

when(roles.validateLogin(credentials.username, credentials.password))
.then(
function (userObj) {
try {
roles.destroyAccessToken(req.params.token);
res.json({ ok: true });
}
catch (ex) {
logger.error("error saving user " + ex);
res.json(401, { ok: false, errors: ['Error updating token']});
}
},
function () {
res.json(401, { ok: false, errors: ['Bad password']});
});
},
when(roles.validateLogin(credentials.username, credentials.password))
.then(
function (userObj) {
try {
roles.destroyAccessToken(req.params.token);
res.json({ ok: true });
}
catch (ex) {
logger.error("error saving user " + ex);
res.json(401, { ok: false, errors: ['Error updating token']});
}
},
function () {
res.json(401, { ok: false, errors: ['Bad password']});
});
},

basicAuth: function (req) {
var auth = req.get('Authorization');
if (!auth) return null;
basicAuth: function (req) {
var auth = req.get('Authorization');
if (!auth) return null;

var matches = auth.match(/Basic\s+(\S+)/);
if (!matches) return null;
var matches = auth.match(/Basic\s+(\S+)/);
if (!matches) return null;

var creds = new Buffer(matches[1], 'base64').toString();
var separatorIndex = creds.indexOf(':');
if (-1 === separatorIndex)
return null;
var creds = new Buffer(matches[1], 'base64').toString();
var separatorIndex = creds.indexOf(':');
if (-1 === separatorIndex)
return null;

return {
username: creds.slice(0, separatorIndex),
password: creds.slice(separatorIndex + 1)
};
}
return {
username: creds.slice(0, separatorIndex),
password: creds.slice(separatorIndex + 1)
};
}

};

Expand Down
Loading

0 comments on commit a162b21

Please sign in to comment.