create account

RE: Integrate Steemconnect V2 User Authorisation Into Any WordPress Website by freetissues

View this thread on: hive.blogpeakd.comecency.com

Viewing a response to: @steempytutorials/integrate-steemconnect-v2-user-authorisation-into-any-wordpress-website

· @freetissues ·
Thank you for wondefull tuts. I managed to follow Part 1 and got the login for the user. Now trying to follow this tut but I find it hard to find where I need to add these to make it work.  Have to say total noob here.
👍  
properties (23)
authorfreetissues
permlinkre-steempytutorials-integrate-steemconnect-v2-user-authorisation-into-any-wordpress-website-20180731t104221224z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-07-31 10:42:24
last_update2018-07-31 10:42:24
depth1
children2
last_payout2018-08-07 10:42:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length218
author_reputation475,604,110,215
root_title"Integrate Steemconnect V2 User Authorisation Into Any WordPress Website"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,623,150
net_rshares1,151,562,821
author_curate_reward""
vote details (1)
@juliank ·
$0.10
Glad to hear that. You can place the code inside a special file, lets say authentication.php and then include this file into the header.php.

Basically, the page where the user will get redirectes back to. The uri you set in the link. That page will need to have the file included
👍  
properties (23)
authorjuliank
permlinkre-freetissues-re-steempytutorials-integrate-steemconnect-v2-user-authorisation-into-any-wordpress-website-20180731t115827590z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-07-31 11:58:24
last_update2018-07-31 11:58:24
depth2
children0
last_payout2018-08-07 11:58:24
cashout_time1969-12-31 23:59:59
total_payout_value0.076 HBD
curator_payout_value0.025 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length280
author_reputation117,823,071,447,502
root_title"Integrate Steemconnect V2 User Authorisation Into Any WordPress Website"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,629,594
net_rshares60,689,117,289
author_curate_reward""
vote details (1)
@steempytutorials ·
$0.10
To give a bit more detail. 

I have a file authentication.php

```
<?php
  if (isset($_GET['code'])) {

    // Params for POST request
    $data = array(
        'code' => $_GET['code'],
        'client_secret' => SC_CLIENT_SECRET
    );

    $payload = json_encode($data);

    // Prepare new cURL resource
    $ch = curl_init('https://steemconnect.com/api/oauth2/token');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

    // Set HTTP Header for POST request
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($payload))
    );

    // Submit the POST request
    $result = curl_exec($ch);

    // Close cURL session handle
    curl_close($ch);

    $json = json_decode($result);
    $date = date("Y/m/d H:G:s", time() + $json->expires_in);

    // Add tokens to the database
    global $wpdb;
    $wpdb->query("INSERT INTO `steem_authorization` (`id`, `access_token`, " .
    "`user_login`, `expires_in`, `refresh_token`) VALUES (NULL, " .
    "'" . $json->access_token . "', '" . $json->username ."', '" .
    $date . "', '" . $json->refresh_token ."') ON DUPLICATE KEY UPDATE " .
    "`user_login`='" . $json->username ."';");
  }

?>
```

The client secret, I set that in wp-config.php

```
'client_secret' => SC_CLIENT_SECRET
```

Then inside the template file of the page I want to add a authorise button I have added the following code:
```
// import steemconnet authentication
include 'authenticate.php';

// see if current user is logged in and has authenticated voting
// permissions in the database
global $wpdb;
$current_user = wp_get_current_user();
```
This includes the file and get the username.

Then lasty I check if the user has already authorised the app if not it shows a button to do so.

```
echo '<div>';
// Check if user is logged in
if ($current_user->user_login == ''){
  echo '<div align="center"><br><h1>You need to <a href="https://ste' .
  'emautomated.eu/wp-login.php?action=wordpress_social_authenticate&' .
  'mode=login&provider=Steemconnect&redirect_to=' . get_permalink() .
  '">log in</a></h1></div>';
} else {
  // Check if logged in user has authorised the app
  $results = $wpdb->get_results('SELECT * FROM `steem_authorization` ' .
  'WHERE `user_login` = "' . $current_user->user_login . '"');
      if (count($results) == 0){
        echo '<div align="center"><h1><br>Authorize <font color=' .
        '"blue">@steemautomated</font> to vote for you.</h1><br><a ' .
        'class="maxbutton-1 maxbutton maxbutton-steemconnect" href=' .
        '"https://steemconnect.com/oauth2/authorize?client_id=' .
        'steemautomated&redirect_uri=' . get_permalink() .'&response_' .
        'type=code&scope=offline,vote"><span class="mb-text">' .
        'Authorize</span></a></div><br>';
  }
}
echo '</div>';
```
👍  
properties (23)
authorsteempytutorials
permlinkre-freetissues-re-steempytutorials-integrate-steemconnect-v2-user-authorisation-into-any-wordpress-website-20180731t135136668z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-07-31 13:51:36
last_update2018-07-31 13:51:36
depth2
children0
last_payout2018-08-07 13:51:36
cashout_time1969-12-31 23:59:59
total_payout_value0.079 HBD
curator_payout_value0.025 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,976
author_reputation31,094,047,689,691
root_title"Integrate Steemconnect V2 User Authorisation Into Any WordPress Website"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,640,643
net_rshares61,729,502,157
author_curate_reward""
vote details (1)