forked from omniauth/omniauth
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Bleigh
committed
Apr 4, 2010
1 parent
a9ef697
commit 9b5ce21
Showing
8 changed files
with
64 additions
and
6 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
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
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,44 @@ | ||
require 'digest/sha1' | ||
module OmniAuth | ||
module Strategies | ||
class Password | ||
include OmniAuth::Strategy | ||
|
||
def initialize(app, secret = 'changethisappsecret', options = {}) | ||
@options = options | ||
@options[:identifier_key] ||= 'nickname' | ||
@secret = secret | ||
super(app, :password) | ||
end | ||
|
||
attr_reader :secret | ||
|
||
def request_phase | ||
return fail!(:missing_information) unless request[:identifier] && request[:password] | ||
return fail!(:password_mismatch) if request[:password_confirmation] && request[:password_confirmation] != '' && request[:password] != request[:password_confirmation] | ||
|
||
env['REQUEST_METHOD'] = 'GET' | ||
env['PATH_INFO'] = request.path + '/callback' | ||
request['auth'] = auth_hash(encrypt(request[:identifier], request[:password])) | ||
@app.call(env) | ||
end | ||
|
||
def auth_hash(crypted_password) | ||
OmniAuth::Utils.deep_merge(super(), { | ||
'uid' => crypted_password, | ||
'user_info' => { | ||
@options[:identifier_key] => request[:identifier] | ||
} | ||
}) | ||
end | ||
|
||
def callback_phase | ||
@app.call(env) | ||
end | ||
|
||
def encrypt(identifier, password) | ||
Digest::SHA1.hexdigest([identifier, password, secret].join('::')) | ||
end | ||
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
Empty file.
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,13 @@ | ||
require File.dirname(__FILE__) + '/../../spec_helper' | ||
|
||
describe OmniAuth::Strategies::Password do | ||
before(:each) do | ||
FakeAdapter.reset! | ||
end | ||
|
||
it do | ||
FakeAdapter.authenticate('mbleigh','dude').should be_false | ||
FakeAdapter.register('mbleigh','dude') | ||
FakeAdapter.authenticate('mbleigh','dude').should be_true | ||
end | ||
end |