Skip to content
This repository has been archived by the owner on Apr 7, 2020. It is now read-only.

Add cookie domain and ignore uri configs #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ variables are:
returned from Google (portion left of '@' in email).
- **$ngo_email_as_user** If set and `$ngo_user` is defined, username
returned will be full email address.
- **$ngo_cookie_domain** If defined, the chosen domain will be added to the
cookies, this can be useful for granting access to multiple subdomains.
- **$ngo_ignore_uri** If defined, URIs containing this prefix will bypass
authentication.

## Available endpoints

Expand Down
9 changes: 9 additions & 0 deletions access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ local secure_cookies = ngx.var.ngo_secure_cookies == "true" or false
local http_only_cookies = ngx.var.ngo_http_only_cookies == "true" or false
local set_user = ngx.var.ngo_user or false
local email_as_user = ngx.var.ngo_email_as_user == "true" or false
local cookie_domain = ngx.var.ngo_cookie_domain or ""
local ignore_uri = ngx.var.ngo_ignore_uri or ""

if whitelist:len() == 0 then
whitelist = nil
Expand Down Expand Up @@ -157,6 +159,10 @@ local function request_profile(token)
end

local function is_authorized()
if uri:sub(1, #ignore_uri) == ignore_uri then
return true
end

local headers = ngx.req.get_headers()

local expires = tonumber(ngx.var.cookie_OauthExpires) or 0
Expand Down Expand Up @@ -227,6 +233,9 @@ local function authorize()
if http_only_cookies then
cookie_tail = cookie_tail .. ";httponly"
end
if cookie_domain ~= "" then
cookie_tail = cookie_tail .. ";Domain=" .. cookie_domain
end

local email = profile["email"]
local user_token = ngx.encode_base64(ngx.hmac_sha1(token_secret, cb_server_name .. email .. expires))
Expand Down