LLMS_REST_Authentication::authenticate( int|false $user_id )

Authenticate an API Request


Parameters Parameters

$user_id

(int|false) (Required) WP_User ID of an already authenticated user or false.


Top ↑

Return Return

(int|false)


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/class-llms-rest-authentication.php

	public function authenticate( $user_id ) {

		// Load includes in case a plugin has triggered authentication early.
		LLMS_REST_API()->includes();

		// 1. If we already have a user, use that user.
		// 2. Only authenticate via ssl.
		// 3. Only authenticate to our end points.
		if ( ! empty( $user_id ) || ! is_ssl() || ! $this->is_rest_request() ) {
			return $user_id;
		}

		$creds = $this->locate_credentials();
		if ( ! $creds ) {
			return false;
		}

		$key = $this->find_key( $creds['key'] );
		if ( ! $key ) {
			return false;
		}

		if ( ! hash_equals( $key->get( 'consumer_secret' ), $creds['secret'] ) ) {
			$this->set_error( llms_rest_authorization_required_error( '', false ) );
			return false;
		}

		$this->api_key = $key;

		$user_id = $key->get( 'user_id' );
		do_action( 'llms_rest_basic_auth_success', $user_id );

		return $user_id;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.5 Load all includes to accommodate plugins and themes that call determine_current_user early.
1.0.0-beta.12 Call llms_rest_authorization_required_error() instructing to not check if the current user is logged in to avoid infinite loops.
1.0.0-beta.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.