Skip to content

Commit 6e1ac3d

Browse files
authored
Merge pull request #285 from sshanks-kx/zac
enhanced .z.ac details
2 parents 5b03cda + 1256e12 commit 6e1ac3d

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

docs/ref/dotz.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ _Environment and callbacks_
1212

1313
<div markdown="1" class="typewriter">
1414
Environment Callbacks
15-
[.z.a IP address](#za-ip-address) [.z.ac HTTP auth from cookie](#zac-http-auth-from-cookie)
15+
[.z.a IP address](#za-ip-address) [.z.ac HTTP auth](#zac-http-auth)
1616
[.z.b dependencies](#zb-dependencies) [.z.bm msg validator](#zbm-msg-validator)
1717
[.z.c cores](#zc-cores) [.z.exit action on exit](#zexit-action-on-exit)
1818
[.z.D/d date shortcuts](#zt-zt-zd-zd-timedate-shortcuts) [.z.pc close](#zpc-close)
@@ -83,33 +83,35 @@ q)"i"$0x0 vs .z.a
8383
When invoked via a Unix Domain Socket, it is 0.
8484

8585

86-
## `.z.ac` (HTTP auth from cookie)
86+
## `.z.ac` (HTTP auth)
8787

8888
```syntax
8989
.z.ac:(requestText;requestHeaderAsDictionary)
9090
```
9191

92-
Lets you define custom code to extract Single Sign On (SSO) token cookies from the HTTP header and verify it, decoding and returning the username, or instructing what action to take.
92+
Lets you define custom code to authorize/authenticate an HTTP request.
93+
e.g. inspect HTTP headers representing oauth tokens, cookies, etc.
94+
Your custom code can then return different values based on what is discovered.
9395

96+
The function should return a two-element list. The list of possible return values is:
97+
98+
* User not authorized/authenticated
9499
```q
95-
q).z.ac:{mySSOAuthenticator x[1]`Authorization}
100+
(0;"")
96101
```
97-
98-
where allowed return values are
99-
102+
User not authorized. Client is sent default 401 HTTP unauthorized response.
103+
An HTTP callback to handle the request will not be called.
104+
* User authorized/authenticated
100105
```q
101-
(0;"") / return default 401
102-
(1;"username") / authenticated username (.z.u becomes this)
103-
(2;"response text") / send raw response text to client
104-
(4;"") / fallback to try authentication via .z.pw (V4.0 2021.07.12)
106+
(1;"username")
105107
```
108+
The provided username is used to set [`.z.u`](#zu-user-id).
109+
The relevant HTTP callback to handle this request will be allowed.
110+
* User not authorized/authenticated (custom response)
111+
```q
112+
(2;"response text")
106113
107-
and `mySSOAuthenticator` is your custom code that authenticates against your SSO library.
108-
109-
If `.z.ac` returns `(4;"")` then `.z.pw` will be called with the b64-decoded credentials from the http header when .z.ac returns (4;"").
110-
111-
:fontawesome-solid-hand-point-right:
112-
[`.z.pw` password check](#zpw-validate-user)
114+
!!! note "If .z.ac is not defined, it uses basic access authentication as per `(4;"")` above"
113115
114116
115117
## `.z.b` (dependencies)
@@ -643,7 +645,7 @@ For the POST method use [.z.pp](#zpp-http-post), and for GET use [.z.ph](#zph-ht
643645
.z.po:f
644646
```
645647

646-
Where `f` is a unary function, `.z.po` is evaluated when a connection to a kdb+ session has been initialized, i.e. after it’s been validated against any `-u/-U` file and `.z.pw` checks.
648+
Where `f` is a unary function, `.z.po` is evaluated when a connection to a kdb+ session has been initialized, i.e. after it’s been validated against any [`-u`](../basics/cmdline.md#-u-usr-pwd-local)/[`-U`](../basics/cmdline.md#-u-usr-pwd) file and `.z.pw` checks.
647649

648650
Its argument is the handle and is typically used to build a dictionary of handles to session information like the value of `.z.a`, `.z.u`
649651

@@ -724,7 +726,7 @@ q)0 "2+2"
724726
.z.pw:f
725727
```
726728

727-
Where `f` is a binary function, `.z.pw` is evaluated _after_ the `-u/-U` checks, and _before_ `.z.po` when opening a new connection to a kdb+ session.
729+
Where `f` is a binary function, `.z.pw` is evaluated _after_ the [`-u`](../basics/cmdline.md#-u-usr-pwd-local)/[`-U`](../basics/cmdline.md#-u-usr-pwd) checks, and _before_ `.z.po` when opening a new connection to a kdb+ session.
728730

729731
The arguments are the user ID (as a symbol) and password (as a string) to be verified; the result is a boolean atom.
730732

0 commit comments

Comments
 (0)