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
-
assert_env_vars
Assert the required ENV vars are present.
-
authenticated?(context)
Helper method used in any endpoints requiring auth.
-
development?
Returns true if running in "development" mode.
-
get_current_user(context) : Tuple(String, String, String | Nil)
Helper method which returns the authenticated user's username and email.
-
get_payload(context) : JSON::Any
Returns a Hash like Object representing the JSON request body.
-
halt(context, status : HTTP::Status)
Sets the desired status and raises an error.
-
has_access?(context, list : List)
Helper method used in any endpoints requiring auth.
-
production?
Returns true if running in "production" mode.
-
send_json(context, payload, status = HTTP::Status::OK)
Sets the response status and correct JSON headers and body.
-
send_status(context, status : HTTP::Status)
Sets the response status.
-
set_env_client_uri
Set the client origin URI (for CORS headers) in ENV.
-
set_rsa_public_key
Decode and set the RSA_PUBLIC_KEY in ENV.
-
test?
Returns true if running in "test" mode.
Method Detail
Helper method used in any endpoints requiring auth. Sets the authenticated user's name and email if successful. Raises an Exception if not.
Helper method which returns the authenticated user's username and email.
Returns a Hash like Object representing the JSON request body.
You should call this from a parse_*
method and halt(...)
on rescue
.
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.
Helper method used in any endpoints requiring auth. Raises an Exception if the user doesn't has access to the given list.
Returns true if running in "production" mode. Production is the default if TODO_ENV isn't set.
Sets the response status and correct JSON headers and body.