Module ngx-oauth.Cookies
Module for reading/writing request/response cookies.
This module exports single function, the module's constructor.
Example:
local Cookies = require 'ngx-oauth.Cookies' cookies = Cookies(conf) cookies.add_token(token)
Functions
__call (conf, crypto) | Creates a new Cookies "object" with the given configuration. |
add_token (token) | Writes access token and refresh token (if provided) cookies to the
response's Set-Cookie header. |
add_username (username) | Writes username cookie to the response's Set-Cookie header. |
clear_all () | Clears all cookies managed by this module, i.e. |
get_access_token () | Reads an access token from the request's cookies. |
get_refresh_token () | Reads a refresh token from the request's cookies. |
get_username () | Reads an username from the request's cookies. |
Functions
- __call (conf, crypto)
-
Creates a new Cookies "object" with the given configuration.
Parameters:
- conf table The configuration (see ngx-oauth.config).
- crypto {encrypt=func,decrypt=func} The crypto module to use (default: ngx-oauth.crypto).
Returns:
-
An initialized Cookies module.
- add_token (token)
-
Writes access token and refresh token (if provided) cookies to the
response's
Set-Cookie
header.Parameters:
- token {access_token=string,expires_in=int,refresh_token=(string or nil)}
- add_username (username)
-
Writes username cookie to the response's
Set-Cookie
header.Parameters:
- username string
- clear_all ()
-
Clears all cookies managed by this module, i.e. adds them to the
response's
Set-Cookie
header with valuedeleted
andMax-Age=0
. - get_access_token ()
-
Reads an access token from the request's cookies.
Returns:
-
string or nil
An access token, or
nil
if not set. - get_refresh_token ()
-
Reads a refresh token from the request's cookies.
Returns:
-
string or nil
A decrypted refresh token, or
nil
if not set. - get_username ()
-
Reads an username from the request's cookies.
Returns:
-
string or nil
An username, or
nil
if not set.