src/auth.bend

emerging-ezhttp@0.11.0.0 · 13 lines · 0 definitions

1# ezhttp/src/auth: Authorization header values, pure. Kept apart from client.bend
2# (which reaches the wire effect) so the proof gate can import it.
3import Base
4import emerging-ezhttp@0.11.0.0/src/http.bend as Http
5import emerging-ezhttp@0.11.0.0/src/b64.bend as B64
6
7# Authorization: Bearer … (RFC 6750)
8def auth.bearer(token: String) -> Http.Header:
9  Http.H{"Authorization", "Bearer " ++ token}
10
11# Authorization: Basic … (RFC 7617, credentials are RFC 4648 Base64)
12def auth.basic(user: String, password: String) -> Http.Header:
13  Http.H{"Authorization", "Basic " ++ B64.b64.encode(user ++ ":" ++ password)}