def token.pick

bend-kit-oauth2@0.11.0.1 · oauth2.bend:143

import bend-kit-oauth2@0.11.0.1/oauth2.bend as Oauth2
import Base
import bend-kit-time@0.3.0.0/time.bend as Time
import bend-kit-json@0.7.0.0/json.bend as Json
import bend-kit-encoding@0.5.0.0/encoding.bend as Enc
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes

143# §6: a refresh reply without refresh_token keeps the old one. b: the body, decoded only for an error.
144def token.pick(ok: Bool, +status: U32, +old: String, now: Time.Instant, b: Bytes.Bytes, g: Got) -> Result<&1, &1, Err, Token>:
145  match ok:
146    case True{}:
147      Got{a, t, +r, s, e, er, d} = g
148      Done{Token{a, t, Bool.pick(String, String.is_empty(r), old, r), s, expiry(now, Json.u32.num(e))}}
149    case False{}:
150      Got{a, t, r, s, e, +er, d} = g
151      Fail{Bool.pick(Err, String.is_empty(er), ErrReply{status, Enc.utf8.decode(b)}, ErrOAuth{status, er, d})}

Uses (14)

Used by (1)