我试图从rails应用程序导出我的数据到谷歌日历,但在登录后我找不到'omniauth。输入request.env.
我使用Rails 4.0.4和Ruby 2.0.0p481
我Gemfilegem '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
控制器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 api (I cannot add a image,)
如果你能帮我解决这个问题,我将非常感激。
编辑:request.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"=>"+&x1Ex8D7hx00l_3Zx02xCEYUxE5xD1xAC-xD7zxE3xF2xD8xA6Pnx96x84CxxDEx98ZxC5x80jsxF7xF8qx04sbxCFfx96vx98~xEDx9Cx11xDExC1xD8x1Dzx1DSx12xA4xDF<", "signed encrypted cookie64"=>"x86xD9xECxFFuxE9xA2xC7zxD8x990xDE+#sxC1x1E$x1E;Jdx8BxA2x9AxB9x05>x01xF5xB6x0ExC0x10xD9xD5xF7xBA[$xC9mxE65<}DxA0bxE7xE8yxCA6x1Fx02xA3Sx1F[xFEkxD1"}, @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"=>"+&x1Ex8D7hx00l_3Zx02xCEYUxE5xD1xAC-xD7zxE3xF2xD8xA6Pnx96x84CxxDEx98ZxC5x80jsxF7xF8qx04sbxCFfx96vx98~xEDx9Cx11xDExC1xD8x1Dzx1DSx12xA4xDF<", "signed encrypted cookie64"=>"x86xD9xECxFFuxE9xA2xC7zxD8x990xDE+#sxC1x1E$x1E;Jdx8BxA2x9AxB9x05>x01xF5xB6x0ExC0x10xD9xD5xF7xBA[$xC9mxE65<}DxA0bxE7xE8yxCA6x1Fx02xA3Sx1F[xFEkxD1"}, @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="+&x1Ex8D7hx00l_3Zx02xCEYUxE5xD1xAC-xD7zxE3xF2xD8xA6Pnx96x84CxxDEx98ZxC5x80jsxF7xF8qx04sbxCFfx96vx98~xEDx9Cx11xDExC1xD8x1Dzx1DSx12xA4xDF<", @sign_secret="x86xD9xECxFFuxE9xA2xC7zxD8x990xDE+#sxC1x1E$x1E;Jdx8BxA2x9AxB9x05>x01xF5xB6x0ExC0x10xD9xD5xF7xBA[$xC9mxE65<}DxA0bxE7xE8yxCA6x1Fx02xA3Sx1F[xFEkxD1", @cipher="aes-256-cbc", @verifier=#<ActiveSupport::MessageVerifier:0x007fd7ec198bd0 @secret="x86xD9xECxFFuxE9xA2xC7zxD8x990xDE+#sxC1x1E$x1E;Jdx8BxA2x9AxB9x05>x01xF5xB6x0ExC0x10xD9xD5xF7xBA[$xC9mxE65<}DxA0bxE7xE8yxCA6x1Fx02xA3Sx1F[xFEkxD1", @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="+&x1Ex8D7hx00l_3Zx02xCEYUxE5xD1xAC-xD7zxE3xF2xD8xA6Pnx96x84CxxDEx98ZxC5x80jsxF7xF8qx04sbxCFfx96vx98~xEDx9Cx11xDExC1xD8x1Dzx1DSx12xA4xDF<", @sign_secret="x86xD9xECxFFuxE9xA2xC7zxD8x990xDE+#sxC1x1E$x1E;Jdx8BxA2x9AxB9x05>x01xF5xB6x0ExC0x10xD9xD5xF7xBA[$xC9mxE65<}DxA0bxE7xE8yxCA6x1Fx02xA3Sx1F[xFEkxD1", @cipher="aes-256-cbc", @verifier=#<ActiveSupport::MessageVerifier:0x007fd7ec198bd0 @secret="x86xD9xECxFFuxE9xA2xC7zxD8x990xDE+#sxC1x1E$x1E;Jdx8BxA2x9AxB9x05>x01xF5xB6x0ExC0x10xD9xD5xF7xBA[$xC9mxE65<}DxA0bxE7xE8yxCA6x1Fx02xA3Sx1F[xFEkxD1", @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."}}}}
EDIT2:
OK。这是一个局部问题。当我在omniauth中注释选项。它记录了我
{ :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."}}
}
}
这可能只是一个连接问题,正如flash消息所暗示的。
我自己解决了问题。我在下面修改了一个选项字典,它开始工作了。
{ access_type: 'offline', prompt: 'consent', approval_prompt: 'force', scope: 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/calendar', }