palauth-iam-node/README.md

53 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
2024-01-16 13:39:03 +00:00
Because NPM is evil, this package is instead hosted within this Gitea repo.
2023-12-23 12:41:11 +00:00
Installing it isn't too hard! Just follow these simple steps.
2023-12-23 12:47:23 +00:00
Create (or modify) a `.yarnrc.yml` file (either in your home directory to configure globally, or in the root of the package where you want to install):
2023-12-23 12:41:11 +00:00
```yml
npmScopes:
2024-01-16 13:39:03 +00:00
paltiverse:
npmRegistryServer: "https://gitea.palk.me/api/packages/paltiverse/npm/"
2023-12-23 12:41:11 +00:00
```
2024-01-16 13:39:03 +00:00
You will now be able to install any public `@paltiverse` packages (either for all projects if you added this to your home directory, or just for the current project if you added it there).
2023-12-23 12:41:11 +00:00
In the package where you want to install the client, run:
```
2024-01-16 13:39:03 +00:00
yarn add @paltiverse/palauth-iam-node
2023-12-23 12:41:11 +00:00
```
2024-01-16 13:39:03 +00:00
For more details, see [the Gitea docs](https://docs.gitea.com/usage/packages/npm).
2023-12-23 12:41:11 +00:00
## Usage
```typescript
2024-01-16 13:39:03 +00:00
import PalAuthIAMClient from "@paltiverse/palauth-iam-node"
2023-12-23 12:41:11 +00:00
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.