jjzjj

php - OAuthException : redirect_uri isn't an absolute URI. 检查 RFC 3986 (Symfony)

coder 2024-01-01 原文

我想在我的网站上添加 facebook 登录选项,关注 this tutorial .我按照教程中的说明进行了所有操作,但仍然出现此错误:

OAuthException: redirect_uri isn't an absolute URI

怎么可能解决呢?

此 url 由 facebookOAuthProvider 生成。该网站不在本地主机上。它在网络服务器上运行,使用 https。

这是相关代码:

    // redirect to Facebook
    $facebookOAuthProvider = $this->get('app.facebook_provider');
    $url = $facebookOAuthProvider->getAuthorizationUrl([
        // these are actually the default scopes
        'scopes' => ['public_profile', 'email'],
    ]);

    return $this->redirect($url);

它重定向到这个 url:

https://www.facebook.com/v2.3/dialog/oauth?scopes[0]=public_profile&scopes[1]=email&state=...&scope=public_profile,email&response_type=code&approval_prompt=auto&redirect_uri=/connect/facebook-check&client_id=...

redirect_uri 确实不是绝对 url。但如何修复它呢?


编辑

如果我添加 'redirect_uri' => [$redir] 那么 url 如下所示:

https://www.facebook.com/v2.3/dialog/oauth?scopes%5B0%5D=public_profile&scopes%5B1%5D=email&scopes%5B2%5D=user_location&redirect_uri%5B0%5D=https%3A%2F%2Fexample.com%2Fconnect%2Ffacebook-check&state=...&scope=public_profile%2Cemail&response_type=code&approval_prompt=auto&client_id=...

我可以在生成的 url 中看到绝对 redirect_uri,但如果我导航到它,我仍然会收到此错误

Redir 定义为:

$redir = $this->generateUrl('connect_facebook_check', array(), UrlGeneratorInterface::ABSOLUTE_URL);

编辑2

如果我将 [$redir] 替换为 $redir,那么 facebook 会使用代码将我正确重定向到 /connect/facebook-check,但我得到一个 OAuthException: redirect_uri isn't an absolute URI。在此处检查 RFC 3986

最佳答案

我不知道您从哪里获得示例代码,但肯定不是从链接的教程中获得的。

Facebook授权是基于你生成一个FB链接,用户去FB给自己授权,然后FB服务器重定向回给你(连同是否授权)。

FB 不会猜测登录后将用户重定向到哪里。你需要给他一个包含 http(s) 和服务器名称的完整路径(如果我没记错的话,它也与 FB 应用程序中保存的兼容)

附带的教程需要编写一个 Controller ,其中包含 2 个方法(输出和返回)以及配置中的相应条目。

如果您使用 this ,然后查看您是如何配置提供程序的。 redirectUri 中有什么?

关于php - OAuthException : redirect_uri isn't an absolute URI. 检查 RFC 3986 (Symfony),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45325967/

