Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "ad", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Active Directory API for Node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
262
readme.md
@@ -5,6 +5,8 @@ # AD | ||
[] | ||
--- | ||
[https://img.shields.io/badge/build-passing-brightgreen.svg](Build Passing) | ||
[https://img.shields.io/badge/build-100%25-brightgreen.svg](Coverage 100%) | ||
AD is a Javascript implementation of common Active Directory tasks, built to be simple as possible. | ||
@@ -16,5 +18,6 @@ | ||
``` | ||
```js | ||
(async () => { | ||
try { | ||
await ad.user().add({ | ||
@@ -29,2 +32,3 @@ userName: 'jsmith' | ||
await ad.user('jsmith').addToGroup('Sales'); | ||
} catch(err) { | ||
@@ -38,9 +42,9 @@ // ... | ||
``` | ||
ad.user('agnes').changePassword('d0ntForgetThisTime')\ | ||
.then(() => ad.user('crook').disable()) | ||
.then(() => ad.user('larry').move('Dungeon')) | ||
.catch((err) => { | ||
// ... | ||
}); | ||
```js | ||
ad.user('agnes').changePassword('d0ntForgetThisTime')\ | ||
.then(() => ad.user('crook').disable()) | ||
.then(() => ad.user('larry').move('Dungeon')) | ||
.catch((err) => { | ||
// ... | ||
}); | ||
@@ -53,7 +57,7 @@ ``` | ||
``` | ||
```bash | ||
npm i ad | ||
``` | ||
``` | ||
```bash | ||
yarn add ad | ||
@@ -64,5 +68,7 @@ ``` | ||
``` | ||
```js | ||
const AD = require('ad'); | ||
// Your AD account should be a member | ||
// of the Administrators group. | ||
const ad = new ad({ | ||
@@ -74,4 +80,16 @@ url: "ldaps://127.0.0.1", | ||
ad.user().get().then(users => { | ||
console.log('Your users:', users); | ||
}).catch(err => { | ||
console.log('Error getting users:', err); | ||
}); | ||
``` | ||
Now run the file: | ||
```bash | ||
node index.js | ||
``` | ||
And you're off to the races. | ||
@@ -81,3 +99,3 @@ | ||
``` | ||
```bash | ||
ad.user().get(opts) | ||
@@ -120,9 +138,223 @@ ad.user().add(opts) | ||
### User | ||
#### ad.user().get(filter) | ||
Returns all user objects. | ||
```js | ||
await ad.user().get({fields: 'sAMAccountName'}); | ||
// => ['jsmith', 'dthree', 'qix']; | ||
``` | ||
#### ad.user().add(options) | ||
Creates a new user. Returns the created user object. | ||
##### Options: | ||
* `userName`: String (required) | ||
* `pass`: String (required) | ||
* `commonName`: String (required) | ||
* `firstName`: String | ||
* `lastName`: String | ||
* `email`: String | ||
* `title`: String | ||
* `location`: String | ||
If not specified, the first and last name will be based on the `commonName`. | ||
```js | ||
await ad.user().add({ | ||
userName: 'jsmith' | ||
commonName: 'John Smith', | ||
password: 'J@vascr!pt1' | ||
}); | ||
// => {sAMAccountName: 'jsmith' ... } | ||
``` | ||
#### ad.user(userName).get(filter) | ||
Returns a user object. If no user is matched, returns undefined. | ||
```js | ||
await ad.user('jsmith').get(); | ||
// => {sAMAccountName: 'jsmith', email: 'jsmith@acme.co' ... } | ||
``` | ||
#### ad.user(userName).exists() | ||
Returns a `Boolean` of whether the user account matched. | ||
```js | ||
await ad.user('lochness').exists(); | ||
// => false | ||
``` | ||
#### ad.user(userName).addToGroup(groupName) | ||
Adds a user to a security group. | ||
```js | ||
await ad.user('jsmith').addToGroup('Sales'); | ||
// => {success: true} | ||
``` | ||
#### ad.user(userName).removeFromGroup(groupName) | ||
Removes a user from a security group. | ||
```js | ||
await ad.user('jsmith').addToGroup('Sales'); | ||
// => {success: true} | ||
``` | ||
#### ad.user(userName).isMemberOf(groupName) | ||
Returns a `Boolean` based on whether the user is a member of a group. | ||
```js | ||
await ad.user('jsmith').isMemberOf('Sales'); | ||
// => true | ||
``` | ||
#### ad.user(userName).authenticate(password) | ||
Attempts to authenticate a user with a given password. Returns `Boolean`. | ||
```js | ||
await ad.user('jsmith').authenticate('J@vascript1#!'); | ||
// => true | ||
``` | ||
#### ad.user(userName).password(password) | ||
Sets a user's password. | ||
```js | ||
await ad.user('jsmith').password('Wh-m@ksp@ssw-rdslIkethis'); | ||
// => true | ||
``` | ||
#### ad.user(userName).passwordNeverExpires() | ||
Sets a user's to never expire. | ||
```js | ||
await ad.user('jsmith').passwordNeverExpires(); | ||
// => {success: true} | ||
``` | ||
#### ad.user(userName).passwordExpires() | ||
Unchecks the "Password never expires" box. | ||
```js | ||
await ad.user('jsmith').passwordExpires(); | ||
// => {success: true} | ||
``` | ||
#### ad.user(userName).enable() | ||
Enables a user. | ||
```js | ||
await ad.user('jsmith').enable(); | ||
// => {success: true} | ||
``` | ||
#### ad.user(userName).disable() | ||
Disables a user. | ||
```js | ||
await ad.user('jsmith').disable(); | ||
// => {success: true} | ||
``` | ||
#### ad.user(userName).unlock() | ||
Unlocks a user who has been locked out by repeated failed login attempts. | ||
```js | ||
await ad.user('jsmith').unlock(); | ||
// => {success: true} | ||
``` | ||
#### ad.user(userName).lock() | ||
Just kidding. You can't lock an account. Try disabling it instead. | ||
```js | ||
await ad.user('jsmith').disable(); | ||
// => {success: true} | ||
``` | ||
#### ad.user(userName).move(location) | ||
Moves a user to another directory, starting from the root of the domain. | ||
```js | ||
await ad.user('jsmith').move('Users/HR'); | ||
// => {success: true} | ||
``` | ||
This is the equivalent of `acme.co => Users (OU) => HR (OU)`. The new `Distinguished Name` (DN) would become `CN=John Smith,OU=HR,OU=Users,DC=acme,DC=co`. | ||
To specify a folder that is not an Organizational Unit, prefix it with `!`: | ||
```js | ||
await ad.user('admin').move('!Builtin'); | ||
// => {success: true} | ||
``` | ||
#### ad.user(userName).location() | ||
Returns a user's relative location, separated by `/`es. | ||
```js | ||
await ad.user('jsmith').location(); | ||
// => 'Users/HR' | ||
``` | ||
#### ad.user(userName).remove() | ||
Deletes a user. Are you sure you want to do this? | ||
```js | ||
await ad.user('jsmith').remove(); | ||
// => {success: true} | ||
``` | ||
## Why? | ||
Active Directory / LDAP can be hard. Some of us are stuck with it, so I wanted to make it easier. | ||
Active Directory / LDAP can be hard. Some of us are stuck with it. | ||
Should you really have to know that `cn` stands for `Common Name` (or was is `Canonical`) in order to use it? Or that `sn` is a `surname`? I dislike systems that require detailed knowledge of their dirty laundry to do anything with them. | ||
So this was a selfish project, really. | ||
Made with <3 by [dthree](https://github.com/dthree). | ||
## License | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
57915
351
0