Top Level Namespace

Defined in:

Constant Summary

REQUIRED_ENV_VARS = ["CLIENT_AUTH_URI", "CLIENT_ID", "CLIENT_SECRET", "DATABASE_URL", "PORT", "TOKEN_EXCHANGE_URL", "RSA_PUBLIC_KEY"] of ::String

Method Summary

Method Detail

def assert_env_vars #

Assert the required ENV vars are present.


[View source]
def authenticated?(context) #

Helper method used in any endpoints requiring auth. Sets the authenticated user's name and email if successful. Raises an Exception if not.


[View source]
def development? #

Returns true if running in "development" mode.


[View source]
def get_current_user(context) : Tuple(String, String, String | Nil) #

Helper method which returns the authenticated user's username and email.


[View source]
def get_payload(context) : JSON::Any #

Returns a Hash like Object representing the JSON request body. You should call this from a parse_* method and halt(...) on rescue.


[View source]
def halt(context, status : HTTP::Status) #

Sets the desired status and raises an error. This will return the status as long as your handler has a rescue { context } block (which it should). If you're getting a generic error it's likely that you're missing the rescue when calling this method.


[View source]
def has_access?(context, list : List) #

Helper method used in any endpoints requiring auth. Raises an Exception if the user doesn't has access to the given list.


[View source]
def production? #

Returns true if running in "production" mode. Production is the default if TODO_ENV isn't set.


[View source]
def send_json(context, payload, status = HTTP::Status::OK) #

Sets the response status and correct JSON headers and body.


[View source]
def send_status(context, status : HTTP::Status) #

Sets the response status.


[View source]
def set_env_client_uri #

Set the client origin URI (for CORS headers) in ENV.


[View source]
def set_rsa_public_key #

Decode and set the RSA_PUBLIC_KEY in ENV.


[View source]
def test? #

Returns true if running in "test" mode.


[View source]