-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HTTP Basic Auth support for requests.
- Loading branch information
1 parent
16396bf
commit c3580d4
Showing
5 changed files
with
128 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#----------------------------------------------------------------------- | ||
# Example rackup file for an entire stickler stack with authorization | ||
# | ||
# -*- vim: set ft=ruby: -*- | ||
#----------------------------------------------------------------------- | ||
$:.unshift File.expand_path( File.join( File.dirname(__FILE__), "..", "lib" ) ) | ||
|
||
require 'stickler' | ||
|
||
tmp = File.expand_path( File.join( File.dirname( __FILE__ ), "..", "spec", "data" ) ) | ||
|
||
use Rack::Auth::Basic, 'Secure Stickler' do |u,p| | ||
(u == "stickler") and (p == "secret") | ||
end | ||
run Stickler::Server.new( tmp ).app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'addressable/uri' | ||
|
||
module Stickler::Repository | ||
# | ||
# Generate the authentication for basic auth request | ||
# | ||
class BasicAuthenticator | ||
def self.handles?( uri ) | ||
%w[ http https ].include?( uri.scheme ) and uri.user and uri.password | ||
end | ||
|
||
def initialize( uri ) | ||
@user = uri.user | ||
@password = uri.password | ||
@cred = ["#{@user}:#{@password}"].pack('m').tr("\n", '') | ||
end | ||
|
||
def credentials | ||
"Basic #{@cred}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters