• Resolved crps92

    (@crps92)


    Hi,

    with the plugin installed the logged in user has the option to generate a token for him/herself under “my profile” -> Open Authentication. (How) is it possible to archive this programmatically?

    Thank you very much in advance!

    Background
    – WP-Page and 1 Client
    – Client uses WP-REST API protected endpoints
    – user can log in (a) via WP-Page or (b) via Client
    – (b) works fine (User credentials flow)

    The problem is that when the user logs in on the WP-page directly the Client can not make requests on his behalf, so I want to generate the users token and send it to the Client along with some other information so that the following flow is identical no matter if the user initially came from the WP-page or the client

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter crps92

    (@crps92)

    Found the solution, not sure if it’s the best one:

    function generate_oauth_token(){
        //if no token exists, create it
        if (is_null(wo_ap_et_access_token_for_user())){
            $_POST['generate_token']="something"; //$_POST['generate_token'] not being empty triggers token generation
            wo_user_profile_update_token_gen( null, null, null ); //$errors, $update, $user are all null
        }
        //get token and echo it
        $token = wo_ap_et_access_token_for_user();
        echo ($token -> access_token);
    }

    functions wo_ap_et_access_token_for_user() and wo_user_profile_update_token_gen($errors, $update, $user) can be found in includes/admin/profile.php

    Thread Starter crps92

    (@crps92)

    seems like wo_ap_et_access_token_for_user return changed.

    last line has to be

    echo ($token);

    • This reply was modified 5 years, 2 months ago by crps92.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Generate token for user programmatically’ is closed to new replies.