有关php - OAuthException : redirect_uri isn't an absolute URI. 检查 RFC 3986 (Symfony)的更多相关文章

  1. ruby - rails 3 redirect_to 将参数传递给命名路由 - 2

    我没有找到太多关于如何执行此操作的信息,尽管有很多关于如何使用像这样的redirect_to将参数传递给重定向的建议:action=>'something',:controller=>'something'在我的应用程序中,我在路由文件中有以下内容match'profile'=>'User#show'我的表演Action是这样的defshow@user=User.find(params[:user])@title=@user.first_nameend重定向发生在同一个用户Controller中,就像这样defregister@title="Registration"@user=Use

  2. ruby-on-rails - Rails 3 - 过滤器链暂停为 :authentication rendered or redirected - 2

    我仍然收到标题中的“错误”消息,但不知道如何解决。在ApplicationController中,classApplicationController在routes.rb#match'set_activity_account/:id/:value'=>'users#account_activity',:as=>:set_activity_account--thisdoesn'tworkaswell..resources:usersdomemberdoget:action_a,:action_bendcollectiondoget'account_activity'endend和User

  3. ruby-on-rails - 这个 C 和 PHP 程序员如何学习 Ruby 和 Rails? - 2

    按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我来自C、php和bash背景,很容易学习,因为它们都有相同的C结构,我可以将其与我已经知道的联系起来。然后2年前我学了Python并且学得很好,Python对我来说比Ruby更容易学。然后从去年开始,我一直在尝试学习Ruby,然后是Rails,我承认,直到现在我还是学不会,讽刺的是那些打着简单易学的烙印,但是对于我这样一个老练的程序员来说,我只是无法将它

  4. ruby-on-rails - rails : Pass Parameters to New Controller during 'redirect_to' - 2

    我正在使用RyanBates的RailsCastonWickedWizardForms创建一个多步骤表单。我没有定义current_user方法(不使用身份验证gem)-因此,我试图在redirect_to期间传递user.id参数-不幸的是,我似乎无法让它工作。任何帮助表示赞赏!我的用户Controller创建方法defcreate@user=User.new(params[:user])respond_todo|format|if@user.saveformat.html{redirect_tocontroller:'user_steps',id:'user.id'}#format

  5. ruby-on-rails - Rails 中的 Post Redirect Get 模式 - 2

    如何在Rails中实现PRG?我在Rails中使用了PRG,但我并不完全相信它是正确的。我想知道在Rails中是否有更好的方法来处理它? 最佳答案 我不知道PRG模式有多流行以及为什么人们必须虔诚地坚持它的失败方面的“重定向”(实际上,一个很好的理由是有时你不想处理“设置”的复杂性制造失败并保持干燥)。您基本上需要的是将:user的参数传输到new。我认为上面@Hitesh的解决方案非常接近。classUsersController:newendendend 关于ruby-on-rail

  6. ruby-on-rails - 带有 redirect_to 的 Flash 通知在 rails 中被破坏 - 2

    我已更新到Rails2.3.10、Rack1.2.1,现在我的所有即时消息都没有显示。我发现在重定向期间,通知是这样传递的redirect_to(@user,:notice=>"Sorrytherewasanerror")在我看来闪存哈希是空的!map:ActionController::Flash::FlashHash{}但是您可以在Controller中看到该消息。是什么原因?session{:home_zip=>"94108",:session_id=>"xxx",:flash=>{:notice=>"Sorrytherewasanerror"},:user_credential

  7. ruby-on-rails - ruby rails : redirect_to not working after create and save - 2

    我想在用户提交电子邮件后redirect_toslider_path。当前,仅显示成功消息而没有重定向。这是代码:classSplash::SubscribersController{:success=>success,:message=>message}.to_json}endendend 最佳答案 只需替换这部分代码:ifsuccessflash[:success]=messageredirect_toslider_pathelseflash[:error]=messageendredirect_toroot_path用这个:i

  8. ruby-on-rails - Rails 还是 Sinatra? PHP程序员入门学习哪个好? - 2

    按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭10年前。我使用PHP的时间太长了,对它感到厌倦了。我也想学习一门新语言。我一直在使用Ruby并且喜欢它。我必须在Rails和Sinatra之间做出选择,那么您会推荐哪一个?Sinatra真的不能用来构建复杂的应用程序,它只能用于简单的应用程序吗?

  9. ruby-on-rails - redirect_to 自定义 http header - 2

    在我当前的项目中,在为http基本身份验证重定向时需要设置自定义httpheader变量。我可以为自定义header指示redirect_to吗?谢谢。 最佳答案 Rails允许您在重定向时添加自定义header。在Railsguides中进行了讨论.10.2.1SettingCustomHeadersIfyouwanttosetcustomheadersforaresponsethenresponse.headersistheplacetodoit.Theheadersattributeisahashwhichmapsheader

  10. ruby - 通过 node-sass 的 Symfony assetic sass 过滤器? - 2

    我在让asseticsass过滤器与node-sass而不是ruby​​替代品一起工作时遇到了一些困难。我的config.yml文件中有以下配置:assetic:debug:"%kernel.debug%"use_controller:falsebundles:[]write-to:"%kernel.root_dir%/../web/assets"read_from:"%kernel.root_dir%/../web/assets"node:"%%PROGRAMFILES%%\nodejs\\node.exe"node_paths:["%%USERPROFILE%%\\AppData\

随机推荐