55 lines
1.6 KiB
Markdown
Raw Normal View History

2023-12-23 12:41:11 +00:00
# PalAuth IAM client for Node JS
This uses the Fetch API, so technically it could work in the browser too. This is not recommended due to the need to handle PalAuth Client Secret tokens for the requests, as well as CORS restrictions.
## Supported features
Currently, only the `/check` method is supported. This checks if a given user has a given permission, returning a simply boolean answer.
## Installation
Because NPM is evil, this package is instead hosted within this GitLab repo.
Installing it isn't too hard! Just follow these simple steps.
In your some directory, create (or modify) a `.yarnrc.yml` file:
```yml
npmScopes:
paltiverse-public:
npmRegistryServer: "https://gitlab.palk.me/api/v4/packages/npm"
```
You will now be able to install any `@paltiverse-public` packages.
In the package where you want to install the client, run:
```
yarn add @paltiverse-public/palauth-iam-node
```
For more details, see [the GitLab docs](https://docs.gitlab.com/16.6/ee/user/packages/yarn_repository/#install-from-the-instance-level).
Using NPM or PNPM? See [the GitLab NPM docs](https://docs.gitlab.com/16.6/ee/user/packages/npm_registry/#install-a-package).
## Usage
```typescript
import PalAuthIAMClient from "@paltiverse-public/palauth-iam-node"
const client = new PalAuthIAMClient({
clientID: "abcdef",
clientSecret: "abcdef",
// If not using auth.palk.me:
baseURL: "https://<my-palauth-instance>/iam",
})
const isAllowed = await client.checkPermission({
userId: "abcdef",
permission: "repositories.issues.create",
})
```
## License
GNU GPL 3.0. See LICENSE.md.