gpt4 book ai didi

ruby-on-rails - request.env ['omniauth.auth' ] 在 Ruby on Rails 中为零

转载 作者:行者123 更新时间:2023-12-02 13:48:47 25 4
gpt4 key购买 nike

我尝试将数据从 Rails 应用程序导出到 Google 日历,但登录后我无法在 request.env 中找到“omniauth.auth”。

我使用 Rails 4.0.4 和 Ruby 2.0.0p481

我的 gem 文件

gem 'google-api-client', '~> 0.7.1', :require => 'google/api_client'
gem 'omniauth', '~> 1.2.1'
gem 'omniauth-google-oauth2', '~> 0.2.4'

omniauth.rb

OmniAuth.config.full_host = "http://localhost:3000"
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, 'MY_GOOGLE_CLIENT_ID', 'MY_GOOGLE_SECRET', { :access_type => 'offline', :prompt => 'consent', :approval_prompt => 'force', :scope => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/calendar', :redirect_uri => 'http://localhost:3000/auth/google-oauth2/callback', }
end

Controller

class GoogleAuthController < ApplicationController
def create
@auth = request.env['omniauth.auth'] #here not found 'omniath.auth' and @auth is nil

if @auth.nil?
flash[:danger] = "Error during connection with Google API."
redirect_to holidays_path
else
@token = @auth['credential']['token']
#another action after login
end
end
end

路线

match "/auth/:provider/callback", to: "google_auth#create", via: 'get'

Google apis (I cannot add a image, )

如果您能帮助解决这个问题,我将非常感激。

编辑:

请求.env

{"GATEWAY_INTERFACE"=>"CGI/1.1", "PATH_INFO"=>"/auth/google-oauth2/callback", "QUERY_STRING"=>"state=fc29151421330cb904b4c4984bdd52e21a53d98531389b74&code=4/mi7TtHWcFpyMeeA-ikQHb6dV5Qki.grzx2bQTFb8dYFZr95uygvVpKDFKjgI", "REMOTE_ADDR"=>"127.0.0.1", "REMOTE_HOST"=>"127.0.0.1", "REQUEST_METHOD"=>"GET", "REQUEST_URI"=>"http://localhost:3000/auth/google-oauth2/callback?state=fc29151421330cb904b4c4984bdd52e21a53d98531389b74&code=4/mi7TtHWcFpyMeeA-ikQHb6dV5Qki.grzx2bQTFb8dYFZr95uygvVpKDFKjgI", "SCRIPT_NAME"=>"", "SERVER_NAME"=>"localhost", "SERVER_PORT"=>"3000", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/2.0.0/2014-05-08)", "HTTP_HOST"=>"localhost:3000", "HTTP_USER_AGENT"=>"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0", "HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "HTTP_ACCEPT_LANGUAGE"=>"en-gb,pl;q=0.5", "HTTP_ACCEPT_ENCODING"=>"gzip, deflate", "HTTP_DNT"=>"1", "HTTP_COOKIE"=>"csrftoken=SlECAmtvbK9jqvqpS6D8nf2YMNdgGvnQ; holidays_view=list; logged_to_google=false; remember_token=EjYlew0u1zVPf21OfDA5hw; _HolidayManager_session=Zm43QVVrd2dKSkFLbnUvZnZLYzlhTVZ6QVNISDErYU5wVzg4ek90dFFoVXVZUHlpb1c3Q2NldGV1R05IellhbHNTYS92TFlLK1dMK3drR3p2bldXejVlbTJGaktnTXNyZWkzdnVJd05PQ3dyb0R0bndjeFV5S01CL1hybFVITzZRM1lqZWxGa1FFQnJ0ektWZUpwNlV2MnNnU3p2OVR2WnE0ME11aDNJZDNLekZSNm85MU9ZdWhZWVlGL0Y3dGdTS0E2NjI4Zk5EQ3Y5WHI1MWRUaC9JSEFwYjNpbkNtMmZ5RTdRWTF5ak1kQ2E5T1hwcFMzczRYZHpjYkxKNldxdzJDZDhreFNqWW9ySGhnNU02dmNwSzlQaUJDbVQrN2FhcFpQYzNHWWQ4OVp2VlVFTFAzQ1hLUWZ2aEJpUkg0Y3g0citJK3pMcU1VdUpNOEJxWTFhRGtMVEdhQVEyUGhxMzRmNytVUEczTmw3SEJQdk94dGZtUysvYVI1M3pjUTFlMmYxVGdFL0UrME5nTXNWblU5V0gvZzViMEJKSUhtbmRlZUo4RnB6VWkzQlBMaHlUYUZhY2xBZTg0TUxtdW44Zy0teUVlY1Y5bXNDRi9XdGxPWWIyNmsyQT09--7c4d0f8a5be4c25d7fbc8f9922425f267d7c9c10", "HTTP_CONNECTION"=>"keep-alive", "HTTP_CACHE_CONTROL"=>"max-age=0", "rack.version"=>[1, 2], "rack.input"=>#<StringIO:0x007fd805127750>, "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>false, "rack.multiprocess"=>false, "rack.run_once"=>false, "rack.url_scheme"=>"http", "HTTP_VERSION"=>"HTTP/1.1", "REQUEST_PATH"=>"/auth/google-oauth2/callback", "ORIGINAL_FULLPATH"=>"/auth/google-oauth2/callback?state=fc29151421330cb904b4c4984bdd52e21a53d98531389b74&code=4/mi7TtHWcFpyMeeA-ikQHb6dV5Qki.grzx2bQTFb8dYFZr95uygvVpKDFKjgI", "ORIGINAL_SCRIPT_NAME"=>"", "action_dispatch.routes"=>#<ActionDispatch::Routing::RouteSet:0x00000002d54308>, "action_dispatch.parameter_filter"=>[:password], "action_dispatch.redirect_filter"=>[], "action_dispatch.secret_token"=>nil, "action_dispatch.secret_key_base"=>"d4b9400cc11ac95836a873c775f9597d9d6428bb4a3d82e3723da38bf04914735397b697d45dbeb6fa4b1a8719c6f87b2e333510d316e1a0f4b1ad40eecf0f8a", "action_dispatch.show_exceptions"=>true, "action_dispatch.show_detailed_exceptions"=>true, "action_dispatch.logger"=>#<Logger:0x000000012f8658 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x000000012f83d8 @datetime_format=nil>, @formatter=#<ActiveSupport::Logger::SimpleFormatter:0x000000012ff2f0 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x000000012fcfc8 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x000000012fd810 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x000000012fee40>>>>, "action_dispatch.backtrace_cleaner"=>#<Rails::BacktraceCleaner:0x0000000427c168 @filters=[#<Proc:0x0000000428bac8@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/railties-4.0.4/lib/rails/backtrace_cleaner.rb:10>, #<Proc:0x0000000428baa0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/railties-4.0.4/lib/rails/backtrace_cleaner.rb:11>, #<Proc:0x0000000428ba78@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/railties-4.0.4/lib/rails/backtrace_cleaner.rb:12>, #<Proc:0x000000042896b0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/railties-4.0.4/lib/rails/backtrace_cleaner.rb:24>], @silencers=[#<Proc:0x00000004289570@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/railties-4.0.4/lib/rails/backtrace_cleaner.rb:15>]>, "action_dispatch.key_generator"=>#<ActiveSupport::CachingKeyGenerator:0x000000042893e0 @key_generator=#<ActiveSupport::KeyGenerator:0x00000004289408 @secret="d4b9400cc11ac95836a873c775f9597d9d6428bb4a3d82e3723da38bf04914735397b697d45dbeb6fa4b1a8719c6f87b2e333510d316e1a0f4b1ad40eecf0f8a", @iterations=1000>, @cache_keys=#<ThreadSafe::Cache:0x000000042893b8 @backend={"encrypted cookie64"=>"+&\x1E\x8D7h\x00l_3Z\x02\xCEYU\xE5\xD1\xAC-\xD7z\xE3\xF2\xD8\xA6Pn\x96\x84Cx\xDE\x98Z\xC5\x80js\xF7\xF8q\x04s\b\xCFf\x96v\x98~\xED\x9C\x11\xDE\xC1\xD8\x1Dz\x1DS\x12\xA4\xDF<", "signed encrypted cookie64"=>"\x86\xD9\xEC\xFFu\xE9\xA2\xC7z\xD8\x990\xDE+#s\xC1\x1E$\x1E;Jd\x8B\xA2\x9A\xB9\x05>\x01\xF5\xB6\x0E\xC0\x10\xD9\xD5\xF7\xBA[$\xC9m\xE65<}D\xA0b\xE7\xE8y\xCA6\x1F\x02\xA3S\x1F[\xFEk\xD1"}, @default_proc=nil>>, "action_dispatch.http_auth_salt"=>"http authentication", "action_dispatch.signed_cookie_salt"=>"signed cookie", "action_dispatch.encrypted_cookie_salt"=>"encrypted cookie", "action_dispatch.encrypted_signed_cookie_salt"=>"signed encrypted cookie", "ROUTES_23765380_SCRIPT_NAME"=>"", "action_dispatch.request_id"=>"bf2e900d-3cc9-4a21-88cf-12a2fdcbcc09", "action_dispatch.remote_ip"=>#<ActionDispatch::RemoteIp::GetIp:0x007fd805124d20 @env={...}, @check_ip=true, @proxies=/
^127\.0\.0\.1$ | # localhost IPv4
^::1$ | # localhost IPv6
^fc00: | # private IPv6 range fc00
^10\. | # private IPv4 range 10.x.x.x
^172\.(1[6-9]|2[0-9]|3[0-1])\.| # private IPv4 range 172.16.0.0 .. 172.31.255.255
^192\.168\. # private IPv4 range 192.168.x.x
/x>, "rack.session"=>#<ActionDispatch::Request::Session:0x007fd7f813b2d0 @by=#<ActionDispatch::Session::CookieStore:0x00000003db62f0 @app=#<ActionDispatch::Flash:0x00000003db6390 @app=#<ActionDispatch::ParamsParser:0x00000003db67a0 @app=#<Rack::Head:0x00000003db67c8 @app=#<Rack::ConditionalGet:0x00000003db67f0 @app=#<Rack::ETag:0x00000003db6818 @app=#<OmniAuth::Builder:0x00000003db7df8 @options=nil, @run=#<ActionDispatch::Routing::RouteSet:0x00000002d54308>, @map=nil, @use=[#<Proc:0x00000003db7420@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/rack-1.5.2/lib/rack/builder.rb:86>, #<Proc:0x00000003db6890@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/rack-1.5.2/lib/rack/builder.rb:86>]>, @cache_control="max-age=0, private, must-revalidate", @no_cache_control="no-cache">>>, @parsers={#<Mime::Type:0x00000002c92e60 @synonyms=["text/x-json", "application/jsonrequest"], @symbol=:json, @string="application/json">=>:json}>>, @default_options={:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :defer=>false, :renew=>false}, @key="_HolidayManager_session", @cookie_only=true>, @env={...}, @delegate={"session_id"=>"465d10f227d1b1033088b17f3aa77cb3", "_csrf_token"=>"SghTPesnhyoSKhA2yFhM4d20/KjqIPixcFUSCpn5jX4=", "omniauth.params"=>{}, "omniauth.state"=>"fc29151421330cb904b4c4984bdd52e21a53d98531389b74", "flash"=>{"discard"=>[:danger], "flashes"=>{:danger=>"Error during connection with Google API."}}}, @loaded=true, @exists=true>, "rack.session.options"=>#<ActionDispatch::Request::Session::Options:0x007fd7f813b280 @by=#<ActionDispatch::Session::CookieStore:0x00000003db62f0 @app=#<ActionDispatch::Flash:0x00000003db6390 @app=#<ActionDispatch::ParamsParser:0x00000003db67a0 @app=#<Rack::Head:0x00000003db67c8 @app=#<Rack::ConditionalGet:0x00000003db67f0 @app=#<Rack::ETag:0x00000003db6818 @app=#<OmniAuth::Builder:0x00000003db7df8 @options=nil, @run=#<ActionDispatch::Routing::RouteSet:0x00000002d54308>, @map=nil, @use=[#<Proc:0x00000003db7420@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/rack-1.5.2/lib/rack/builder.rb:86>, #<Proc:0x00000003db6890@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/rack-1.5.2/lib/rack/builder.rb:86>]>, @cache_control="max-age=0, private, must-revalidate", @no_cache_control="no-cache">>>, @parsers={#<Mime::Type:0x00000002c92e60 @synonyms=["text/x-json", "application/jsonrequest"], @symbol=:json, @string="application/json">=>:json}>>, @default_options={:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :defer=>false, :renew=>false}, @key="_HolidayManager_session", @cookie_only=true>, @env={...}, @delegate={:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :defer=>false, :renew=>false, :id=>"465d10f227d1b1033088b17f3aa77cb3"}>, "action_dispatch.request.path_parameters"=>{:controller=>"google_auth", :action=>"create", :provider=>"google-oauth2"}, "action_controller.instance"=>#<GoogleAuthController:0x007fd7f813db70 @_routes=nil, @_action_has_layout=true, @_headers={"Content-Type"=>"text/html"}, @_status=200, @_request=#<ActionDispatch::Request:0x007fd7f813da58 @env={...}, @symbolized_path_params=nil, @filtered_parameters={"state"=>"fc29151421330cb904b4c4984bdd52e21a53d98531389b74", "code"=>"4/mi7TtHWcFpyMeeA-ikQHb6dV5Qki.grzx2bQTFb8dYFZr95uygvVpKDFKjgI", "controller"=>"google_auth", "action"=>"create", "provider"=>"google-oauth2"}, @filtered_env=nil, @filtered_path=nil, @protocol=nil, @port=nil, @method="GET", @request_method="GET", @remote_ip=nil, @original_fullpath=nil, @fullpath="/auth/google-oauth2/callback?state=fc29151421330cb904b4c4984bdd52e21a53d98531389b74&code=4/mi7TtHWcFpyMeeA-ikQHb6dV5Qki.grzx2bQTFb8dYFZr95uygvVpKDFKjgI", @ip=nil, @uuid=nil>, @_response=#<ActionDispatch::Response:0x007fd7f813da30 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x007fd7f813d990>, @stream=#<ActionDispatch::Response::Buffer:0x007fd7f813d8f0 @response=#<ActionDispatch::Response:0x007fd7f813da30 ...>, @buf=[], @closed=false>, @header={"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff", "X-UA-Compatible"=>"chrome=1"}, @status=200, @sending_file=false, @blank=false, @cv=#<MonitorMixin::ConditionVariable:0x007fd7f813d8c8 @monitor=#<ActionDispatch::Response:0x007fd7f813da30 ...>, @cond=#<ConditionVariable:0x007fd7f813d8a0 @waiters={}, @waiters_mutex=#<Mutex:0x007fd7f813d850>>>, @committed=false, @content_type=nil, @charset=nil, @cache_control={}, @etag=nil, @request=#<ActionDispatch::Request:0x007fd7f813da58 @env={...}, @symbolized_path_params=nil, @filtered_parameters={"state"=>"fc29151421330cb904b4c4984bdd52e21a53d98531389b74", "code"=>"4/mi7TtHWcFpyMeeA-ikQHb6dV5Qki.grzx2bQTFb8dYFZr95uygvVpKDFKjgI", "controller"=>"google_auth", "action"=>"create", "provider"=>"google-oauth2"}, @filtered_env=nil, @filtered_path=nil, @protocol=nil, @port=nil, @method="GET", @request_method="GET", @remote_ip=nil, @original_fullpath=nil, @fullpath="/auth/google-oauth2/callback?state=fc29151421330cb904b4c4984bdd52e21a53d98531389b74&code=4/mi7TtHWcFpyMeeA-ikQHb6dV5Qki.grzx2bQTFb8dYFZr95uygvVpKDFKjgI", @ip=nil, @uuid=nil>>, @_env={...}, @_prefixes=["google_auth", "application"], @_lookup_context=#<ActionView::LookupContext:0x007fd7f813d670 @details_key=nil, @details={:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}, @skip_default_locale=false, @cache=true, @prefixes=["google_auth", "application"], @rendered_format=nil, @view_paths=#<ActionView::PathSet:0x007fd7f813d5f8 @paths=[#<ActionView::OptimizedFileSystemResolver:0x000000040e0bd8 @pattern=":prefix/:action{.:locale,}{.:formats,}{.:handlers,}", @cache=#<ActionView::Resolver::Cache:0x000000040e0bb0 @data=#<ActionView::Resolver::Cache::SmallCache:0x000000040e0b88 @backend={#<ActionView::LookupContext::DetailsKey:0x0000000392d6c0 @hash=-2472005154318598025>=>#<ActionView::Resolver::Cache::SmallCache:0x0000000394bee0 @backend={"create"=>#<ActionView::Resolver::Cache::SmallCache:0x0000000394bbe8 @backend={"google_auth"=>#<ActionView::Resolver::Cache::SmallCache:0x0000000394b8a0 @backend={false=>#<ActionView::Resolver::Cache::SmallCache:0x0000000394b440 @backend={[]=>[app/views/google_auth/create.html.erb]}, @default_proc=nil>}, @default_proc=#<Proc:0x000000036d35f0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:45 (lambda)>>}, @default_proc=#<Proc:0x000000036d33c0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:46 (lambda)>>, "google_auth"=>#<ActionView::Resolver::Cache::SmallCache:0x00000003958bb8 @backend={"layouts"=>#<ActionView::Resolver::Cache::SmallCache:0x00000003961a88 @backend={false=>#<ActionView::Resolver::Cache::SmallCache:0x00000003963810 @backend={}, @default_proc=nil>}, @default_proc=#<Proc:0x000000036d35f0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:45 (lambda)>>}, @default_proc=#<Proc:0x000000036d33c0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:46 (lambda)>>, "application"=>#<ActionView::Resolver::Cache::SmallCache:0x00000003966f60 @backend={"layouts"=>#<ActionView::Resolver::Cache::SmallCache:0x00000003966e70 @backend={false=>#<ActionView::Resolver::Cache::SmallCache:0x00000003966b78 @backend={[]=>[app/views/layouts/application.html.erb]}, @default_proc=nil>}, @default_proc=#<Proc:0x000000036d35f0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:45 (lambda)>>}, @default_proc=#<Proc:0x000000036d33c0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:46 (lambda)>>, "navbar"=>#<ActionView::Resolver::Cache::SmallCache:0x007fd804e326d0 @backend={"layouts"=>#<ActionView::Resolver::Cache::SmallCache:0x007fd804e325e0 @backend={true=>#<ActionView::Resolver::Cache::SmallCache:0x007fd804e324f0 @backend={[]=>[app/views/layouts/_navbar.html.erb]}, @default_proc=nil>}, @default_proc=#<Proc:0x000000036d35f0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:45 (lambda)>>}, @default_proc=#<Proc:0x000000036d33c0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:46 (lambda)>>, "footer"=>#<ActionView::Resolver::Cache::SmallCache:0x007fd8050e52d8 @backend={"layouts"=>#<ActionView::Resolver::Cache::SmallCache:0x007fd8050e51e8 @backend={true=>#<ActionView::Resolver::Cache::SmallCache:0x007fd8050e50f8 @backend={[]=>[app/views/layouts/_footer.html.erb]}, @default_proc=nil>}, @default_proc=#<Proc:0x000000036d35f0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:45 (lambda)>>}, @default_proc=#<Proc:0x000000036d33c0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:46 (lambda)>>, "index"=>#<ActionView::Resolver::Cache::SmallCache:0x00000004243228 @backend={"holidays"=>#<ActionView::Resolver::Cache::SmallCache:0x00000004243138 @backend={false=>#<ActionView::Resolver::Cache::SmallCache:0x00000004242fd0 @backend={[]=>[app/views/holidays/index.html.erb]}, @default_proc=nil>}, @default_proc=#<Proc:0x000000036d35f0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:45 (lambda)>>}, @default_proc=#<Proc:0x000000036d33c0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:46 (lambda)>>, "holidays"=>#<ActionView::Resolver::Cache::SmallCache:0x00000004241d10 @backend={"layouts"=>#<ActionView::Resolver::Cache::SmallCache:0x00000004241bd0 @backend={false=>#<ActionView::Resolver::Cache::SmallCache:0x00000004241ab8 @backend={}, @default_proc=nil>}, @default_proc=#<Proc:0x000000036d35f0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:45 (lambda)>>}, @default_proc=#<Proc:0x000000036d33c0@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:46 (lambda)>>}, @default_proc=#<Proc:0x000000036d3398@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:47 (lambda)>>}, @default_proc=#<Proc:0x000000036d3348@/home/damian/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.4/lib/action_view/template/resolver.rb:48 (lambda)>>>, @path="/home/damian/i4b/HolidayManager/branches/googleapis/HolidayManager/app/views">]>>, @_action_name="create", @_response_body=nil, @_config={}, @auth=nil, @result={...}>, "action_dispatch.request.content_type"=>nil, "action_dispatch.request.request_parameters"=>{}, "rack.request.query_string"=>"state=fc29151421330cb904b4c4984bdd52e21a53d98531389b74&code=4/mi7TtHWcFpyMeeA-ikQHb6dV5Qki.grzx2bQTFb8dYFZr95uygvVpKDFKjgI", "rack.request.query_hash"=>{"state"=>"fc29151421330cb904b4c4984bdd52e21a53d98531389b74", "code"=>"4/mi7TtHWcFpyMeeA-ikQHb6dV5Qki.grzx2bQTFb8dYFZr95uygvVpKDFKjgI"}, "action_dispatch.request.query_parameters"=>{"state"=>"fc29151421330cb904b4c4984bdd52e21a53d98531389b74", "code"=>"4/mi7TtHWcFpyMeeA-ikQHb6dV5Qki.grzx2bQTFb8dYFZr95uygvVpKDFKjgI"}, "action_dispatch.request.parameters"=>{"state"=>"fc29151421330cb904b4c4984bdd52e21a53d98531389b74", "code"=>"4/mi7TtHWcFpyMeeA-ikQHb6dV5Qki.grzx2bQTFb8dYFZr95uygvVpKDFKjgI", "controller"=>"google_auth", "action"=>"create", "provider"=>"google-oauth2"}, "action_dispatch.request.formats"=>[#<Mime::Type:0x00000002c7e2f8 @synonyms=["application/xhtml+xml"], @symbol=:html, @string="text/html">], "rack.request.cookie_hash"=>{"csrftoken"=>"SlECAmtvbK9jqvqpS6D8nf2YMNdgGvnQ", "holidays_view"=>"list", "logged_to_google"=>"false", "remember_token"=>"EjYlew0u1zVPf21OfDA5hw", "_HolidayManager_session"=>"Zm43QVVrd2dKSkFLbnUvZnZLYzlhTVZ6QVNISDErYU5wVzg4ek90dFFoVXVZUHlpb1c3Q2NldGV1R05IellhbHNTYS92TFlLK1dMK3drR3p2bldXejVlbTJGaktnTXNyZWkzdnVJd05PQ3dyb0R0bndjeFV5S01CL1hybFVITzZRM1lqZWxGa1FFQnJ0ektWZUpwNlV2MnNnU3p2OVR2WnE0ME11aDNJZDNLekZSNm85MU9ZdWhZWVlGL0Y3dGdTS0E2NjI4Zk5EQ3Y5WHI1MWRUaC9JSEFwYjNpbkNtMmZ5RTdRWTF5ak1kQ2E5T1hwcFMzczRYZHpjYkxKNldxdzJDZDhreFNqWW9ySGhnNU02dmNwSzlQaUJDbVQrN2FhcFpQYzNHWWQ4OVp2VlVFTFAzQ1hLUWZ2aEJpUkg0Y3g0citJK3pMcU1VdUpNOEJxWTFhRGtMVEdhQVEyUGhxMzRmNytVUEczTmw3SEJQdk94dGZtUysvYVI1M3pjUTFlMmYxVGdFL0UrME5nTXNWblU5V0gvZzViMEJKSUhtbmRlZUo4RnB6VWkzQlBMaHlUYUZhY2xBZTg0TUxtdW44Zy0teUVlY1Y5bXNDRi9XdGxPWWIyNmsyQT09--7c4d0f8a5be4c25d7fbc8f9922425f267d7c9c10"}, "rack.request.cookie_string"=>"csrftoken=SlECAmtvbK9jqvqpS6D8nf2YMNdgGvnQ; holidays_view=list; logged_to_google=false; remember_token=EjYlew0u1zVPf21OfDA5hw; _HolidayManager_session=Zm43QVVrd2dKSkFLbnUvZnZLYzlhTVZ6QVNISDErYU5wVzg4ek90dFFoVXVZUHlpb1c3Q2NldGV1R05IellhbHNTYS92TFlLK1dMK3drR3p2bldXejVlbTJGaktnTXNyZWkzdnVJd05PQ3dyb0R0bndjeFV5S01CL1hybFVITzZRM1lqZWxGa1FFQnJ0ektWZUpwNlV2MnNnU3p2OVR2WnE0ME11aDNJZDNLekZSNm85MU9ZdWhZWVlGL0Y3dGdTS0E2NjI4Zk5EQ3Y5WHI1MWRUaC9JSEFwYjNpbkNtMmZ5RTdRWTF5ak1kQ2E5T1hwcFMzczRYZHpjYkxKNldxdzJDZDhreFNqWW9ySGhnNU02dmNwSzlQaUJDbVQrN2FhcFpQYzNHWWQ4OVp2VlVFTFAzQ1hLUWZ2aEJpUkg0Y3g0citJK3pMcU1VdUpNOEJxWTFhRGtMVEdhQVEyUGhxMzRmNytVUEczTmw3SEJQdk94dGZtUysvYVI1M3pjUTFlMmYxVGdFL0UrME5nTXNWblU5V0gvZzViMEJKSUhtbmRlZUo4RnB6VWkzQlBMaHlUYUZhY2xBZTg0TUxtdW44Zy0teUVlY1Y5bXNDRi9XdGxPWWIyNmsyQT09--7c4d0f8a5be4c25d7fbc8f9922425f267d7c9c10", "action_dispatch.cookies"=>#<ActionDispatch::Cookies::CookieJar:0x007fd7ec19a638 @key_generator=#<ActiveSupport::CachingKeyGenerator:0x000000042893e0 @key_generator=#<ActiveSupport::KeyGenerator:0x00000004289408 @secret="d4b9400cc11ac95836a873c775f9597d9d6428bb4a3d82e3723da38bf04914735397b697d45dbeb6fa4b1a8719c6f87b2e333510d316e1a0f4b1ad40eecf0f8a", @iterations=1000>, @cache_keys=#<ThreadSafe::Cache:0x000000042893b8 @backend={"encrypted cookie64"=>"+&\x1E\x8D7h\x00l_3Z\x02\xCEYU\xE5\xD1\xAC-\xD7z\xE3\xF2\xD8\xA6Pn\x96\x84Cx\xDE\x98Z\xC5\x80js\xF7\xF8q\x04s\b\xCFf\x96v\x98~\xED\x9C\x11\xDE\xC1\xD8\x1Dz\x1DS\x12\xA4\xDF<", "signed encrypted cookie64"=>"\x86\xD9\xEC\xFFu\xE9\xA2\xC7z\xD8\x990\xDE+#s\xC1\x1E$\x1E;Jd\x8B\xA2\x9A\xB9\x05>\x01\xF5\xB6\x0E\xC0\x10\xD9\xD5\xF7\xBA[$\xC9m\xE65<}D\xA0b\xE7\xE8y\xCA6\x1F\x02\xA3S\x1F[\xFEk\xD1"}, @default_proc=nil>>, @set_cookies={"request_method"=>{:value=>"GET", :path=>"/"}}, @delete_cookies={}, @host="localhost", @secure=false, @options={:signed_cookie_salt=>"signed cookie", :encrypted_cookie_salt=>"encrypted cookie", :encrypted_signed_cookie_salt=>"signed encrypted cookie", :secret_token=>nil, :secret_key_base=>"d4b9400cc11ac95836a873c775f9597d9d6428bb4a3d82e3723da38bf04914735397b697d45dbeb6fa4b1a8719c6f87b2e333510d316e1a0f4b1ad40eecf0f8a", :upgrade_legacy_signed_cookies=>false}, @cookies={"csrftoken"=>"SlECAmtvbK9jqvqpS6D8nf2YMNdgGvnQ", "holidays_view"=>"list", "logged_to_google"=>"false", "remember_token"=>"EjYlew0u1zVPf21OfDA5hw", "_HolidayManager_session"=>"Zm43QVVrd2dKSkFLbnUvZnZLYzlhTVZ6QVNISDErYU5wVzg4ek90dFFoVXVZUHlpb1c3Q2NldGV1R05IellhbHNTYS92TFlLK1dMK3drR3p2bldXejVlbTJGaktnTXNyZWkzdnVJd05PQ3dyb0R0bndjeFV5S01CL1hybFVITzZRM1lqZWxGa1FFQnJ0ektWZUpwNlV2MnNnU3p2OVR2WnE0ME11aDNJZDNLekZSNm85MU9ZdWhZWVlGL0Y3dGdTS0E2NjI4Zk5EQ3Y5WHI1MWRUaC9JSEFwYjNpbkNtMmZ5RTdRWTF5ak1kQ2E5T1hwcFMzczRYZHpjYkxKNldxdzJDZDhreFNqWW9ySGhnNU02dmNwSzlQaUJDbVQrN2FhcFpQYzNHWWQ4OVp2VlVFTFAzQ1hLUWZ2aEJpUkg0Y3g0citJK3pMcU1VdUpNOEJxWTFhRGtMVEdhQVEyUGhxMzRmNytVUEczTmw3SEJQdk94dGZtUysvYVI1M3pjUTFlMmYxVGdFL0UrME5nTXNWblU5V0gvZzViMEJKSUhtbmRlZUo4RnB6VWkzQlBMaHlUYUZhY2xBZTg0TUxtdW44Zy0teUVlY1Y5bXNDRi9XdGxPWWIyNmsyQT09--7c4d0f8a5be4c25d7fbc8f9922425f267d7c9c10", "request_method"=>"GET"}, @encrypted=#<ActionDispatch::Cookies::EncryptedCookieJar:0x007fd7ec198e00 @parent_jar=#<ActionDispatch::Cookies::CookieJar:0x007fd7ec19a638 ...>, @options={:signed_cookie_salt=>"signed cookie", :encrypted_cookie_salt=>"encrypted cookie", :encrypted_signed_cookie_salt=>"signed encrypted cookie", :secret_token=>nil, :secret_key_base=>"d4b9400cc11ac95836a873c775f9597d9d6428bb4a3d82e3723da38bf04914735397b697d45dbeb6fa4b1a8719c6f87b2e333510d316e1a0f4b1ad40eecf0f8a", :upgrade_legacy_signed_cookies=>false}, @encryptor=#<ActiveSupport::MessageEncryptor:0x007fd7ec198cc0 @secret="+&\x1E\x8D7h\x00l_3Z\x02\xCEYU\xE5\xD1\xAC-\xD7z\xE3\xF2\xD8\xA6Pn\x96\x84Cx\xDE\x98Z\xC5\x80js\xF7\xF8q\x04s\b\xCFf\x96v\x98~\xED\x9C\x11\xDE\xC1\xD8\x1Dz\x1DS\x12\xA4\xDF<", @sign_secret="\x86\xD9\xEC\xFFu\xE9\xA2\xC7z\xD8\x990\xDE+#s\xC1\x1E$\x1E;Jd\x8B\xA2\x9A\xB9\x05>\x01\xF5\xB6\x0E\xC0\x10\xD9\xD5\xF7\xBA[$\xC9m\xE65<}D\xA0b\xE7\xE8y\xCA6\x1F\x02\xA3S\x1F[\xFEk\xD1", @cipher="aes-256-cbc", @verifier=#<ActiveSupport::MessageVerifier:0x007fd7ec198bd0 @secret="\x86\xD9\xEC\xFFu\xE9\xA2\xC7z\xD8\x990\xDE+#s\xC1\x1E$\x1E;Jd\x8B\xA2\x9A\xB9\x05>\x01\xF5\xB6\x0E\xC0\x10\xD9\xD5\xF7\xBA[$\xC9m\xE65<}D\xA0b\xE7\xE8y\xCA6\x1F\x02\xA3S\x1F[\xFEk\xD1", @digest="SHA1", @serializer=ActiveSupport::MessageEncryptor::NullSerializer>, @serializer=Marshal>>, @signed_or_encrypted=#<ActionDispatch::Cookies::EncryptedCookieJar:0x007fd7ec198e00 @parent_jar=#<ActionDispatch::Cookies::CookieJar:0x007fd7ec19a638 ...>, @options={:signed_cookie_salt=>"signed cookie", :encrypted_cookie_salt=>"encrypted cookie", :encrypted_signed_cookie_salt=>"signed encrypted cookie", :secret_token=>nil, :secret_key_base=>"d4b9400cc11ac95836a873c775f9597d9d6428bb4a3d82e3723da38bf04914735397b697d45dbeb6fa4b1a8719c6f87b2e333510d316e1a0f4b1ad40eecf0f8a", :upgrade_legacy_signed_cookies=>false}, @encryptor=#<ActiveSupport::MessageEncryptor:0x007fd7ec198cc0 @secret="+&\x1E\x8D7h\x00l_3Z\x02\xCEYU\xE5\xD1\xAC-\xD7z\xE3\xF2\xD8\xA6Pn\x96\x84Cx\xDE\x98Z\xC5\x80js\xF7\xF8q\x04s\b\xCFf\x96v\x98~\xED\x9C\x11\xDE\xC1\xD8\x1Dz\x1DS\x12\xA4\xDF<", @sign_secret="\x86\xD9\xEC\xFFu\xE9\xA2\xC7z\xD8\x990\xDE+#s\xC1\x1E$\x1E;Jd\x8B\xA2\x9A\xB9\x05>\x01\xF5\xB6\x0E\xC0\x10\xD9\xD5\xF7\xBA[$\xC9m\xE65<}D\xA0b\xE7\xE8y\xCA6\x1F\x02\xA3S\x1F[\xFEk\xD1", @cipher="aes-256-cbc", @verifier=#<ActiveSupport::MessageVerifier:0x007fd7ec198bd0 @secret="\x86\xD9\xEC\xFFu\xE9\xA2\xC7z\xD8\x990\xDE+#s\xC1\x1E$\x1E;Jd\x8B\xA2\x9A\xB9\x05>\x01\xF5\xB6\x0E\xC0\x10\xD9\xD5\xF7\xBA[$\xC9m\xE65<}D\xA0b\xE7\xE8y\xCA6\x1F\x02\xA3S\x1F[\xFEk\xD1", @digest="SHA1", @serializer=ActiveSupport::MessageEncryptor::NullSerializer>, @serializer=Marshal>>>, "action_dispatch.request.unsigned_session_cookie"=>{"session_id"=>"465d10f227d1b1033088b17f3aa77cb3", "_csrf_token"=>"SghTPesnhyoSKhA2yFhM4d20/KjqIPixcFUSCpn5jX4=", "omniauth.params"=>{}, "omniauth.state"=>"fc29151421330cb904b4c4984bdd52e21a53d98531389b74", "flash"=>{"discard"=>[:danger], "flashes"=>{:danger=>"Error during connection with Google API."}}}}

编辑2:

好的。我定位了问题。当我在omniauth.rb中评论选项时,它记录了我

{ :access_type => 'offline', :prompt => 'consent', :approval_prompt => 'force', :scope => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/calendar', :redirect_uri => 'http://localhost:3000/auth/google-oauth2/callback', }

最佳答案

查看 request.env 哈希值,没有 omniauth.auth 键 - 有一个 omniauth.state 键...也许这就是你想要的?

env 哈希值的末尾还包含以下内容:

unsigned_session_cookie"=>{
"session_id"=>"465d10f227d1b1033088b17f3aa77cb3",
"_csrf_token"=>"SghTPesnhyoSKhA2yFhM4d20/KjqIPixcFUSCpn5jX4=",
"omniauth.params"=>{},
"omniauth.state"=>"fc29151421330cb904b4c4984bdd52e21a53d98531389b74",
"flash"=>{
"discard"=>[:danger],
"flashes"=>{:danger=>"Error during connection with Google API."}}
}
}

这可能只是连接问题,正如该闪现消息似乎暗示的那样。

关于ruby-on-rails - request.env ['omniauth.auth' ] 在 Ruby on Rails 中为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24694460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com