Created
December 1, 2010 01:56
-
-
Save dira/722793 to your computer and use it in GitHub Desktop.
OmniAuth strategy for a custom provider
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 characters
| 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 |
i did d same as above u mentioned bt when i hit my apllication's URL i m getting error as undefined method `call' for #<Pixelation
??????
How can I test this strategy?
???
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do we have to get avatar in every oauth2 ? Or this is just an option ?