PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / 2.2.4
Wp Social Login and Register Social Counter v2.2.4
trunk 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.10 1.3.11 1.3.2 1.3.3 1.3.4 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.4 1.4.5 1.4.6 1.4.8 1.4.9 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.5 1.8.6 1.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.8 2.2.9 3.0.0 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0
wp-social / lib / login / line-app.php
wp-social / lib / login Last commit date
line-app.php 4 years ago
line-app.php
69 lines
1 <?php
2
3 namespace WP_Social\Lib\Login;
4
5 defined('ABSPATH') || exit;
6
7 class Line_App {
8
9 private $client_id;
10
11 private $client_secret;
12
13 public function __construct() {
14 $saved_settings = \WP_Social\App\Settings::get_login_settings_data();
15 if (!empty($saved_settings['lineapp'])) {
16 $this->client_id = $saved_settings['lineapp']['id'];
17 $this->client_secret = $saved_settings['lineapp']['secret'];
18 }
19 }
20
21 public function get_auth_url($redirect_uri) {
22 return "https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id=" . $this->client_id . "&redirect_uri=" . $redirect_uri . "&state=12345abcde&scope=profile%20openid%20email";
23 }
24
25 public function get_id_token($code) {
26 $redirect_uri = get_site_url() . '/wp-json/wslu-social-login/type/lineapp';
27
28 $response = wp_remote_post(
29 'https://api.line.me/oauth2/v2.1/token',
30 array(
31 'method' => 'POST',
32 'body' => array(
33 'grant_type' => 'authorization_code',
34 'code' => $code,
35 'redirect_uri' => $redirect_uri,
36 'client_id' => $this->client_id,
37 'client_secret' => $this->client_secret,
38 )
39 )
40 );
41
42 if (is_wp_error($response)) {
43 return $response->get_error_message();
44 }
45 return json_decode($response['body']);
46 }
47
48 public function get_user_info($code) {
49
50 $id_token = $this->get_id_token($code);
51
52 $response = wp_remote_post(
53 'https://api.line.me/oauth2/v2.1/verify',
54 array(
55 'method' => 'POST',
56 'body' => array(
57 'client_id' => $this->client_id,
58 'id_token' => $id_token->id_token,
59 )
60 )
61 );
62
63 if (is_wp_error($response)) {
64 return $response->get_error_message();
65 }
66 return json_decode($response['body']);
67 }
68 }
69