forked from pump-io/pump.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Data type for storing credentials for a remote system
Store the OAuth credentials for a remote system for a user.
- Loading branch information
Evan Prodromou
committed
Sep 14, 2012
1 parent
e9f92a8
commit 5538271
Showing
3 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Credentials for a remote system | ||
// | ||
// Copyright 2012 StatusNet Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
var databank = require("databank"), | ||
Stamper = require("../stamper").Stamper, | ||
_ = require("underscore"), | ||
DatabankObject = databank.DatabankObject, | ||
NoSuchThingError = databank.NoSuchThingError; | ||
|
||
var Credentials = DatabankObject.subClass("credentials"); | ||
|
||
Credentials.schema = { | ||
pkey: "host_and_id", | ||
fields: ["host", | ||
"id", | ||
"client_id", | ||
"client_secret", | ||
"expires_at", | ||
"created", | ||
"updated"], | ||
indices: ["host", "id", "client_id"] | ||
}; | ||
|
||
Credentials.beforeCreate = function(props, callback) { | ||
props.created = props.updated = Stamper.stamp(); | ||
callback(null, props); | ||
}; | ||
|
||
Credentials.prototype.beforeUpdate = function(props, callback) { | ||
props.updated = Stamper.stamp(); | ||
callback(null, props); | ||
}; | ||
|
||
exports.Credentials = Credentials; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// credentials-test.js | ||
// | ||
// Test the credentials module | ||
// | ||
// Copyright 2012, StatusNet Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
var assert = require("assert"), | ||
vows = require("vows"), | ||
databank = require("databank"), | ||
Step = require("step"), | ||
URLMaker = require("../lib/urlmaker").URLMaker, | ||
modelBatch = require("./lib/model").modelBatch, | ||
Databank = databank.Databank, | ||
DatabankObject = databank.DatabankObject; | ||
|
||
var suite = vows.describe("credentials module interface"); | ||
|
||
var testSchema = { | ||
pkey: "host_and_id", | ||
fields: ["host", | ||
"id", | ||
"client_id", | ||
"client_secret", | ||
"expires_at", | ||
"created", | ||
"updated"], | ||
indices: ["host", "id", "client_id"] | ||
}; | ||
|
||
var testData = { | ||
"create": { | ||
host: "social.example", | ||
id: "acct:user@comment.example", | ||
client_id: "AAAAAA", | ||
client_secret: "123456", | ||
expires_at: 0 | ||
}, | ||
"update": { | ||
expires_at: 1 | ||
} | ||
}; | ||
|
||
var mb = modelBatch("credentials", "Credentials", testSchema, testData); | ||
|
||
mb["When we require the credentials module"] | ||
["and we get its Credentials class export"] | ||
["and we create a credentials instance"] | ||
["auto-generated fields are there"] = function(err, created) { | ||
assert.isString(created.created); | ||
assert.isString(created.updated); | ||
}; | ||
|
||
suite.addBatch(mb); | ||
|
||
suite["export"](module); |