简体   繁体   English

Laravel CORS - 对预检请求的响应未通过访问控制检查:没有“Access-Control-Allow-Origin” header 出现在请求中

[英]Laravel CORS -Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested

I am trying to integrate Laravel socialite to my project, i am coming across the following error我正在尝试将 Laravel 社交名流集成到我的项目中,但遇到以下错误

Access to XMLHttpRequest at 'https://github.com/login/oauth/authorize?client_id=6b87b76a942a90caec24&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fgithub%2Fcallback&scope=user%3Aemail&response_type=code&state=ZLzrBzsFH6YVKpat3yZ5a2G6vLd0wWedFRwFRXoc' (redirected from 'http://localhost:8000/github') from origin 'http://localhost:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Access to XMLHttpRequest at 'https://github.com/login/oauth/authorize?client_id=6b87b76a942a90caec24&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fgithub%2Fcallback&scope=user%3Aemail&response_type=code&state=ZLzrBzsFH6YVKpat3yZ5a2G6vLd0wWedFRwFRXoc' (redirected from 'http ://localhost:8000/github') 来自原点 'http://localhost:8000' 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:否 'Access-Control-Allow-Origin' header 存在于请求的资源上。

The issue is when i press sign in with github button i get the above error问题是当我按下 github 按钮登录时出现上述错误

Error Picture错误图片

cors.php file cors.php文件


   'allowed_methods' => ['*'],

   'allowed_origins' => ['http://localhost:8000'],

   'allowed_origins_patterns' => [],

   'allowed_headers' => ['*'],

   'exposed_headers' => [],

   'max_age' => 0,

   'supports_credentials' => false, 

am using the Fruitcake/laravel-cors package我正在使用 Fruitcake/laravel-cors package

protected $middleware = [
        \Fruitcake\Cors\HandleCors::class,
    ];

Where am i going wrong?我哪里错了?

Access to XMLHttpRequest at 'https://github.com/...' (redirected from 'http://localhost:8000/github')... blocked by CORS policy通过“https://github.com/...”访问 XMLHttpRequest(从“http://localhost:8000/github”重定向)...被 CORS 策略阻止

You are not Github.你不是 Github。

The code running on your Laravel application is not running on github.com.在 Laravel 应用程序上运行的代码未在 github.com 上运行。

You cannot grant permission to your JavaScript to read data that Github is sending to the user's browser.您不能授予 JavaScript 读取 Github 发送到用户浏览器的数据的权限。


In broader terms, you've gone very wrong somewhere in your attempt to implement OAuth.从更广泛的角度来说,您在尝试实现 OAuth 的过程中出现了非常错误的地方。 You are making an Ajax request where you need to make a request that navigates the browser to Github for the user to interact with their login UI.您正在发出 Ajax 请求,您需要发出将浏览器导航到 Github 的请求,以便用户与其登录 UI 进行交互。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel7 CORS:被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:否 'Access-Control-Allow-Origin' - Laravel7 CORS : blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' 响应预检请求未通过访问控制检查:否'Access-Control-Allow-Origin' - esponse to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' CORS 错误:对预检请求的响应 'Access-Control-Allow-Origin' header 包含多个值 '*、*'、 - CORS error: Response to preflight request The 'Access-Control-Allow-Origin' header contains multiple values '*, *', Laravel 7 - 没有“访问控制允许来源” header 存在于请求的资源上 - Laravel 7 - No 'Access-Control-Allow-Origin' header is present on the requested resource “CORS:不存在‘Access-Control-Allow-Origin’header”,但存在 - “CORS: No 'Access-Control-Allow-Origin' header is present ”, but it is present header("访问控制允许来源:"); 不工作 CORS 策略,预检请求不允许重定向 - header("Access-Control-Allow-Origin: "); dont work CORS policy, Redirect is not allowed for a preflight request 错误:请求的资源上没有“Access-Control-Allow-Origin”标头 - Error: No 'Access-Control-Allow-Origin' header is present on the requested resource 请求的资源上不存在“ Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource 请求的资源上不存在“Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource 请求的资源上不存在“ Access-Control-Allow-Origin”标头 - No ‘Access-Control-Allow-Origin’ header is present on the requested resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM