# timetics/1.0.22/core/integrations/auth.php

Timetics – Appointment Booking Calendar &amp; Scheduling, version 1.0.22. 91 lines.

- Page: https://pluginprobe.com/plugins/timetics/1.0.22/code/core/integrations/auth.php
- Raw: https://pluginprobe.com/plugins/timetics/1.0.22/raw/core/integrations/auth.php
- Modified: 2024-06-12T04:00:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/timetics/1.0.22/code/core/integrations/auth.php#L10-L20`.

```php
<?php
/**
 * Authentication for integrations
 *
 * @package Timetics
 */

namespace Timetics\Core\Integrations;

use Timetics\Core\Integrations\Google\Service\Calendar;
use Timetics\Utils\Singleton;

/**
 * Auth Class
 *
 * @since 1.0.0
 */
class Auth {
    use Singleton;

    /**
     * Initialize
     *
     * @return  void
     */
    public function init() {
        add_action( 'template_redirect', [ $this, 'authenticate' ] );
    }

    /**
     * Authenticate integration
     *
     * @return  void
     */
    public function authenticate() {
        $query_var = get_query_var( 'timetics-integration', false );
        $user_id   = get_current_user_id();

        $code = isset( $_GET['code'] ) ? sanitize_text_field( $_GET['code'] ) : '';

        if ( ! $query_var ) {
            return;
        }

        switch ( $query_var ) {
			case 'google-auth':
				$this->google_auth( $code );
                break;
        }

        do_action('timetics_integration_auth', $query_var, $code );

        $redirect_url = admin_url('admin.php?page=timetics#/my-profile');

        if ( current_user_can('manage_options') ) {
            $redirect_url = admin_url('admin.php?page=timetics#/settings');
        }

        wp_redirect( $redirect_url );
        exit;
    }

    /**
     * Authentication for google
     *
     * @param   string  $code
     *
     * @return  void
     */
    public function google_auth( $code = '' ) {
        $client = timetics_get_google_client();

        $client->add_scope( Calendar::scope() );
        $data = $client->fetch_access_token_with_auth_code( $code );
        $data['code'] = $code;

        timetics_update_google_auth( get_current_user_id(), $data );
    }

    /**
     * Authentication for zoom
     *
     * @param   string  $code
     *
     * @return void
     */
    public function zoom_auth( $code = '' ) {
        // Override this function to authenticate zoom
    }
}

```
