Skip to content

Commit

Permalink
Version 1.2.0
Browse files Browse the repository at this point in the history
OAuth enforced as per Zoom requirements
  • Loading branch information
michaelbourne committed Feb 18, 2023
1 parent 6bb5c0e commit a1d7100
Show file tree
Hide file tree
Showing 158 changed files with 36,199 additions and 1,316 deletions.
Binary file added Gravity-Forms-Zoom-Webinar-Registration.zip
Binary file not shown.
17 changes: 10 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "michaelbourne/gravity-forms-zoom-webinar-registration",
"description": "Register attendees in your Zoom Webinar through a Gravity Form",
"version": "0.0.1",
"version": "1.2.0",
"license": "GPL-3.0-or-later",
"authors": [{
"name": "Michael Bourne",
Expand All @@ -12,14 +12,17 @@
"issues": "https://github.com/michaelbourne/gravity-forms-zoom-webinar-registration/issues"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.2.3",
"wp-coding-standards/wpcs": "^0.14.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.3"
},
"require": {
"firebase/php-jwt": "^5.2.0"
"squizlabs/php_codesniffer": "^3.7.1",
"wp-coding-standards/wpcs": "^2.3.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"phpcompatibility/php-compatibility": "*"
},
"archive": {
"exclude": ["/vendor/wp-coding-standards", "/vendor/bin", "/vendor/squizlabs", "/vendor/dealerdirect"]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
19 changes: 8 additions & 11 deletions gravity-forms-zoom-webinar-registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* @wordpress-plugin
* Plugin Name: Gravity Forms Zoom Webinar Registration
* Description: Register attendees in your Zoom Webinar through a Gravity Form
* Version: 1.0.1
* Version: 1.2.0
* Author: Michael Bourne
* Author URI: https://5forests.com
* Requires at least: 5.3
* Tested up to: 5.3
* Stable tag: 1.0.1
* Requires PHP: 7.1
* Requires at least: 5.4
* Tested up to: 6.1.1
* Stable tag: 1.2.0
* Requires PHP: 8.0
* License: GPL3
* License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
* Text Domain: gravity-zwr
Expand All @@ -26,10 +26,10 @@
* Created Date: Friday March 25th 2020
* Author: Michael Bourne
* -----
* Last Modified: Monday, March 30th 2020, 2:03:15 pm
* Last Modified: Friday, February 17th 2023, 3:52:08 pm
* Modified By: Michael Bourne
* -----
* Copyright (C) 2020 Michael Bourne
* Copyright (C) 2020-2023 Michael Bourne
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -51,7 +51,7 @@

defined( 'GRAVITYZWR_ROOT' ) || define( 'GRAVITYZWR_ROOT', plugin_dir_path( __FILE__ ) );
defined( 'GRAVITYZWR_URI' ) || define( 'GRAVITYZWR_URI', plugin_dir_url( __FILE__ ) );
defined( 'GRAVITYZWR_VERSION' ) || define( 'GRAVITYZWR_VERSION', '1.0.1' );
defined( 'GRAVITYZWR_VERSION' ) || define( 'GRAVITYZWR_VERSION', '1.2.0' );
defined( 'GRAVITYZWR_ZOOMAPIURL' ) || define( 'GRAVITYZWR_ZOOMAPIURL', 'https://api.zoom.us/v2' );

add_action( 'gform_loaded', array( 'GravityZWR_Bootstrap', 'load' ), 5 );
Expand All @@ -67,9 +67,6 @@ public static function load() {
return;
}

// load vendor files.
require_once GRAVITYZWR_ROOT . 'vendor/autoload.php';

// Load API Helper classes.
require_once GRAVITYZWR_ROOT . 'includes/class-gravityzwr-wordpressremote.php';
require_once GRAVITYZWR_ROOT . 'includes/class-gravityzwr-zoomapi.php';
Expand Down
36 changes: 18 additions & 18 deletions includes/class-gravityzwr-wordpressremote.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Created Date: Friday March 25th 2020
* Author: Michael Bourne
* -----
* Last Modified: Monday, March 30th 2020, 2:07:50 pm
* Last Modified: Friday, February 17th 2023, 7:02:39 pm
* Modified By: Michael Bourne
* -----
* Copyright (C) 2020 Michael Bourne
Expand Down Expand Up @@ -53,35 +53,35 @@ class GravityZWR_WordPressRemote {
/**
* Request response
*
* @var [type]
* @var array|WP_Error
*/
protected $response;

/**
* Body of the response
*
* @var [type]
* @var string
*/
protected $body;

/**
* Headers of the response
*
* @var [type]
* @var array
*/
protected $headers;

/**
* Response Code from the Request
*
* @var [type]
* @var int|string
*/
protected $response_code;

/**
* Response Message from the Request
*
* @var [type]
* @var string
*/
protected $response_message;

Expand All @@ -92,7 +92,7 @@ class GravityZWR_WordPressRemote {
* @param array $arguments Request Arguements.
* @param string $method Request Method.
*/
public function __construct( $url, $arguments = array(), $method = 'get' ) {
public function __construct( string $url, array $arguments = array(), string $method = 'get' ) {
$this->method = strtoupper( $method );
$this->url = $url;
$this->arguments = $arguments;
Expand All @@ -115,43 +115,43 @@ public function run() {
/**
* Get the body
*
* @return mixed
* @return string
*/
public function get_body() {
public function get_body(): string {
return $this->body;
}

/**
* Get the headers
*
* @return mixed
* @return array
*/
public function get_headers() {
return $this->headers;
public function get_headers(): array {
return (array) $this->headers;
}

/**
* Response Code
*
* @return string
*/
public function get_response_code() {
return $this->response_code;
public function get_response_code(): int {
return (int) $this->response_code;
}

/**
* Get the response message
*
* @return string
*/
public function get_response_message() {
public function get_response_message(): string {
return $this->response_message;
}

/**
* Get the whole response
*
* @return mixed
* @return array|WP_Error
*/
public function get_response() {
return $this->response;
Expand All @@ -160,9 +160,9 @@ public function get_response() {
/**
* If the request was a success
*
* @return mixed
* @return bool
*/
public function is_success() {
public function is_success(): bool {
// phpcs:ignore
if ( '200' == (string) $this->response_code ) {
return true;
Expand Down
62 changes: 49 additions & 13 deletions includes/class-gravityzwr-zoomapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
* Created Date: Friday March 25th 2020
* Author: Michael Bourne
* -----
* Last Modified: Monday, March 30th 2020, 2:07:45 pm
* Last Modified: Friday, February 17th 2023, 7:56:22 pm
* Modified By: Michael Bourne
* -----
* Copyright (C) 2020 Michael Bourne
*/

use \Firebase\JWT\JWT;

if ( ! defined( 'ABSPATH' ) ) {
return;
}
Expand All @@ -30,18 +28,56 @@
*/
class GravityZWR_ZOOMAPI extends GravityZWR_WordPressRemote {
/**
* Prepare the headers for JSON request and generate a JWT.
* Prepare the headers for JSON request.
*/
public function run() {
$options = GravityZWR::get_zoom_settings_keys();
$key = $options['zoomapikey'];
$secret = $options['zoomapisecret'];
$token = array(
'iss' => $key,
'exp' => time() + 60,
);

$this->arguments['headers']['Authorization'] = 'Bearer ' . JWT::encode( $token, $secret );

// Get bearer token from transients.
$token = get_transient( 'gravityzwr_zoom_token' );

// If transient not set or expired, send a POST request to the Zoom API to get a new token.
if ( false === $token ) {

$options = GravityZWR::get_zoom_settings_keys();

// Set variables from contants if set, or efault to options array if not.
$account = defined( 'GRAVITYZWR_ACCOUNT_ID' ) ? GRAVITYZWR_ACCOUNT_ID : $options['zoomaccountid'];
$client = defined( 'GRAVITYZWR_CLIENT_ID' ) ? GRAVITYZWR_CLIENT_ID : $options['zoomclientid'];
$secret = defined( 'GRAVITYZWR_CLIENT_SECRET' ) ? GRAVITYZWR_CLIENT_SECRET : $options['zoomclientsecret'];

$token = wp_remote_post(
'https://zoom.us/oauth/token?grant_type=account_credentials&account_id=' . $account,
array(
'headers' => array(
'Host' => 'zoom.us',
'Authorization' => 'Basic ' . base64_encode( $client . ':' . $secret ), // phpcs:ignore
'Content-type' => 'application/x-www-form-urlencoded',
),
)
);

// If we get a WP Error, log it and return.
if ( is_wp_error( $token ) ) {
$gfaddon = new GravityZWR();
$gfaddon->log_error( 'WP Error getting Zoom OAuth token: ' . $token->get_error_message() );
return;
}

// If we get a 200 response, set the transient and get the token.
if ( 200 === wp_remote_retrieve_response_code( $token ) ) {
$token = json_decode( wp_remote_retrieve_body( $token ) );
$expires = (int) $token->expires_in ?? HOUR_IN_SECONDS;
set_transient( 'gravityzwr_zoom_token', $token->access_token, $expires );
$token = $token->access_token;
} else {
// If we don't get a 200 response, log the error and return.
$gfaddon = new GravityZWR();
$gfaddon->log_error( 'Zoom API Error getting Zoom token: ' . wp_remote_retrieve_response_message( $token ) );
return;
}
}

$this->arguments['headers']['Authorization'] = 'Bearer ' . $token;
$this->arguments['headers']['Content-type'] = 'application/json';
parent::run();
}
Expand Down
Loading

0 comments on commit a1d7100

Please sign in to comment.