Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

faye server with basic access authentication #67

Open
wants to merge 6 commits 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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Add the gem to your Gemfile and run the `bundle` command to install it.

```ruby
gem "private_pub"

# If your faye-server is protected with basic access authentication you can use my fork
# go to the configuration part to get details
gem 'private_pub', :git => 'git://github.com/svenhedin/private_pub.git'


```

Run the generator to create the initial files.
Expand Down Expand Up @@ -108,6 +114,15 @@ The configuration is set separately for each environment in the generated `confi
* `server`: The URL to use for the Faye server such as `http://localhost:9292/faye`.
* `secret_token`: A secret hash to secure the server. Can be any string.
* `signature_expiration`: The length of time in seconds before a subscription signature expires. If this is not set there is no expiration. Note: if Faye is on a separate server from the Rails app, the system clocks must be in sync for the expiration to work properly.
* `basic_auth`: If your faye server is protected with basic access authentication credentials, you have to set the right credentials in your `config/private_pub.yml` file. Remove the basic_auth yaml-block if not necessary...

```yaml
production:
# ...
basic_auth:
user: 'user'
password: 'pass'
```


## How It Works
Expand Down
3 changes: 3 additions & 0 deletions lib/generators/private_pub/templates/private_pub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ production:
server: "http://example.com/faye"
secret_token: "<%= defined?(SecureRandom) ? SecureRandom.hex(32) : ActiveSupport::SecureRandom.hex(32) %>"
signature_expiration: 3600 # one hour
# basic_auth:
# user: 'user'
# password: 'pass'
4 changes: 4 additions & 0 deletions lib/private_pub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def publish_message(message)

form = Net::HTTP::Post.new(url.path.empty? ? '/' : url.path)
form.set_form_data(:message => message.to_json)
raise Error, "No user or password for basic_auth is
specified. If you dont want basic access authentication
remove basic_auth from private_pub.yml." if config[:basic_auth] and (config[:basic_auth]['user'].nil? or config[:basic_auth]['password'].nil?)
form.basic_auth(config[:basic_auth]['user'], config[:basic_auth]['password']) if config[:basic_auth]

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == "https"
Expand Down