Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 0.9.230409 #14

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions Google/GoogleLogin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?php
namespace Socialify;

defined('ABSPATH') || die();

const PROVIDER_KEY = 'google';

add_action('admin_init', __NAMESPACE__ . '\\add_settings');

// wp-json/socialify/v1/google/
add_action('rest_api_init', function () {
register_rest_route('socialify/v1', PROVIDER_KEY, [
'methods' => 'GET',
'callback' => function ( \WP_REST_Request $req ) {
$config = get_config();
if (empty($config)) {
return new \WP_Error( '502', esc_html__( 'Config error', 'socialify' ), array( 'status' => 502 ) );
}
try{
$adapter = new \Hybridauth\Provider\Google($config);
if (!empty($_REQUEST['redirect_to'])) {
$redirect_to = $_REQUEST['redirect_to'];
$adapter->getStorage()->set('socialify_redirect_to', $redirect_to);
}


if ($accessToken = $adapter->getAccessToken()) {
$adapter->setAccessToken($accessToken);
}
$adapter->authenticate();

$data = [
'user_profile' => $adapter->getUserProfile(),
'redirect_to' => $adapter->getStorage()->get('socialify_redirect_to'),
];

$adapter->disconnect();

do_action('socialify_auth_handle', $data['user_profile'], PROVIDER_KEY, $data['redirect_to']);

//Set process data
// $auth_process_data['user_data'] = $adapter->getUserProfile();
// $auth_process_data['redirect_to'] = $adapter->getStorage()->get('socialify_redirect_to');
// $auth_process_data['provider'] = 'google';

//Disconnect the adapter & destroy session

return json_encode(["message" => "Authorized skiped"]);

}
catch(\Exception $e){
return new \WP_Error( '502', $e->getMessage(), array( 'status' => 502 ) );
}
},
'permission_callback' => '__return_true'
]);
});

// add_filter('socialify_auth_process', __NAMESPACE__ . '\\handle', 11, 2);

function get_config()
{
$options = \Socialify\Settings\get();

if (empty($options['google_client_id']) || empty($options['google_client_secret'])) {
return false;
}

$config = [
'callback' => get_endpoint(),
'keys' => [
'id' => $options['google_client_id'] ?? null,
'secret' => $options['google_client_secret'] ?? null,
],
//'scope' => 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email',
'authorize_url_parameters' => [
'approval_prompt' => 'force',
'access_type' => 'offline',
// to pass only when you need to acquire a new refresh token.
],
//'debug_mode' => 'debug',
//'debug_file' => __FILE__ . '.log',
];


return $config;
}


function get_auth_url_with_redirect_to_current_page(){
global $wp;
return add_query_arg('redirect_to', home_url( $wp->request), get_endpoint());
}

function get_endpoint()
{
return rest_url('socialify/v1/' . PROVIDER_KEY);
}


function add_settings()
{
$section_id = 'google';
$option_key = \Socialify\Settings\OPTION_KEY;
$option_page = \Socialify\Settings\OPTION_PAGE;

add_settings_section(
$section_id,
"Google",
function () {
?>
<details>
<summary>Help</summary>
<ol>
<li>
<span>
<?= __('Get settings for Googla App: ', 'socialify') ?>
</span>
<a href="https://console.developers.google.com/apis/credentials/"
target="_blank">https://console.developers.google.com/apis/credentials</a>
</li>
<li>Callback URI use this: <code><?= get_endpoint() ?></code></li>
<li>URL for site: <code><?= site_url() ?></code></li>
<li>Domain: <code><?= $_SERVER['SERVER_NAME'] ?></code></li>
</ol>
</details>
<?php
},
$option_page
);

add_settings_field(
'google_client_id',
'Client ID',
function ($args) {
printf(
'<input type="text" name="%s" value="%s" size="77">',
$args['name'], $args['value']
);
},
$option_page,
$section_id,
$args = [
'name' => $option_key . '[google_client_id]',
'value' => get_option($option_key)['google_client_id'] ?? '',
]
);

add_settings_field(
'google_client_secret',
'Secret Token',
function ($args) {
printf(
'<input type="text" name="%s" value="%s" size="77">',
$args['name'], $args['value']
);
},
$option_page,
$section_id,
$args = [
'name' => $option_key . '[google_client_secret]',
'value' => get_option($option_key)['google_client_secret'] ?? '',
]
);


}
File renamed without changes.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
Socialify for WordPress - Social Login, OAuth2, HybridAuth
=============

## Features
# Features
- Google Login
- Facebook Login
- Yandex Login https://github.com/uptimizt/socialify-yandex-login
- Vkontakte Login https://github.com/uptimizt/socialify-vkontakte-login
- auto register user
- automatic user detection by e-mail
- self hosted, complete security, no 3rd cloud storage

## Other

sponsor link
https://bizzapps.ru/p/telegram-open-network/
# Addons
- Facebook
- Instagram
- GitHub
- Telegram
- Yandex
- Vkontakte
- the list of providers will be expanded soon

https://github.com/uptimizt/tecomments
# roadmap
- apple
- microsoft
38 changes: 0 additions & 38 deletions assets/svg/facebook.svg

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": {
"hybridauth/hybridauth": "^3.0"
"hybridauth/hybridauth": "^3.9.0"
}
}
148 changes: 77 additions & 71 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading