Token

final class Token : Model
extension Token: ModelTokenAuthenticatable

A Token model associates a randomly generated string with a User.

A Token is generated upon each login, and revoked by deletion upon each logout. The .token value is used in between those events in an HTTP Bearer Authorization header field to authenticate the user sending API requests. There is no identifying user info in a .token; the association to a specific User is done internally on the API server through this model.

Properties

Initializaton

Methods

  • Creates a new random Token.

    Declaration

    Swift

    static func generate(for user: User, length: Int = 16) throws -> Token

    Parameters

    user

    The User to be associated with this Token.

    length

    Desired length of token data, defaults to 16.

    Return Value

    A Token object.