auth 0.0.9 → 1.0.1

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 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
- ## Features
5
+ ## Installation
4
6
 
5
- - share items with multiple users
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
- ```javascript
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
- ## Account API
13
+ ## Usage
78
14
 
79
- ### account.getMainToken(callback)
15
+ <!-- TODO: Generate by running `node index.js --help` and writing this -->
80
16
 
81
- returns the main access token with super privileges. No restrictions to collections & items.
17
+ ```sh
18
+ Usage: auth [options] [command]
82
19
 
83
- ```javascript
84
- user.getMainToken(function(null, token) {
85
- console.log(token.key); //key used to login
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
- ```javascript
100
-
101
- //only give access to the posts collection, and only allow reading items
102
- user.createToken({ item: Posts.collection.name, access: [access.POST] }, function(err, token) {
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
- ### account.ownItem(item)
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
- - make sub-schemas ownable
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,78 @@
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
+ import { join } from "path"
7
+ import { fileURLToPath } from "url"
8
+ const __dirname = fileURLToPath(new URL(".", import.meta.url))
9
+ const pkg = JSON.parse(await fs.readFile(join(__dirname, "./package.json")))
10
+ const { name, description, version } = pkg
11
+
12
+ try {
13
+ // TODO: Remove when Node.js 18 is not maintained anymore
14
+ globalThis.crypto ??= (await import("crypto")).webcrypto
15
+ } catch {}
16
+
17
+ /** Web compatible method to create a random string of a given length */
18
+ export function randomString(size = 32) {
19
+ const bytes = crypto.getRandomValues(new Uint8Array(size))
20
+ return Buffer.from(bytes, "base64").toString("base64")
21
+ }
22
+
23
+ const program = new Command()
24
+
25
+ program.name(name).description(description).version(version)
26
+
27
+ program
28
+ .command("secret")
29
+ .option("--raw", "Output the string without any formatting.")
30
+ .description("Generate a random string.")
31
+ .action((options) => {
32
+ const value = randomString()
33
+ if (options.raw) return console.log(value)
34
+ // TODO: Detect framework, check for existing value, and write automatically
35
+ console.log(`
36
+ Secret generated. Copy it to your .env/.env.local file (depending on your framework):
37
+
38
+ AUTH_SECRET=${value}`)
39
+ })
40
+
41
+ // TODO: Get this programmatically
42
+ const frameworks = {
43
+ nextjs: {
44
+ src: "https://github.com/nextauthjs/next-auth-example",
45
+ demo: "https://next-auth-example.vercel.app",
46
+ },
47
+ sveltekit: {
48
+ src: "https://github.com/nextauthjs/sveltekit-auth-example",
49
+ demo: "https://sveltekit-auth-example.vercel.app",
50
+ },
51
+ express: {
52
+ src: "https://github.com/nextauthjs/express-auth-example",
53
+ demo: "https://express-auth-example.vercel.app",
54
+ },
55
+ }
56
+
57
+ program
58
+ .command("framework")
59
+ .argument("[framework]", "The framework to use.", (value) => {
60
+ if (!value) return value
61
+ if (Object.keys(frameworks).includes(value)) return value
62
+ throw new InvalidArgumentError(
63
+ `Valid frameworks are: ${supportedFrameworks.join(", ")}`
64
+ )
65
+ })
66
+ .description("Clone a framework template.")
67
+ .action((framework) => {
68
+ if (!framework) {
69
+ return console.log(`
70
+ Supported frameworks are: ${Object.keys(frameworks).join(", ")}`)
71
+ }
72
+ const { src, demo } = frameworks[framework]
73
+ console.log(`
74
+ Source code: ${src}
75
+ Deployed demo: ${demo}`)
76
+ })
77
+
78
+ program.parse(process.argv)
package/package.json CHANGED
@@ -1,33 +1,28 @@
1
1
  {
2
2
  "name": "auth",
3
- "version": "0.0.9",
4
- "description": "ERROR: No README.md file found!",
5
- "main": "./lib/index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
3
+ "description": "The CLI tool by Auth.js to supercharge your authentication workflow.",
4
+ "homepage": "https://cli.authjs.dev",
5
+ "version": "1.0.1",
6
+ "type": "module",
7
+ "bin": {
8
+ "auth": "index.js"
8
9
  },
9
- "repository": {
10
- "type": "git",
11
- "url": "git://github.com/crcn/node-auth.git"
12
- },
13
- "author": "",
14
- "license": "BSD",
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
- "outcome": "0.0.x",
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
- "browserify": "./browser/index.js",
28
- "devDependencies": {
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
@@ -1,2 +0,0 @@
1
- [commands]
2
- proj = subl .
package/.npmignore DELETED
@@ -1,2 +0,0 @@
1
- node_modules
2
- .DS_Store
@@ -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
@@ -1,13 +0,0 @@
1
-
2
-
3
- exports.connect = function(host) {
4
- if(arguments.length == 0) {
5
- host = window.location.origin;
6
- }
7
-
8
-
9
-
10
- return {
11
- Account: require("./account").connect(host)
12
- };
13
- }
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
-
@@ -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);
@@ -1,14 +0,0 @@
1
- var plugin = require("plugin");
2
-
3
-
4
- plugin().
5
- params({
6
- http: {
7
- port: 8085
8
- },
9
- mongodb: "mongodb://localhost/auth-tes"
10
- }).
11
- require("plugin-express").
12
- require("plugin-mongodb").
13
- require(__dirname + "/../").
14
- load();
@@ -1,6 +0,0 @@
1
-
2
-
3
-
4
- router.on("-method=DELETE groups/:group/items/:item", function(req, res, mw) {
5
-
6
- });
@@ -1,2 +0,0 @@
1
- var auth = require("auth");
2
-