【问题标题】:Angular with wordpress jwt authAngular 与 wordpress jwt auth
【发布时间】:2017-05-15 05:32:18
【问题描述】:

我正在尝试将 wordpress 作为我的 angularjs 应用程序的后端,因此我将插件 rest-api 与 jwt-auth 一起使用 所以尝试登录时出现以下错误

XMLHttpRequest cannot load http://localhost/back/wp-json/jwt-auth/v1/token. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://imider.ma' is therefore not allowed access. The response had HTTP status code 500.

我知道我必须添加 CROS 访问权限,但我不熟悉 wordpress,有什么帮助吗?

【问题讨论】:

    标签: angularjs wordpress


    【解决方案1】:

    https://docs.google.com/document/d/17zgUHZrvL5KVG2yKQE8NWgxNZn6V08xr65DBox5WVZ0/edit?usp=sharing

    这里是我如何访问 api 的教程

    那么你就可以用它来获取token了

    $http({
                    method:'post',
                    url:'',
                    data: {
                        username: '',
                        password: ''
                    }
                }).then(function(results){
                    console.log(results);
                })
    

    那你就可以用这个了

    $http({
                        method:'get',
                        url:'',
                        headers: { 'Authorization': 'Bearer <myTokenId>' }
                    }).then(function(results){
                        console.log(results);
                    })
    

    【讨论】:

      【解决方案2】:

      我制作了一个视频,详细介绍了安装和设置插件的过程。如果您按照我在那里概述的步骤进行操作,您应该会很好。

      https://youtu.be/Mp7T7x1oxDk

      这个想法是,您还需要修改 .htaccesswp-config.php 以使插件也可以与现有的 API 端点一起使用。

      只需安装插件并添加用于签署令牌的 SECRET_KEY 即可使 JWT 设置工作,但它不允许您将通过该 API 生成的令牌与现有 REST API 端点一起使用。

      【讨论】:

        猜你喜欢
        • 2018-04-28
        • 2018-04-08
        • 2019-01-10
        • 1970-01-01
        • 2020-02-13
        • 2021-10-16
        • 2018-10-06
        • 2018-03-30
        • 2020-11-07
        相关资源
        最近更新 更多