简体   繁体   中英

GET https://…/wp-json/wp/v2/users/me 401 (Unauthorized) from Angular2+ with Headless WP CMS backend

What I'm trying to do: I want to be able to retrieve currently logged in private user details, ie. current user email, posts made by the current user, past terawallet transactions, wallet balance, user settings and display it on the angular front end from the wp backend. For this, I am using the wp-api-angular library

What I've been able to achieve:

-log in to various accounts from angular front end

-create basic posts

-delete posts

-edit posts

-Create token and I can see it in my Networks tab in dev tools, with the user_display_name, user_email, and user_nicename

Essentially I've been able to replicate the demo content here https://github.com/wordpress-clients/wp-api-angular#wpapiusers , the issue is when I try to reach site.com/wp-json/wp/v2/users/me (where I assume all the details I'm looking for are at) it returns to me a 401 unauthorized

What I've tried to do: I've been going at it for a few hours and I can't find the issue (I'm still new to json)

-Added to .htaccess

RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

-Added to /etc/apache2/sites-enabled/000-default.conf

AllowOverride All

-Changed permissions from None to All in /etc/apache2/apache2.conf in /var/www/

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

On postman it says I have a CORS issue, but on reqbin it goes through just fine, so I'm confused

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

So I was able to find a temporary, dev-only solution to this with the chrome extension called "CORS Unblock", this is aligned to the issue I was seeing on Postman that said that I had a CORS issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM