<commit_before># Heroku Bouncer

Heroku Bouncer is a Rack middleware (implemented in Sinatra) that
requires Heroku OAuth on all requests.

## Demo

[heroku-bouncer-demo](https://github.com/schneems/heroku-bouncer-demo) is a
Sinatra app that uses heroku-bouncer.

## Use

1. Create your OAuth client using `/auth/heroku/callback` as your
   callback endpoint. Use `http://localhost:5000/auth/heroku/callback`
   for local development with Foreman.

    ```sh
    heroku clients:register localhost http://localhost:5000/auth/heroku/callback
    heroku clients:register myapp https://myapp.herokuapp.com/auth/heroku/callback
    ```

2. Set `HEROKU_OAUTH_ID` and `HEROKU_OAUTH_SECRET` in your environment.
3. Set the `COOKIE_SECRET` environment variable to a long random string.
   Otherwise, the OAuth ID and secret are concatenated for use as a secret.
4. Use the middleware.

    **Rack, Sinatra, and Rails 4**

    Add a `use` line to `config.ru`:

    ```ruby
    require ::File.expand_path('../config/environment', __FILE__)

    use ::Heroku::Bouncer
    run Rails.application
    ```

    The middleware does not work properly when configured inside
    Rails 4.

    **Rails 3**

    Add a middleware configuration line to `config/application.rb`:

    ```ruby
    config.middleware.use ::Heroku::Bouncer
    ```

## Options

There are 4 boolean options you can pass to the middleware:

* `herokai_only`: Automatically redirects non-Heroku accounts to
  `www.heroku.com`. Alternatively, pass a valid URL and non-Herokai will<commit_msg>update README: requires a session middleware<commit_after># Heroku Bouncer

Heroku Bouncer is a Rack middleware (implemented in Sinatra) that
requires Heroku OAuth on all requests.

## Demo

[heroku-bouncer-demo](https://github.com/schneems/heroku-bouncer-demo) is a
Sinatra app that uses heroku-bouncer.

## Use

1. Install the Heroku OAuth CLI plugin.

    ```sh
    heroku plugins:install git://github.com/heroku/heroku-oauth.git
    ```

2. Create your OAuth client using `/auth/heroku/callback` as your
   callback endpoint. Use `http://localhost:5000/auth/heroku/callback`
   for local development with Foreman.

    ```sh
    heroku clients:register localhost http://localhost:5000/auth/heroku/callback
    heroku clients:register myapp https://myapp.herokuapp.com/auth/heroku/callback
    ```

3. Set `HEROKU_OAUTH_ID` and `HEROKU_OAUTH_SECRET` in your environment.
4. Set the `COOKIE_SECRET` environment variable to a long random string.
   Otherwise, the OAuth ID and secret are concatenated for use as a secret.
5. Use the middleware as follows:

    **Rack**

    `Heroku::Bouncer` requires a session middleware to be mounted above
    it. Pure Rack apps will need to add such a middleware if they don't
    already have one. In `config.ru`:

    ```ruby
    require 'rack/session/cookie'
    require 'heroku/bouncer'
    require 'my_app'

    # use `openssl rand -base64 32` to generate a secret
    use Rack::Session::Cookie, secret: "..."
    use Heroku::Bouncer
    run MyApp
    ```

    **Sinatra**

    `Heroku::Bouncer` can be run like a Rack app, but since a Sinatra
    app can mount Rack middleware, it may be easier to mount it inside
    the app and use Sinatra's session.

    ```ruby
    class MyApp < Sinatra::Base
      ...
      enable :sessions, secret: "..."
      use ::Heroku::Bouncer
      ...
    ```

    **Rails**

    Add a middleware configuration line to `config/application.rb`:

    ```ruby
    config.middleware.use ::Heroku::Bouncer
    ```

## Options

There are 4 boolean options you can pass to the middleware:

* `herokai_only`: Automatically redirects non-Heroku accounts to
  `www.heroku.com`. Alternatively, pass a valid URL and non-Herokai will
{'fraction_non_alphanumeric': 0.10002674511901578, 'fraction_numerical': 0.009093340465365071, 'mean_word_length': 3.4155844155844157, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2384947', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1160, 'n_words': 401}