Skip to content

Commit

Permalink
Update authkit documentation & bump to version 0.2.0 (#1124)
Browse files Browse the repository at this point in the history
Once this PR is closed, I will release appkit.
  • Loading branch information
owi92 authored Feb 28, 2024
2 parents 9fa684b + 0ce4050 commit 04a7317
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
26 changes: 26 additions & 0 deletions docs/docs/setup/auth/user/tobira-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ Deno.serve({ port: 7007 }, async (request) => {
});
```

You can also use [the `@opencast/tobira-authkit` package](https://www.npmjs.com/package/@opencast/tobira-authkit) for writing your service.
That library uses Node.js, gives you type safety (via TypeScript) and performs additional checks.

```ts title="Same login callback written with authkit using Node.js"
import { LoginCheck, runLoginCallbackServer } from "@opencast/tobira-authkit";

await runLoginCallbackServer({
listen: { host: "127.0.0.1", port: 7007 },
check,
});

const check: LoginCheck = async ({ userid, password }) => {
if (userid === "peter" && password === "verysecure") {
return {
outcome: "user",
username: "peter",
displayName: "Peter Lustig",
userRole: "ROLE_USER_PETER",
roles: ["ROLE_USER", "ROLE_ANONYMOUS", ...],
};
} else {
return "forbidden";
}
};
```


## Create sessions manually via `POST /~session`

Expand Down
2 changes: 1 addition & 1 deletion util/authkit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## Unreleased
## v0.2.0

- Add `userRole` to `LoginOutcome`: this reflects the Tobira change of requiring an explicit unique user role.
- Rename `runServer` to `runLoginProxyServer`
Expand Down
13 changes: 6 additions & 7 deletions util/authkit/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
# `@opencast/tobira-authkit`: Helper for building your own Tobira auth handler

This library enables you to build your own login handler that can be used with Tobira.
Useful mostly for `auth.mode = "login-proxy"`.
See [the documentation](https://elan-ev.github.io/tobira/setup/auth/login-proxy) for context and more information.
Useful mostly for using the login callbacks or for intercepting login requests.
See [the documentation](https://elan-ev.github.io/tobira/next/setup/auth/user/tobira-session) for context and more information.

## API

The API is described only very briefly here as all public functions and types are documented in code.
The main entry point (and only non-type export) is `startServer`.
There are two main entry points: `runLoginCallbackServer` (for `login-callback`) and `runLoginProxyServer` (for intercepting login requests).

```typescript
import { startServer, LoginCheck } from "@opencast/tobira-authkit";
import { runLoginCallbackServer, LoginCheck } from "@opencast/tobira-authkit";

startServer({
await runLoginCallbackServer({
check: myCheckFunction,
// ... other options
});

const myCheckFunction: LoginCheck = async ({ userid, password }) => { ... };
```

This starts an HTTP server that handles login requests by eventually calling the provided `check` function.
This starts an HTTP server that handles login requests by calling the provided `check` function.
Said function can either return `"forbidden"` or an object describing the user.
In the latter case, this library will automatically send a `POST /~session` to Tobira.
2 changes: 1 addition & 1 deletion util/authkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opencast/tobira-authkit",
"version": "0.1.0",
"version": "0.2.0",
"description": "Helper library to implement your own auth logic for Tobira",
"author": "The Opencast project",
"repository": {
Expand Down

0 comments on commit 04a7317

Please sign in to comment.