Commit 4c3abd29 authored by jan.koester's avatar jan.koester
Browse files

test

parent 0bbc64bb
Loading
Loading
Loading
Loading
Loading
+1 −0
Changes for .gitignore: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,3 +3,4 @@ build/*
/out/build/x64-Debug
out*
tuxist.de.db
bindings/nodejs/lib
 No newline at end of file
+4 −4
Changes for bindings/CMakeLists.txt: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -7,10 +7,10 @@ set(NODE_MODULE_MINIMUM_ABI 83)

include("${CMAKE_SOURCE_DIR}/cmake/nodejs.cmake")

add_node_module(authdb-nds)
add_node_module(authdb-nds INSTALL_PATH "nodejs/lib/{node_abi}/authdb-nds.node")

target_sources(authdb-nds INTERFACE
    ${CMAKE_CURRENT_SOURCE_DIR}/nodesjs.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/nodejs/nodesjs.cpp
)

target_include_directories(
@@ -30,7 +30,7 @@ if(Python3_FOUND)
    message(STATUS "Python3 found: ${Python3_VERSION} – building authdb Python module")

    add_library(authdb-python SHARED
        ${CMAKE_CURRENT_SOURCE_DIR}/python.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/python/python.cpp
    )

    set_target_properties(authdb-python PROPERTIES
@@ -80,7 +80,7 @@ if(PHP_CONFIG_EXECUTABLE)
    message(STATUS "  PHP ext dir  : ${PHP_EXTENSION_DIR}")

    add_library(authdb-php SHARED
        ${CMAKE_CURRENT_SOURCE_DIR}/php.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/php/php.cpp
    )

    set_target_properties(authdb-php PROPERTIES
+16 −0
Changes for bindings/nodejs/.npmignore: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Build artifacts
lib/
CMakeLists.txt
CMakeFiles/
Makefile
cmake_install.cmake

# Other language bindings
php.cpp
python.cpp

# Development
.git
.gitignore
*.o
*.a
+28 −0
Changes for bindings/nodejs/LICENSE.txt: 28 added lines, 0 removed lines.
Original line number Diff line number Diff line
BSD 3-Clause License

Copyright (c) 2024, jan.koester

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
   contributors may be used to endorse or promote products derived from
   this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+101 −0
Changes for bindings/nodejs/README.md: 101 added lines, 0 removed lines.
Original line number Diff line number Diff line
# authdb-client

Native Node.js client bindings for **AuthDB** – an authentication database with a JSON REST API.

## Installation

```bash
npm install authdb-client
```

The package ships prebuilt native binaries for a range of Node.js ABI versions on Linux / FreeBSD.
If no prebuild is available for your version, see *Building from source* below.

## Usage

```js
const { ClientConnection, Client } = require('authdb-client');

// 1. Create a connection
const con = new ClientConnection();
con.setUrl('https://authdb.example.com:9090');
con.setClientName('my-app');
con.setClientSecret('s3cret');
con.setUsername('admin');
con.setUserPassword('password');

// 2. Create a client and authenticate
const client = new Client(con);
const ok = client.userAuth();
console.log('Authenticated:', ok);

// 3. Query session info
const info = client.sessionInfo();
console.log(info);
// { sessionId: '...', userId: '...', username: '...', domainId: '...' }

// 4. GPO checks
const allowed = client.gpoCheck('<gpo-uuid>');

// 5. Logout
client.remSession();
```

## API

### `ClientConnection`

| Method                        | Description                           |
| ----------------------------- | ------------------------------------- |
| `setUrl(url)`                 | Set the AuthDB server URL             |
| `setClientName(name)`         | Set the client application name       |
| `setClientSecret(secret)`     | Set the client application secret     |
| `setUsername(username)`        | Set the username for authentication   |
| `setUserPassword(password)`   | Set the user password                 |
| `getClientId()`               | Get the assigned client UUID          |
| `getSessionID()`              | Get the current session UUID          |
| `setSessionID(sessionId)`     | Restore a previously obtained session |
| `reConnect()`                 | Reconnect to the server               |

### `Client`

| Method                                      | Returns           | Description                              |
| ------------------------------------------- | ----------------- | ---------------------------------------- |
| `userAuth()`                                | `boolean`         | Authenticate with user credentials       |
| `clientAuth()`                              | `boolean`         | Authenticate with client credentials     |
| `addConnection(name, secret)`               | `string` (UUID)   | Register a new client connection         |
| `remConnection(clientId)`                   | –                 | Remove a client connection               |
| `editConnection(clientId, name, secret)`    | –                 | Edit an existing client connection       |
| `sessionInfo()`                             | `SessionInfo`     | Get current session details              |
| `remSession()`                              | `boolean`         | Invalidate the current session           |
| `gpoCheck(gpoId)`                           | `boolean`         | Check a GPO permission                   |
| `gpoExists(gpoId)`                          | `boolean`         | Check if a GPO exists                    |
| `changeUserPw(oldPw, newPw)`               | –                 | Change the current user's password       |

## Building from Source

Requires the full authdb repository and its C++ dependencies (see the project README).

```bash
git clone <repo-url> authdb
cd authdb
mkdir build && cd build
cmake .. && make
```

Then copy the prebuilt binaries into the npm package:

```bash
node bindings/nodejs/copy-prebuilds.js
```

## Publishing

```bash
cd bindings/nodejs
npm publish
```

## License

BSD-3-Clause – see [LICENSE.txt](LICENSE.txt).
Loading