Naviga Web
Docs Home
  • Introduction
  • Release notes
  • Starter kit
    • Introduction
    • Environment Variables
    • Makefile
    • Changelog
    • API
  • Feature: Advanced Search
    • User guide
    • Search Help
    • How to Setup
    • Technical Details
  • Developer documentation
    • Developer prerequisites
      • Developer hardware suggestions
      • Setup on Windows
      • Setup on Linux/Ubuntu
    • Getting started with development
      • Composer package management
      • Gulp and asset building (optional)
      • Git
      • Hosts file
      • Certificate
      • Initiate Naviga Web
      • Start Naviga Web
      • Bin scripts
      • Create theme
      • Environments
      • Deployment
      • Onboarding tasks
        • #0 - New site
        • #1 - Configuration
        • #2 - Front page
        • #3 - Content presentation
        • #4 - OC List
        • #5 - Content containers
        • #6 - Teaser template
        • #7 - Single article
        • #8 - Widget
        • #9 - Custom task
        • #10 - Feedback
    • Architecture
    • Paywall and authentication
      • CloudFront Paywall
      • Engage paywall
      • Lua Paywall (deprecated)
    • Project management: A typical project
    • Database dump
    • Debugging
    • Keep your project up-to-date
    • Gulp and Sass
    • Domain mapping
    • Widgets overview
  • Starter kit packages
    • Base package
      • Changelog
    • Boards plugin (EveryBoard)
      • Installation
      • Setup
      • Board Widgets
        • Linked board
        • Template board
        • Embed widget
        • OC List item
        • Content container
      • Teaser templates
      • Actions and filters
      • Export - import
      • Changelog
    • ContentSync plugin
      • Usage
      • Changelog
    • Drop In Plugins package
      • Changelog
    • Everyware plugin
      • Installation
      • Setup
      • Actions and filters
      • Fetching lists and their content
      • Sorting
      • Widgets
      • Changelog
    • Imengine package
      • Helper class: Imengine
      • Changelog
    • NewsML package
      • Idf Parser
      • Changelog
      • Usage
    • NGINX conf package
      • API
      • Changelog
      • Usage
    • Presentation Preview plugin
      • API
      • Changelog
      • Usage
    • Support package
      • Changelog
    • Theme EU resources package*
      • Changelog
    • Theme US resources package
      • Changelog
    • Twig package
      • Development
        • Filters
          • class_string
          • spacey
          • trim_array
        • Functions
          • php_function
          • php_method
          • render_classes
          • render_partial
        • Operators
          • contains
      • Helper classes
        • View
        • ViewSetup
      • Changelog
  • Widgets and component packages
    • Article List widget
      • Installation
      • Using Article List
      • Changelog
    • Menu handler
      • Usage
      • Changelog
    • Section Header widget
      • Changelog
    • Social media icons widget
      • Installation
      • Changelog
    • Google Analytics plugin
      • Set up Google Analytics
      • Most read widget
      • Changelog
    • Redirect Original URLs plugin
      • Installation
      • Changelog
    • Settings Parameters plugin
      • Installation
      • Usage
      • Changelog
  • Design and theme packages
    • Base theme 1
      • Changelog
    • Base theme 2
      • Colors
      • Fonts
      • Header
      • Menus
      • Pages with Board
      • Sidebars
      • Teaser layouts
      • Article page (text)
      • Article page (embeds)
      • Changelog
    • Example theme
      • Changelog
  • MU Plugins
    • Project Plugin
      • Installation
      • Changelog
    • Starter Package Catalyst
    • Concepts
      • Admin Pages
        • All Concepts
        • Add New Concept
        • Types
        • Errors
        • Concept duplicates
      • API
      • Console
      • Changelog
    • Network
      • Changelog
    • Cache Invalidator
      • Getting Started & WP admin
      • Implementation of Lua endpoint
      • Filters
      • Changelog
    • RSS Feeds
      • Setup
      • Administration pages
      • Changelog
  • Services
    • Imengine
    • Imengine documentation
    • Open Content
    • Writer Bookmarklet
Powered by GitBook
On this page
  • How it works
  • Usage in Naviga Web php code

Was this helpful?

  1. Developer documentation
  2. Paywall and authentication

Lua Paywall (deprecated)

Custom server side paywall, with Lua

This solution became deprecated with Starter Kit 2.

So only available for setups stil on Starter Kit v1 or earlier.

How it works

Authentication of users is done in nginx with the help of Lua, this is not how it has to be done but we have found it a good and efficient way. Doing it there means we don't have to let all requests initialize PHP and Wordpress which would be a problem for performance.

So how is this done in practice? We have to make sure different cached content is delivered to users depending on their authorization status, we also have a check on a URL basis to make sure we don't run the authentication on content where it is not needed.

The authorization workflow is kickstarted in nginx configuration.

# Run authentication check except these filetypes.
set $ew_auth_var "closed";
set_by_lua_file $check_auth '/opt/openresty/site/lualib/check-auth.lua';

rewrite_by_lua_file '/opt/openresty/site/lualib/auth.lua';

The Lua-code that sets this variable will validate cookie data or in some other way integrate with the authorization system to determine the status of the active user. When the status is determined it will set the value of the variable.

-- Only check this against request that have check_auth
if ngx.var.check_auth ~= "true" then
    return
end

ngx.req.clear_header("X-EW-Auth")
ngx.req.clear_header("X-EW-AuthEnvironment")

-- TODO: Logic that integrates the authorization system to determine user status.
local ew_auth = '';

ngx.req.set_header("X-EW-Auth", ew_auth);

local cache_key = 'closed'

if ew_auth == 'true' then
    cache_key = 'open'
elseif ew_auth == 'false' then
    cache_key = 'expired'
elseif ew_auth == 'noaccess' then
    cache_key = 'noaccess'
end

ngx.var.ew_auth_var = cache_key

When the status is determined we add that variable as part of the cache key.

ledge:config_set("cache_key_spec", { ngx.var.every_device, ngx.var.ew_auth_var, scheme, ngx.var.host, ngx.var.uri, ngx.var.args })

Usage in Naviga Web php code

When a request goes all the way to PHP we will be able to read a header value to get the authorization status. This means you can make decisions to show/hide or take any other actions depending on the status and it will only be applied to users with the same authorization status.

/**
 * Check if user has access to content.
 *
 * @return bool
 */
public static function hasUserAccess() {
  return isset($_SERVER['HTTP_X_EW_AUTH']) && $_SERVER['HTTP_X_EW_AUTH'] === 'true';
}
PreviousEngage paywallNextProject management: A typical project

Last updated 2 years ago

Was this helpful?