Skip to content

Commit

Permalink
Adding helper for setting up development environment. Removing all me…
Browse files Browse the repository at this point in the history
…ntion of cjson.
  • Loading branch information
awestendorf committed Mar 20, 2015
1 parent a1c7a5b commit c01b230
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
master
======

* Added dev/test environment setup.

1.1.0
======

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Lua module to add Google OAuth to nginx.

You can copy `access.lua` to your nginx configurations, or clone the
repository. Your installation of nginx must already be built with Lua
support, and you will need the ``cjson`` and ``luasec`` modules as well.
support, and you will need the ``json`` and ``luasec`` modules as well.

### Ubuntu

Expand All @@ -18,6 +18,7 @@ lua5.1
liblua5.1-0
liblua5.1-0-dev
liblua5.1-sec-dev
liblua5.1-json
```

You will also need to download and build the following and link them
Expand All @@ -26,7 +27,6 @@ with nginx
```
ngx_devel_kit
lua-nginx-module
lua-cjson-2.1.0
```

See ``/chef/source-lua.rb`` for a Chef recipe to install nginx and Lua
Expand Down Expand Up @@ -207,6 +207,8 @@ If you wish the full email address returned from Google to be set as the usernam

## Development

See `test/README.md`.

Bug reports and pull requests are [welcome](https://github.com/agoragames/nginx-google-oauth).

It can be useful to turn off [lua_code_cache](http://wiki.nginx.org/HttpLuaModule#lua_code_cache)
Expand All @@ -217,7 +219,6 @@ while you're iterating.
- Add support for non-blocking sockets in obtaining an auth token
- Support auth token refresh and timeouts
- Continue support for Ubuntu but make imports work on other platforms as well
- Replace cjson requirement with "standard" Lua json
- 401 page that allows signing out and back in with a different account
- whitelist and blacklist is checked on every request

Expand Down
17 changes: 2 additions & 15 deletions chef/source-lua.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# http://wiki.nginx.org/HttpLuaModule#Installation_on_Ubuntu_11.10
# TODO: try using "lua-json" instead of lua-cjson
# https://launchpad.net/ubuntu/+source/lua-json
%w{libpcre3 libpcre3-dev libssl-dev liblwp-useragent-determined-perl libpam0g-dev lua5.1 liblua5.1-0 liblua5.1-0-dev cmake liblua5.1-sec-dev}.each do |devpkg|
%w{libpcre3 libpcre3-dev libssl-dev liblwp-useragent-determined-perl libpam0g-dev lua5.1 liblua5.1-0 liblua5.1-0-dev cmake liblua5.1-sec-dev liblua5.1-json}.each do |devpkg|
package devpkg
end

Expand All @@ -36,11 +36,6 @@
action :create_if_missing
end

remote_file "/tmp/lua-cjson-2.1.0.tar.gz" do
source "http://www.kyne.com.au/~mark/software/download/lua-cjson-2.1.0.tar.gz"
action :create_if_missing
end

# compile nginx
# -------------

Expand All @@ -51,10 +46,9 @@
tar zxf nginx-#{nginx_version}.tar.gz
tar zxf ngx_devel_kit-0.2.19.tar.gz
tar zxf nginx-lua-0.9.6.tar.gz
tar zxf lua-cjson-2.1.0.tar.gz
# Lua paths. Requires hack to get linking right.
ln -s /usr/lib/liblua5.1.so /usr/lib/liblua.so
ln -s `find /usr/lib -iname liblua5.1.so` /usr/lib/liblua.so
export LUA_LIB=/usr/lib/
export LUA_INC=/usr/include/lua5.1
Expand All @@ -65,13 +59,6 @@
--add-module=/tmp/lua-nginx-module-0.9.6
make
make install
cd /tmp/lua-cjson-2.1.0
mkdir build
cd build
cmake ..
make install
END
creates node[:nginx][:src_binary]
end
5 changes: 5 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ubuntu 12.04

Run `setup.sh` to install all apt requirements, download and build nginx with lua support. All prefixes will match this directory.

To run nginx, edit `oauth.conf` to use the correct domain and certificates, and then start the server with `sbin/nginx -c oauth.conf`. You should now be able to access the server
27 changes: 27 additions & 0 deletions test/oauth.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
worker_processes 1;

events {
worker_connections 1024;
}

http {
server {
server_name supersecret.net;
listen 443;

ssl on;
ssl_certificate supersecret_net.pem;
ssl_certificate_key supersecret_net.pem;

set $ngo_client_id "abc-def.apps.googleusercontent.com";
set $ngo_client_secret "abcdefg-123-xyz";
set $ngo_secure_cookies "true";
set $ngo_token_secret "SuPeRsEcReT";

lua_code_cache off;
access_by_lua_file "../access.lua";

header_filter_by_lua "ngx.header.content_length = nil";
body_filter_by_lua_file "../body_filter.lua";
}
}
35 changes: 35 additions & 0 deletions test/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

# This has been tested to work on Ubuntu 12.04. YMMV
PACKAGES="libpcre3 libpcre3-dev libssl-dev liblwp-useragent-determined-perl libpam0g-dev lua5.1 liblua5.1-0 liblua5.1-0-dev cmake liblua5.1-sec-dev liblua5.1-json"
echo "Installing lua and supporting packages"
sudo apt-get install $PACKAGES

mkdir src
cd src

VERSION="1.6.2"
echo "Downloading nginx $VERSION"
wget "http://nginx.org/download/nginx-$VERSION.tar.gz"

echo "Downloading ngx_devel_kit"
wget "https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz"
mv v0.2.19.tar.gz ngx_devel_kit-0.2.19.tar.gz

echo "Downloading nginx-lua"
wget "https://github.com/chaoslawful/lua-nginx-module/archive/v0.9.6.tar.gz"
mv v0.9.6.tar.gz nginx-lua-0.9.6.tar.gz

echo "Untarring"
tar zxf nginx-$VERSION.tar.gz
tar zxf ngx_devel_kit-0.2.19.tar.gz
tar zxf nginx-lua-0.9.6.tar.gz

echo "Linking libua to /usr/lib/liblua.so"
sudo ln -s `find /usr/lib -iname liblua5.1.so` /usr/lib/liblua.so

echo "Building nginx"
cd nginx-$VERSION
./configure --add-module=../ngx_devel_kit-0.2.19 --add-module=../lua-nginx-module-0.9.6 --prefix=`readlink -f ../..` --with-http_ssl_module
make install
cd ..

0 comments on commit c01b230

Please sign in to comment.