global::auth

Authentication mechanisms and credential manipulation.

fn unix_users

fn unix_users() -> Status
Process the SASL authentication mechanism.

The current implementation support β€œPLAIN” mechanism, and will call the testsaslauthd program to check the credentials.

The credentials will be verified depending on the mode of saslauthd.

A native implementation will be provided in the future.


fn is_authenticated

fn is_authenticated() -> bool
Check if the client is authenticated.

authenticate stage only.

  • bool - true if the client succeeded to authenticate itself, false otherwise.
#{
    authenticate: [
       action "log info" || log("info", `client authenticated: ${auth::is_authenticated()}`),
    ]
}

fn credentials

fn credentials() -> Credentials
Get authentication credentials from the client.

authenticate only.

  • Credentials - the credentials of the client.
#{
    authenticate: [
       action "log auth" || log("info", `${auth::credentials()}`),
    ]
}

get type

fn get type(credentials: Credentials) -> String
Get the type of the `auth` property of the connection.

authenticate only.

  • String - the credentials type.
#{
    authenticate: [
       action "log auth type" || {
            let credentials = auth::credentials();

            // Logs here will output 'Verify' or 'AnonymousToken'.
            // depending on the authentication type.
            log("info", `credentials type: ${credentials.type}`);
        },
    ]
}

get authid

fn get authid(credentials: Credentials) -> String
Get the `authid` property of the connection. Can only be use on 'Verify' authentication typed credentials.

authenticate only.

  • String - the authentication id.
#{
    authenticate: [
       action "log auth id" || {
            let credentials = auth::credentials();
            log("info", `credentials id: ${credentials.authid}`);
        },
    ]
}

get authpass

fn get authpass(credentials: Credentials) -> String
Get the `authpass` property of the connection. Can only be use on 'Verify' authentication typed credentials.

authenticate only.

  • String - the authentication password.
#{
    authenticate: [
       action "log auth pass" || {
            let credentials = auth::credentials();
            log("info", `credentials pass: ${credentials.authpass}`);
        },
    ]
}

get anonymous_token

fn get anonymous_token(credentials: Credentials) -> String
Get the `anonymous_token` property of the connection. Can only be use on 'AnonymousToken' authentication typed credentials.

authenticate only.

  • String - the token.
#{
    authenticate: [
       action "log auth token" || {
            let credentials = auth::credentials();
            log("info", `credentials token: ${credentials.anonymous_token}`);
        },
    ]
}