在此部分之前,一切正常,这是我的策略类:
module OmniAuth module StrategIEs class MyStrategy < OAuth2 def initialize(app,API_key = nil,secret_key = nil,options = {},&block) clIEnt_options = { :site => CUSTOM_PROVIDER_URL,:authorize_url => "#{CUSTOM_PROVIDER_URL}/auth/my_provIDer/authorize",:token_url => "#{CUSTOM_PROVIDER_URL}/auth/my_provIDer/access_token" } super(app,:onyx_oauth,API_key,secret_key,clIEnt_options,&block) end protected def user_data response = @access_token.get("/auth/my_provIDer/user.Json"); if response.status.to_i == 200 @data ||= MultiJson.decode(response.body); else raise 'Service error' end end def request_phase options[:scope] ||= "read" super end def user_hash user_data end def auth_hash OmniAuth::Utils.deep_merge(super,{ 'uID' => user_data["uID"],'user_info' => user_data['user_info'],'extra' => user_data['extra'] }) end end endend
我要做的是在客户端应用程序中使用登录表单,然后使用我的自定义策略,将这些凭据(电子邮件/密码)发送给提供程序(我通过http_AUTHORIZATION标头思考),以记录用户进入提供程序跳过提供程序中的登录表单,因此在设计验证用户之后,它会通过authorize方法并让整个Oauth2进程继续.
我一直在尝试一些事情,包括在策略中定义方法调用(env),并在调用super之前使用诸如“email:password”之类的凭据设置env [‘http_AUTHORIZATION’].我还在request_phase方法中包含了选项哈希中的’http_AUTHORIZATION’键,甚至也包含在:headers键中.我的最后一次尝试是将它包含在头哈希中,并将其包含在类的客户端对象(OAuth2 :: ClIEnt实例)中的法拉第连接对象中.
几乎调试了整个过程,并尝试将其包含在任何地方,我的提供商始终没有在标题中获得特定的密钥,甚至在Devise测试每个策略时调试提供程序……但毕竟不是运气.
我真的很感激,如果有人告诉我我做错了什么,或者我想要完成的事情是不是以我正在做的方式完成,或者是否有更简单的方法来完成它.
在此先感谢,对于很长的帖子/问题感到抱歉,再次感谢您的时间!
解决方法 我想这可能就是你要找的东西:取自https://github.com/jackdempsey/omniauth-reddit
module OmniAuth module StrategIEs class Reddit < OmniAuth::StrategIEs::OAuth2 #class NoAuthorizationCodeError < StandardError; end option :name,"reddit" option :authorize_options,[:scope,:duration] option :clIEnt_options,{ site: 'https://oauth.reddit.com',token_url: 'https://ssl.reddit.com/API/v1/access_token' } uID { raw_info['ID'] } info do { name: raw_info['name'] } end extra do {'raw_info' => raw_info} end def raw_info @raw_info ||= access_token.get('/API/v1/me').parsed || {} end def build_access_token options.token_params.merge!(:headers => {'Authorization' => basic_auth_header }) super end def basic_auth_header "Basic " + Base64.strict_encode64("#{options[:clIEnt_ID]}:#{options[:clIEnt_secret]}") end MOBILE_USER_AGENTS = 'webos|ipod|iphone|mobile' def request_phase options[:clIEnt_options].authorize_url = mobile_request? ? 'https://ssl.reddit.com/API/v1/authorize.compact' : 'https://ssl.reddit.com/API/v1/authorize' super end def mobile_request? ua = Rack::Request.new(@env).user_agent.to_s ua.downcase =~ Regexp.new(MOBILE_USER_AGENTS) end end endend总结
以上是内存溢出为你收集整理的ruby-on-rails-3 – 如何在使用者中使用omniauth和oauth2注入http_authorization头,以便在提供者中进行身份验证?全部内容,希望文章能够帮你解决ruby-on-rails-3 – 如何在使用者中使用omniauth和oauth2注入http_authorization头,以便在提供者中进行身份验证?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)