コード例 #1
2
 /**
  * Generates token.
  *
  * Uses 'create_token' to create a token.
  *
  * @since 4.3.0
  *
  * @param string $request The rest-api request that contains all parameters.
  * @return array The token and expiration-timestamp
  */
 function action(WP_REST_Request $request)
 {
     $return = new WP_Error('400', __('Authentication failed.', 'wp_jwt_auth'));
     if (isset($request['method'])) {
         // if user wants to login by social-media-account
         $return = apply_filters('wak_login_method_' . $request['method'], $return, $request);
     } else {
         // if user wants to login by username/password
         $username = $request['username'];
         $password = $request['password'];
         $jwt_functions = new WAK_Functions();
         $user = get_user_by('login', $username);
         if ($user && wp_check_password($password, $user->data->user_pass, $user->ID)) {
             $return = $jwt_functions->create_token($user->ID);
         } else {
             $return = new WP_Error('credentials_invalid', __('Username/Password combination is invalid', 'wp_jwt_auth'));
         }
     }
     if (isset($request['set_wp_cookie']) && $request['set_wp_cookie'] == 'true' && !is_wp_error($return)) {
         wp_set_auth_cookie($return['userid'], true);
     }
     if (isset($request['redirect_to']) && !is_wp_error($return)) {
         $location = $request['redirect_to'];
         if (is_wp_error($return)) {
             $location .= '?error=true&msg=' . urlencode($return->get_error_message());
         }
         wp_redirect($location);
         exit;
         return;
     }
     return $return;
 }
コード例 #2
0
 /**
  * Create a jwt for current user
  *
  * @return string|WP_Error
  */
 public function create_jwt_token()
 {
     $identity = $this->check_identity();
     if (is_wp_error($identity)) {
         return $identity;
     }
     $jwt_functions = new WAK_Functions();
     $this->user_id = $this->check_user_status();
     if (!$this->user_id || is_wp_error($this->user_id)) {
         return new WP_Error('no_user_found', __('No user matching the facebook id was found', 'wp-authentication-kit'));
     }
     return $jwt_functions->create_token($this->user_id);
 }
コード例 #3
0
 public function create_jwt_token()
 {
     $token_app_id = get_option('wak_account_kit_app_id');
     if (empty($token_app_id)) {
         return new WP_Error('app_id_missing', __('Account-Kit app id is missing', 'wp-authentication-kit'));
     }
     $token_app_secret = get_option('wak_account_kit_app_secret');
     if (empty($token_app_secret)) {
         return new WP_Error('app_id_missing', __('Account-Kit app secret is missing', 'wp-authentication-kit'));
     }
     $identity = $this->check_identity();
     if (is_wp_error($identity)) {
         return $identity;
     }
     $this->user_id = $this->check_user_status();
     if (!$this->user_id || is_wp_error($this->user_id)) {
         return new WP_Error('no_user_found', __('No user matching the account kit id was found', 'wp-authentication-kit'));
     }
     $jwt_functions = new WAK_Functions();
     return $jwt_functions->create_token($this->user_id);
 }
コード例 #4
0
 /**
  * Add jwt-validation to wp-authorization.
  *
  * Uses 'validate_token' in order to validate the token from the current request.
  *
  * @since 0.0.1
  *
  * @param string $user The user from current authorization.
  * @return int Logged in user id.
  */
 function rest_jwt_auth_handler($user)
 {
     $jwt_functions = new WAK_Functions();
     $jwt_return = $jwt_functions->validate_token();
     if (!$jwt_return) {
         return $user;
     }
     return $jwt_return;
 }
コード例 #5
0
<?php

require_once "./inc/class-wak-functions.php";
$functions = new WAK_Functions();
echo $functions->create_secret();