moonbitstack/moonmcp/auth does not have a README file

    Bearer

    pub struct Bearer {
    // private fields
    }

    How a transport checks a bearer token (← the authorization section of the protocol): a request without one is answered 401 with a WWW-Authenticate challenge, and one whose token does not verify is answered the same way with invalid_token.

    Two ways to build one: Bearer::hmac for a token signed with a shared secret, which is what a test and a single-tenant deployment use, and Bearer::own for anything else — an RSA or ECDSA key, a JSON Web Key Set fetched from the issuer, an opaque token looked up in a table. own takes the whole decision, so this library never has an opinion about how a token is judged, only about what happens when it is not.

    Bearer::check

    fn Bearer::check(self : Bearer, authorization : String) -> Result[Principal, String]

    Check the Authorization header of a request. Err carries the reason the token is refused, phrased for the client.

    Bearer::hmac

    fn Bearer::hmac(secret~ : String, alg? :
    Alg
    , issuer? : String, audience? : Array[String], leeway? : Int64, clock? : () -> Int64) -> Bearer

    Check tokens signed with secret by a shared key: alg is the algorithm the verifier uses, and a token that names another one is refused rather than trusted.

    issuer and audience are checked when given, so a token minted for another service does not open this one. clock is the instant in seconds since the epoch that expiry is measured against, which a test fixes and a deployment leaves alone.

    Bearer::own

    fn Bearer::own(check~ : (String) -> Result[Principal, String]) -> Bearer

    Check tokens with check, which returns the caller or the reason the token is refused. The reason travels to the client in error_description, so it should say what is wrong without saying anything a stranger could use.

    Principal

    pub(all) struct Principal {
    subject : String?
    claims : Map[String, Json]
    } derive(Eq,
    Debug
    )

    The caller a token vouched for: its sub, and every claim as it arrived.

    A claim is whatever the issuer put there — a scope list, a tenant, a role. Nothing here interprets them; a handler reads what it needs.

    Principal::equal

    fn Principal::equal(Principal, Principal) -> Bool

    Principal::has_scope

    fn Principal::has_scope(self : Principal, scope : String) -> Bool

    Whether the token grants scope, read from the scope claim (space separated) or scp (a list), which are the two spellings in use.

    Principal::not_equal

    fn Principal::not_equal(x : Principal, y : Principal) -> Bool

    Source Files

    Powered by MoonBit

    Site sourceReport issueModulesSkillsBuild queueStatistics

    © 2026 mooncakes.io