Created
December 1, 2010 01:56
-
-
Save dira/722793 to your computer and use it in GitHub Desktop.
Revisions
-
dira revised this gist
Jul 12, 2011 . 2 changed files with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,8 @@ # config/initializers/omniauth.rb module OmniAuth module Strategies # tell OmniAuth to load our strategy autoload :Pixelation, 'lib/pixelation_strategy' end end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ # lib/pixelation_strategy.rb require 'omniauth/core' module OmniAuth module Strategies -
dira revised this gist
Dec 2, 2010 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -19,10 +19,7 @@ def request_phase end def callback_phase uid, username, avatar, token = request.params["uid"], request.params["username"], request.params["avatar"], request.params["token"] sha1 = Digest::SHA1.hexdigest("a mix of #{@secret}, #{uid}, #{username}, #{avatar}") # check if the request comes from Pixelation or not -
dira revised this gist
Dec 2, 2010 . 2 changed files with 13 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,13 @@ module OmniAuth module Strategies # tell OmniAuth to load our strategy autoload :Pixelation, 'lib/pixelation_authorization' end end Rails.application.config.middleware.use OmniAuth::Builder do provider :twitter, "app_name", "secret" provider :facebook, "app_name", "secret", :scope => '' # pass the 2 parameters to the constructor provider :pixelation, "secret", "redirect URL" end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,14 +4,14 @@ module Strategies class Pixelation include OmniAuth::Strategy # receive parameters from the strategy declaration and save them def initialize(app, secret, auth_redirect, options = {}) @secret = secret @auth_redirect = auth_redirect super(app, :pixelation, options) end # redirect to the Pixelation website def request_phase r = Rack::Response.new r.redirect @auth_redirect @@ -24,11 +24,10 @@ def callback_phase avatar = request.params["avatar"] token = request.params["token"] sha1 = Digest::SHA1.hexdigest("a mix of #{@secret}, #{uid}, #{username}, #{avatar}") # check if the request comes from Pixelation or not if sha1 == token @uid, @username, @avatar = uid, username, avatar # OmniAuth takes care of the rest super else @@ -37,9 +36,8 @@ def callback_phase end end # normalize user's data according to https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema def auth_hash OmniAuth::Utils.deep_merge(super(), { 'uid' => @uid, 'user_info' => { @@ -51,4 +49,4 @@ def auth_hash end end end end -
dira revised this gist
Dec 1, 2010 . 2 changed files with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ module OmniAuth module Strategies # this strategy is not loaded by default, so specify the path autoload :Pixelation, 'lib/pixelation_authorization' end end Rails.application.config.middleware.use OmniAuth::Builder do provider :twitter, ENV["OAUTH_TWITTER_APP"], ENV["OAUTH_TWITTER_SECRET"] provider :facebook, ENV["OAUTH_FB_APP"], ENV["OAUTH_FB_SECRET"], :scope => '' provider :pixelation, ENV["PIXELATION_SECRET"], ENV["PIXELATION_AUTH_REDIRECT"] end File renamed without changes. -
dira created this gist
Dec 1, 2010 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ require 'omniauth/core' module OmniAuth module Strategies class Pixelation include OmniAuth::Strategy # the last parameter must be an options hash def initialize(app, secret, auth_redirect, options = {}) @secret = secret @auth_redirect = auth_redirect super(app, :pixelation, options) end # redirect to the URL received in initialization def request_phase r = Rack::Response.new r.redirect @auth_redirect r.finish end def callback_phase uid = request.params["uid"] username = request.params["username"] avatar = request.params["avatar"] token = request.params["token"] sha1 = Digest::SHA1.hexdigest("a mix of #{@secret}, #{uid}, #{username}, #{avatar}") # check if it comes from Pixelation or not if sha1 == token @uid = uid @username = username @avatar = avatar # OmniAuth takes care of the rest super else # OmniAuth takes care of the rest fail!(:invalid_credentials) end end # invoked by OmniAuth def auth_hash # must respect https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema OmniAuth::Utils.deep_merge(super(), { 'uid' => @uid, 'user_info' => { 'name' => @username, 'nickname' => @username, 'image' => @avatar } }) end end end end