Authenticate user on custom endpoint
-
Hi All,
I have created a new endpoint for authenticating user using basic authentication. The client will send headers like
Authorization Basic <base64 encoded token>When i send right username and password function works fine . But when i give wrong password there is no response.
Please find the code for function below
function check_authentication( WP_REST_Request $request ) { $serverparams = apache_request_headers(); $authorization = $serverparams['Authorization']; if($authorization!='') { $authvalues = explode(' ',$authorization); $usernamepass = $authvalues[1]; $usernamepassdecode = base64_decode($usernamepass); $creds = explode(':',$usernamepassdecode); $username = $creds[0]; echo $username; $pass = $creds[1]; echo $pass; $user = get_user_by('login',$username); if(wp_check_password($pass,$user->user_pass,$user->ID)) return 'Success'; else return 'Fail'; } else{ return 'authorization header missing'; } }
can some one please help me here ?
Thanks,
Pavan
- The topic ‘Authenticate user on custom endpoint’ is closed to new replies.