• If I use Postman to request an authorisation code from WP OAuth Server it returns the WP admin login page.

    Is this the expected behaviour or am I doing something wrong?

    If this is the expected behaviour what do I have to do to access the WP API without manually intervening to login into the target site?

    FYI once logged in my implementation works fine.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I am also facing this problem and struggling with it. Please let me know how I can solve this problem. I am getting access token if I am on the same browser and logged in. If I am not logged in I am redirecting to wp-login page ??

    Thread Starter mgcwebsites

    (@mgcwebsites)

    Yep that’s how it works – the next step is logging in – no doubt it’s easy when you know how but I didn’t know where to start and couldn’t even find a hint in the right direction. I wasted hours writing my own oAuth plugin too!

    *IF* it’s OK for the updating site/app to know the username and password for the site exposing the API (i.e. you own both of them as in my cases) then JSON Web Tokens are quick, easy and work reliably.

    On the site to be accessed…..

    Install JWT Authentication for WP-API by Enrique Chavez
    Add the following to .htaccess

    # BEGIN JWT Authentication for WP-API
    RewriteEngine on
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule ^(.*) – [E=HTTP_AUTHORIZATION:%1]
    SetEnvIf Authorization “(.*)” HTTP_AUTHORIZATION=$1
    # END JWT Authentication for WP-API

    Add the following to config.php

    # BEGIN JWT Authentication for WP-API
    define(‘JWT_AUTH_SECRET_KEY’, ‘your-top-secret-key’);
    define(‘JWT_AUTH_CORS_ENABLE’, true);
    # END JWT Authentication for WP-API

    Activate the plugin

    On the site / app that will do the accessing you can now request a JWT via a new endpoint the plugin creates BUT this app will need to be in possession of the WP username and password. Now just send the token in the headers with of every request as a bearer token and it just works. You can configure the timeout of the tokens from seconds to years. There is also a way to revoke tokens but honestly that’s still on my todo list.

    I’m no security expert so do your own research but for my situation this saved the day – I have yet to find any other method of accessing the API that I could get to work.

    Last tip is don’t even think about coding up anything until you’ve already seen it work in Postman – it’s so much quicker to trial and error using the app – saves hours.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Rookie question re unexpected login page’ is closed to new replies.