All Projects → sorah → Nginx_omniauth_adapter

sorah / Nginx_omniauth_adapter

Licence: mit
Use omniauth for nginx auth_request

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Nginx omniauth adapter

Next Advanced Apollo Starter
Advanced, but minimalistic Next.js pre-configured starter with focus on DX
Stars: ✭ 131 (+107.94%)
Mutual labels:  authentication, nginx
Docker Nginx Basic Auth
🔐 Simple Docker image for basic authentication
Stars: ✭ 111 (+76.19%)
Mutual labels:  authentication, nginx
Flask Restful Authentication
An example for RESTful authentication using nginx, uWSGI, Flask, MongoDB and JSON Web Token(JWT).
Stars: ✭ 63 (+0%)
Mutual labels:  authentication, nginx
Authelia
The Single Sign-On Multi-Factor portal for web apps
Stars: ✭ 11,094 (+17509.52%)
Mutual labels:  authentication, nginx
Feathers Vue
A boiler plate template using Feathers with Email Verification, Vue 2 with Server Side Rendering, stylus, scss, jade, babel, webpack, ES 6-8, login form, user authorization, and SEO
Stars: ✭ 195 (+209.52%)
Mutual labels:  authentication, nginx
Nginx Http Shibboleth
Shibboleth auth request module for nginx
Stars: ✭ 168 (+166.67%)
Mutual labels:  authentication, nginx
Vouch Proxy
an SSO and OAuth / OIDC login solution for Nginx using the auth_request module
Stars: ✭ 1,239 (+1866.67%)
Mutual labels:  authentication, nginx
External Auth Server
easy auth for reverse proxies
Stars: ✭ 189 (+200%)
Mutual labels:  authentication, nginx
Micro Auth
A microservice that makes adding authentication with Google and Github to your application easy.
Stars: ✭ 466 (+639.68%)
Mutual labels:  authentication, nginx
Nginx Auth Proxy
Authentication for multiple services using nginx
Stars: ✭ 22 (-65.08%)
Mutual labels:  authentication, nginx
Photo Blog
The Photo Blog Application based on Laravel 5 and Vue.js 2 + Prerender
Stars: ✭ 55 (-12.7%)
Mutual labels:  nginx
Vpstoolbox
一键安装Trojan-GFW代理,Hexo博客,Nextcloud等應用程式。
Stars: ✭ 1,080 (+1614.29%)
Mutual labels:  nginx
Chef Openresty
An Opscode Chef cookbook for the OpenResty NGINX bundle
Stars: ✭ 58 (-7.94%)
Mutual labels:  nginx
Mern Stack Authentication
Secure MERN Stack CRUD Web Application using Passport.js Authentication
Stars: ✭ 60 (-4.76%)
Mutual labels:  authentication
Next Authentication
Authentication & Authorization library for the Next.js framework
Stars: ✭ 55 (-12.7%)
Mutual labels:  authentication
Ldap Jwt
Lightweight node.js based web service that provides user authentication against LDAP server (Active Directory / Windows network) credentials and returns a JSON Web Token.
Stars: ✭ 58 (-7.94%)
Mutual labels:  authentication
Fullstack Apollo Express Postgresql Boilerplate
💥 A sophisticated GraphQL with Apollo, Express and PostgreSQL boilerplate project.
Stars: ✭ 1,079 (+1612.7%)
Mutual labels:  authentication
Sudo pair
Plugin for sudo that requires another human to approve and monitor privileged sudo sessions
Stars: ✭ 1,077 (+1609.52%)
Mutual labels:  authentication
Authen
🚦 User Authentication Identifiers for Laravel
Stars: ✭ 53 (-15.87%)
Mutual labels:  authentication
Salte Auth
💻🗝 Authentication for the modern web!
Stars: ✭ 61 (-3.17%)
Mutual labels:  authentication

NginxOmniauthAdapter - Use omniauth for nginx auth_request

Circle CI

Use omniauth for your nginx's authentication via ngx_http_auth_request_module.

NginxOmniauthAdapter provides small Rack app (built with Sinatra) for auth_request.

Prerequisite

  • nginx with ngx_http_auth_request_module

Quick example

$ bundle install

$ cd example/
$ foreman start

http://ngx-auth-test.127.0.0.1.xip.io:18080/

(make sure to have nginx on your PATH)

Usage

Steps

  1. Start adapter app with proper configuration
  2. enable auth_request and add some endpoints on nginx
  • See example/nginx-site.conf for nginx configuration.

Running with Rubygems

# Gemfile
gem 'nginx_omniauth_adapter'

Then write config.ru then deploy it. (see ./config.ru for example)

Using docker

  • Prebuilt: https://quay.io/repository/sorah/nginx_omniauth_adapter
    • Own your risk.
    • They're built at circleci
  • Build manually: checkout this repo and run docker build ..
    • Much safer.
    • But if you can't trust upstream image quay.io/sorah/rbenv:2.2, write your own Dockerfile. This is just a simple Rack app.

Configuration

environment variable is available only on included config.ru (or Docker image).

  • :providers: omniauth provider names.
  • :secret $NGX_OMNIAUTH_SESSION_SECRET: Rack session secret. Should be set when not on dev mode
  • :host $NGX_OMNIAUTH_HOST: URL of adapter. This is used for redirection. Should include protocol (e.g. http://example.com.)
    • If this is not specified, adapter will perform redirect using given Host header.
  • :allowed_app_callback_url $NGX_OMNIAUTH_ALLOWED_APP_CALLBACK_URL (regexp): If specified, URL only matches to this are allowed for app callback url.
  • :allowed_back_to_url $NGX_OMNIAUTH_ALLOWED_BACK_TO_URL (regexp): If specified, URL only matches to this are allowed for back_to url.
  • :app_refresh_interval NGX_OMNIAUTH_APP_REFRESH_INTERVAL (integer): Interval to require refresh session cookie on app domain (in second, default 1 day).
  • :adapter_refresh_interval NGX_OMNIAUTH_ADAPTER_REFRESH_INTERVAL (integer): Interval to require re-logging in on adapter domain (in second, default 3 days).

Included config.ru (or Docker)

You can set configuration via environment variables.

The following variables are only available on included config.ru:

  • $NGX_OMNIAUTH_SESSION_COOKIE_NAME: session cookie name (default ngx_omniauth)
  • $NGX_OMNIAUTH_SESSION_COOKIE_TIMEOUT: session cookie expiry (default 3 days)
  • $NGX_OMNIAUTH_DEV=1 or $RACK_ENV=development
    • enable dev mode (omniauth developer provider)
  • github provider
    • $NGX_OMNIAUTH_GITHUB_KEY, $NGX_OMNIAUTH_GITHUB_SECRET: application key + secret.
    • $NGX_OMNIAUTH_GITHUB_HOST: (optional) Set if you'd like to use GitHub Enterprise instance (e.g. https://YOUR-GITHUB-ENTERPRISE)
    • $NGX_OMNIAUTH_GITHUB_TEAMS: (optional) Restrict to specified teams (e.g. awesomeorganization/owners)
  • google_oauth2 provider
    • $NGX_OMNIAUTH_GOOGLE_KEY, $NGX_OMNIAUTH_GOOGLE_SECRET: oauth2 key + secret.
    • $NGX_OMNIAUTH_GOOGLE_HD: (optional) Restrict to specified hosted domain (Google Apps Domain).

Manually (Rack)

If you're going to write config.ru from scratch, make sure:

  • OmniAuth is included in middleware stack
  • Rack session is enabled in middleware stack

Then run:

run NginxOmniauthAdapter.app(
  providers: %i(developer),
  secret: secret_base64, # optional
  # ... (set more configuration, see above variable list)
)

How it works

  1. browser access to restricted area (where auth_request has enabled)
  2. nginx sends subrequest to /_auth/challenge. It will be proxied to adapter app (GET /test)
  3. adapter app /test returns 401 when request (browser) doesn't have valid cookie
  4. nginx handles 401 with error_page, so do internal redirection (/_auth/initiate)
  5. nginx handles /_auth/initiate. It will be proxied to adapter app GET /initiate.
  • Also nginx passes some information for callback to adapter app.
  • x-ngx-omniauth-initiate-back-to URL to back after logged in
  • x-ngx-omniauth-initiate-callback URL that proxies to adapter app /callback. This must be same domain to backend app for cookie.
  1. adapter app GET /initiate redirects to /auth/:provider.
  2. Browser do some authenticate in adapter app with Omniauth.
  3. adapter app's omniauth callback sets valid session, then redirects to /_auth/callback, where specified at x-ngx-omniauth-initiate-callback.
  • Adapter app gives GET parameter named session on redirect. It contains encrypted session.
  1. nginx handles /_auth/callback. It will be proxied to adapter app /callback.
  • This decrypts given encrypted session string and set to cookie.
  • Then redirect to x-ngx-omniauth-initiate-back-to.
  1. browser backs to URL where attempted to access first, at step 1.
  2. nginx sends auth subrequest to backend app /test.
  3. backend app /test returns 200, because request has valid session cookie.
  4. nginx returns response as usual.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/sorah/nginx_omniauth_adapter.

License

The gem is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].