auth 0.0.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +19 -162
- package/index.js +75 -0
- package/package.json +22 -27
- package/.cupboard +0 -2
- package/.npmignore +0 -2
- package/browser/account.js +0 -70
- package/browser/index.js +0 -13
- package/docs/issues.md +0 -4
- package/docs/pseudo-1.js +0 -19
- package/examples/ex1.js +0 -72
- package/examples/ex2.js +0 -62
- package/examples/models.js +0 -17
- package/examples/plugin-1.js +0 -14
- package/examples/pseduo.js +0 -6
- package/examples/pseudo-2.js +0 -2
- package/examples/pseudo-3.js +0 -61
- package/lib/access.js +0 -18
- package/lib/http/middleware/index.js +0 -31
- package/lib/http/routes/index.js +0 -152
- package/lib/http/routes/lostPassword.js +0 -121
- package/lib/http/routes/reqOutcome.js +0 -10
- package/lib/index.js +0 -65
- package/lib/mixin/ownableModel.js +0 -118
- package/lib/models/account.js +0 -281
- package/lib/models/lostPassword.js +0 -28
- package/lib/models/token.js +0 -298
- package/models.md +0 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Auth.js
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,175 +1,32 @@
|
|
|
1
|
+
# Auth.js CLI
|
|
1
2
|
|
|
3
|
+
The CLI tool by [Auth.js](https://authjs.dev) to supercharge your authentication workflow.
|
|
2
4
|
|
|
3
|
-
##
|
|
5
|
+
## Installation
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
- creating account tokens with access to specific collections & items
|
|
7
|
-
- used for locking down public access to certain features.
|
|
8
|
-
- ability to add expiration for tokens
|
|
9
|
-
-
|
|
7
|
+
You don't need to install this package, run any of the following commands:
|
|
10
8
|
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
var mongoose = require("mongoose"),
|
|
14
|
-
step = require("step"),
|
|
15
|
-
Schema = mongoose.Schema,
|
|
16
|
-
ObjectId = Schema.Types.ObjectId;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var auth = require("auth").connect({
|
|
20
|
-
connection: mongoose.createConnection("mongodb://localhost/auth-test")
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
var Post = new Schema({
|
|
24
|
-
message: String
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
//make the post ownable
|
|
28
|
-
Post.plugin(auth.ownable);
|
|
29
|
-
|
|
30
|
-
step(
|
|
31
|
-
function() {
|
|
32
|
-
auth.signup({ email: "me@email.com", password: "password" }, this);
|
|
33
|
-
},
|
|
34
|
-
function(err, account) {
|
|
35
|
-
this.account = account;
|
|
36
|
-
var post = new Post({
|
|
37
|
-
message: "Hello World!"
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
//make the account OWN the post
|
|
41
|
-
account.own(post);
|
|
42
|
-
|
|
43
|
-
post.save(this);
|
|
44
|
-
},
|
|
45
|
-
function() {
|
|
46
|
-
Post.find(this.account.ownQuery(), this);
|
|
47
|
-
},
|
|
48
|
-
function(err, post) {
|
|
49
|
-
console.log(post.message); //Hello World!
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
## auth API
|
|
56
|
-
|
|
57
|
-
### auth auth.connect(options)
|
|
58
|
-
|
|
59
|
-
- options
|
|
60
|
-
`connection` - mongodb connection
|
|
61
|
-
|
|
62
|
-
### auth.Account.signup(account, onCreated)
|
|
63
|
-
|
|
64
|
-
creates a new user
|
|
65
|
-
|
|
66
|
-
### auth.Account.login(credentals, onLogin)
|
|
67
|
-
|
|
68
|
-
Logs the user in with u/p, or a token
|
|
69
|
-
|
|
70
|
-
Example:
|
|
71
|
-
|
|
72
|
-
```javascript
|
|
73
|
-
auth.Account.login({ token: tokenKey }, onLogin);
|
|
74
|
-
auth.Account.login({ email: "email", password: "password" }, onLogin);
|
|
9
|
+
```sh
|
|
10
|
+
npx auth
|
|
75
11
|
```
|
|
76
12
|
|
|
77
|
-
##
|
|
13
|
+
## Usage
|
|
78
14
|
|
|
79
|
-
|
|
15
|
+
<!-- TODO: Generate by running `node index.js --help` and writing this -->
|
|
80
16
|
|
|
81
|
-
|
|
17
|
+
```sh
|
|
18
|
+
Usage: auth [options] [command]
|
|
82
19
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
console.log(token.ttl); // -1 = no expiration date.
|
|
87
|
-
console.log(token.scope); //[ { collectionName: null, item: null, access: ["GET", "POST", "PUT", "DELETE", "SUPER"]}]
|
|
88
|
-
})
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### account.createToken(options, callback)
|
|
92
|
-
|
|
93
|
-
- `options` - options for the token
|
|
94
|
-
- `item` - the item to grant access to (optional)
|
|
95
|
-
- `collectionName` - the collection
|
|
96
|
-
- `ttl` - time in MS for expiration
|
|
97
|
-
- `access` - (array) scope access. default is `access.all()`
|
|
20
|
+
Options:
|
|
21
|
+
-V, --version output the version number
|
|
22
|
+
-h, --help display help for command
|
|
98
23
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
console.log(token.scope); //[ { collectionName: "posts", item: null, access: ["GET"]}]
|
|
104
|
-
});
|
|
24
|
+
Commands:
|
|
25
|
+
secret [options] Generate a random string.
|
|
26
|
+
framework [framework] Clone a framework template.
|
|
27
|
+
help [command] display help for command
|
|
105
28
|
```
|
|
106
29
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
makes the account an owner of an item with SUPER privileges on item
|
|
110
|
-
|
|
111
|
-
```javascript
|
|
112
|
-
var p = new Post({ message: "hello!" });
|
|
113
|
-
user.ownItem(p);
|
|
114
|
-
p.save();
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### account.shareItem(item, access)
|
|
118
|
-
|
|
119
|
-
Shares an item with another user
|
|
120
|
-
|
|
121
|
-
- `item` - item to own
|
|
122
|
-
- `access` - access level for the given item. Blank = ALL privileges.
|
|
123
|
-
|
|
124
|
-
```javascript
|
|
125
|
-
var access = require("auth").access;
|
|
126
|
-
Post.findOne({message:"hello!"}, function(err, post) {
|
|
127
|
-
user2.shareItem(post, [access.GET]); //ability to only see item
|
|
128
|
-
post.save();
|
|
129
|
-
});
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### account.authorized(item, access)
|
|
133
|
-
|
|
134
|
-
returns TRUE if the account has access to the item. Note that the result can be variable
|
|
135
|
-
depending if whether the given user logs in with a restricted login token. See below.
|
|
136
|
-
|
|
137
|
-
```javascript
|
|
138
|
-
|
|
139
|
-
//logged
|
|
140
|
-
user2.authorized(post); //TRUE
|
|
141
|
-
user2.authorized(post, [access.POST]); //FALSE
|
|
142
|
-
user2.authorized(post, [access.GET]); //TRUE
|
|
143
|
-
user2.authorized(post, [access.GET, access.POST]); //TRUE
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
//login with the post owner, but restrict access with the created
|
|
147
|
-
//token above.
|
|
148
|
-
User.login({ token: aboveTokenKey }, function(err, user) {
|
|
149
|
-
user.authorized(post, [access.TRUE]); //FALSE
|
|
150
|
-
user.authorized(post, [access.POST]); //FALSE
|
|
151
|
-
})
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### Error account.unauthorized(callback)
|
|
155
|
-
|
|
156
|
-
Tiny flow-control utility.
|
|
157
|
-
|
|
158
|
-
### account.addToSearch(query)
|
|
159
|
-
|
|
160
|
-
adds account to the given search. For example:
|
|
161
|
-
|
|
162
|
-
```javascript
|
|
163
|
-
|
|
164
|
-
Post.findOne(user.addToSearch(), function(err, post) {
|
|
165
|
-
user.authorized(post); //TRUE
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
## TODO
|
|
30
|
+
## Acknowledgements
|
|
169
31
|
|
|
170
|
-
|
|
171
|
-
- sharing whole collections (job & timer)
|
|
172
|
-
- custom authentication schema
|
|
173
|
-
- validation of credentials (email/pass)
|
|
174
|
-
- Auth.lockdown - prevent models from being saved or serialized if unauthorized
|
|
175
|
-
- hooks with [passport](https://github.com/jaredhanson/passport)
|
|
32
|
+
Special thanks to Craig for the `auth` package name on npm.
|
package/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { InvalidArgumentError } from "commander"
|
|
2
|
+
import { Command } from "commander"
|
|
3
|
+
// import pkg from "./package.json" assert { type: "json" }
|
|
4
|
+
|
|
5
|
+
import fs from "fs/promises"
|
|
6
|
+
const pkg = JSON.parse(await fs.readFile("./package.json"))
|
|
7
|
+
const { name, description, version } = pkg
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
// TODO: Remove when Node.js 18 is not maintained anymore
|
|
11
|
+
globalThis.crypto ??= (await import("crypto")).webcrypto
|
|
12
|
+
} catch {}
|
|
13
|
+
|
|
14
|
+
/** Web compatible method to create a random string of a given length */
|
|
15
|
+
export function randomString(size = 32) {
|
|
16
|
+
const bytes = crypto.getRandomValues(new Uint8Array(size))
|
|
17
|
+
return Buffer.from(bytes, "base64").toString("base64")
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const program = new Command()
|
|
21
|
+
|
|
22
|
+
program.name(name).description(description).version(version)
|
|
23
|
+
|
|
24
|
+
program
|
|
25
|
+
.command("secret")
|
|
26
|
+
.option("--raw", "Output the string without any formatting.")
|
|
27
|
+
.description("Generate a random string.")
|
|
28
|
+
.action((options) => {
|
|
29
|
+
const value = randomString()
|
|
30
|
+
if (options.raw) return console.log(value)
|
|
31
|
+
// TODO: Detect framework, check for existing value, and write automatically
|
|
32
|
+
console.log(`
|
|
33
|
+
Secret generated. Copy it to your .env/.env.local file (depending on your framework):
|
|
34
|
+
|
|
35
|
+
AUTH_SECRET=${value}`)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// TODO: Get this programmatically
|
|
39
|
+
const frameworks = {
|
|
40
|
+
nextjs: {
|
|
41
|
+
src: "https://github.com/nextauthjs/next-auth-example",
|
|
42
|
+
demo: "https://next-auth-example.vercel.app",
|
|
43
|
+
},
|
|
44
|
+
sveltekit: {
|
|
45
|
+
src: "https://github.com/nextauthjs/sveltekit-auth-example",
|
|
46
|
+
demo: "https://sveltekit-auth-example.vercel.app",
|
|
47
|
+
},
|
|
48
|
+
express: {
|
|
49
|
+
src: "https://github.com/nextauthjs/express-auth-example",
|
|
50
|
+
demo: "https://express-auth-example.vercel.app",
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
program
|
|
55
|
+
.command("framework")
|
|
56
|
+
.argument("[framework]", "The framework to use.", (value) => {
|
|
57
|
+
if (!value) return value
|
|
58
|
+
if (Object.keys(frameworks).includes(value)) return value
|
|
59
|
+
throw new InvalidArgumentError(
|
|
60
|
+
`Valid frameworks are: ${supportedFrameworks.join(", ")}`
|
|
61
|
+
)
|
|
62
|
+
})
|
|
63
|
+
.description("Clone a framework template.")
|
|
64
|
+
.action((framework) => {
|
|
65
|
+
if (!framework) {
|
|
66
|
+
return console.log(`
|
|
67
|
+
Supported frameworks are: ${Object.keys(frameworks).join(", ")}`)
|
|
68
|
+
}
|
|
69
|
+
const { src, demo } = frameworks[framework]
|
|
70
|
+
console.log(`
|
|
71
|
+
Source code: ${src}
|
|
72
|
+
Deployed demo: ${demo}`)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
program.parse(process.argv)
|
package/package.json
CHANGED
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auth",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
3
|
+
"description": "The CLI tool by Auth.js to supercharge your authentication workflow.",
|
|
4
|
+
"homepage": "https://cli.authjs.dev",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"auth": "index.js"
|
|
8
9
|
},
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
"files": [
|
|
11
|
+
"*.d.ts*",
|
|
12
|
+
"*.js",
|
|
13
|
+
"lib",
|
|
14
|
+
"src"
|
|
15
|
+
],
|
|
16
|
+
"keywords": [
|
|
17
|
+
"authjs",
|
|
18
|
+
"cli"
|
|
19
|
+
],
|
|
20
|
+
"author": "Balázs Orbán <info@balazsorban.com>",
|
|
21
|
+
"license": "MIT",
|
|
15
22
|
"dependencies": {
|
|
16
|
-
"
|
|
17
|
-
"step": "0.0.x",
|
|
18
|
-
"structr": "0.2.x",
|
|
19
|
-
"underscore": "1.4.x",
|
|
20
|
-
"dsync": "0.0.x",
|
|
21
|
-
"vine": "0.1.x",
|
|
22
|
-
"dustjs-linkedin": "1.1.x",
|
|
23
|
-
"seq": "0.3.x",
|
|
24
|
-
"comerr": "0.0.x",
|
|
25
|
-
"verify": "0.0.x"
|
|
23
|
+
"commander": "11.1.0"
|
|
26
24
|
},
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
"plugin": "*",
|
|
30
|
-
"plugin-express": "0.0.x",
|
|
31
|
-
"plugin-mongodb": "0.0.x"
|
|
25
|
+
"prettier": {
|
|
26
|
+
"semi": false
|
|
32
27
|
}
|
|
33
|
-
}
|
|
28
|
+
}
|
package/.cupboard
DELETED
package/.npmignore
DELETED
package/browser/account.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
var structr = require("structr"),
|
|
2
|
-
_ = require("underscore");
|
|
3
|
-
|
|
4
|
-
exports.connect = function(host) {
|
|
5
|
-
|
|
6
|
-
var host = window.location.protocol + "//" + window.location.host;
|
|
7
|
-
|
|
8
|
-
if(window.location.port && String(window.location.port).length > 0) {
|
|
9
|
-
host += ":" + window.location.port;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var Account;
|
|
15
|
-
return Account = structr({
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
"__construct": function(data) {
|
|
21
|
-
_.extend(this, data);
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
"save": function() {
|
|
28
|
-
//TODO
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
"static login": function(data, onLogin) {
|
|
35
|
-
|
|
36
|
-
if(arguments.length == 1) {
|
|
37
|
-
onLogin = data;
|
|
38
|
-
data = {};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
$.ajax({
|
|
42
|
-
type: "GET",
|
|
43
|
-
data: data,
|
|
44
|
-
url: host + "/account.json",
|
|
45
|
-
success: function(resp) {
|
|
46
|
-
if(resp.errors) return onLogin(resp.errors);
|
|
47
|
-
onLogin(null, new Account(resp.result));
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
"static signup": function(data, onSignup) {
|
|
57
|
-
$.ajax({
|
|
58
|
-
type: "POST",
|
|
59
|
-
data: data,
|
|
60
|
-
url: host + "/account.json",
|
|
61
|
-
success: function(resp) {
|
|
62
|
-
if(resp.errors) return onLogin(resp.errors);
|
|
63
|
-
onLogin(null, new Account(resp.result));
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
package/browser/index.js
DELETED
package/docs/issues.md
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
- How do we make sure that users are the owner's of particular documents?
|
|
2
|
-
- How do we do this efficiently?
|
|
3
|
-
- How do we grant privileges for documents without writing a ton of code for each sharable collection?
|
|
4
|
-
- timer that checks for privileges to grant & remove at set intervals
|
package/docs/pseudo-1.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
var auth = require("auth").init({
|
|
2
|
-
collections: {
|
|
3
|
-
profile: "profile",
|
|
4
|
-
sessions: "session",
|
|
5
|
-
friends: "friends"
|
|
6
|
-
},
|
|
7
|
-
connection: dbconnection
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
auth.collections.register("friends");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var profile = auth.signup()
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
package/examples/ex1.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
var mongoose = require("mongoose"),
|
|
2
|
-
step = require("step"),
|
|
3
|
-
outcome = require("outcome");
|
|
4
|
-
|
|
5
|
-
var auth = require("../").init({
|
|
6
|
-
connection: mongoose.connect("mongodb://localhost:27017/auth")
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
auth.connection.model("friends", new mongoose.Schema({
|
|
11
|
-
name: String,
|
|
12
|
-
last: String
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
auth.sharedCollections.add("friends");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var on = outcome.error(function(err) {
|
|
20
|
-
console.error(err.stack);
|
|
21
|
-
}),
|
|
22
|
-
user,
|
|
23
|
-
user2;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
step(
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
function() {
|
|
35
|
-
auth.signup({ username: "craig", email: "craig.j.condon@gmail.com", password: "test" }, this);
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
on.success(function(data) {
|
|
42
|
-
user = data.user;
|
|
43
|
-
auth.signup({ username: "john", email: "craig.j.condon+test@gmail.com", password: "test"}, this);
|
|
44
|
-
}),
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
on.success(function(data) {
|
|
50
|
-
user2 = data.user;
|
|
51
|
-
|
|
52
|
-
//thrown into a job
|
|
53
|
-
user.grantPermission(user2, ["*:friends"]);
|
|
54
|
-
|
|
55
|
-
//wait for permissions to be granted
|
|
56
|
-
auth.worker.once("grant", this);
|
|
57
|
-
}),
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
*/
|
|
61
|
-
|
|
62
|
-
on.success(function() {
|
|
63
|
-
auth.sandbox("*:friends").login({ username: "john", password: "test" }, this);
|
|
64
|
-
}),
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
on.success(function(data) {
|
|
70
|
-
console.log(data.token.scopes);
|
|
71
|
-
})
|
|
72
|
-
);
|
package/examples/ex2.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
var step = require("step"),
|
|
2
|
-
mongoose = require("mongoose");
|
|
3
|
-
|
|
4
|
-
require("./models");
|
|
5
|
-
|
|
6
|
-
var auth = require("../").connect({
|
|
7
|
-
connection: mongoose.createConnection("mongodb://localhost/auth-test")
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
var user1, user2, post, Post = auth.connection.model("posts");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
step(
|
|
14
|
-
function() {
|
|
15
|
-
console.log("u1");
|
|
16
|
-
auth.signup({ email: "me@email.com", password: "password" }, this);
|
|
17
|
-
},
|
|
18
|
-
function(err, u1) {
|
|
19
|
-
user1 = u1;
|
|
20
|
-
console.log("u2");
|
|
21
|
-
auth.signup({ email: "me@email2.com", password: "password" }, this);
|
|
22
|
-
},
|
|
23
|
-
function(err, u2) {
|
|
24
|
-
user2 = u2;
|
|
25
|
-
if(err) consoe.log(err.stack)
|
|
26
|
-
post = new Post({title:"test", message:"hello"});
|
|
27
|
-
user1.ownItem(post);
|
|
28
|
-
post.save(this);
|
|
29
|
-
},
|
|
30
|
-
function(err) {
|
|
31
|
-
if(err) consoe.log(err.stack)
|
|
32
|
-
Post.findOne(user1.addToSearch(), this);
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
function(err, p) {
|
|
36
|
-
post = p;
|
|
37
|
-
|
|
38
|
-
if(!user1.hasItemAccess(p)) return user1.unauthorized(this);
|
|
39
|
-
|
|
40
|
-
user2.lockdownItem(p);
|
|
41
|
-
console.log(JSON.stringify(p))
|
|
42
|
-
|
|
43
|
-
//share with my friend
|
|
44
|
-
user2.shareItem(p);
|
|
45
|
-
p.save(this);
|
|
46
|
-
},
|
|
47
|
-
function(err) {
|
|
48
|
-
console.log(err)
|
|
49
|
-
post.fetchOwner(this);
|
|
50
|
-
},
|
|
51
|
-
function(err, u) {
|
|
52
|
-
console.log(err);
|
|
53
|
-
user1 = u;
|
|
54
|
-
this();
|
|
55
|
-
},
|
|
56
|
-
function(err) {
|
|
57
|
-
console.log(err);
|
|
58
|
-
user1.remove();
|
|
59
|
-
user2.remove();
|
|
60
|
-
}
|
|
61
|
-
)
|
|
62
|
-
|
package/examples/models.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
var mongoose = require("mongoose"),
|
|
2
|
-
auth = require("../"),
|
|
3
|
-
Schema = mongoose.Schema;
|
|
4
|
-
|
|
5
|
-
exports.Comment = new Schema({
|
|
6
|
-
message: String
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
exports.Post = new Schema({
|
|
10
|
-
title: String,
|
|
11
|
-
message: String,
|
|
12
|
-
comments: [exports.Comment]
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
exports.Post.plugin(auth.ownable);
|
|
17
|
-
mongoose.model("posts", exports.Post);
|
package/examples/plugin-1.js
DELETED
package/examples/pseduo.js
DELETED
package/examples/pseudo-2.js
DELETED