Multiscreen White Label Setup

Overview

Using the DudaAPI, you can build a full-fledged site creation implementation into your own platform. The flow for this would be as follows:

Display a list of templates --> User selects template they want --> Create the new site based off site selection (optional to include existing site URL to import content from) --> Create a sub-user account with user's email --> Grant access for the sub-user to access the newly created site --> Log the user into your branded editor so they can edit or build the newly created site.

The guide is broken into four steps, with the final one providing all the code needed to implement the flow described above.

Target Audience

DudaPro partners looking to integrate automatic multi-screen site creation and user login into an existing website. 

Essentials before getting started

Be a DudaPro Partner and have requested API access. Have your API credentials ready, including the SSO key and secret key. Also have a web server with PHP installed. 

Steps to implement:

1) Get all templates and display them

File: step-1-preview-templates.php

The first step of implementing the white label setup is to display a preview of all available templates. In order to do this, we will call the DudaAPI to get an array of the available templates. We will then loop through the array and print the results in a table based layout. 

API URL: https://api.dudamobile.com/api/sites...reen/templates

URL Parameters: none

Success response code: [http_code] => 200

PHP Code example: (replace {parameter} with actual value)

<?php
//Set API user and password
define("API_USER","xxxxxxxxxx");
define("API_PASS","yyyyyyyyyy");
//Set parameters to make cURL call to Duda
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/sites/multiscreen/templates');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
//execute cURL call and get template data
$output = curl_exec($ch);
//check for errors in cURL
if(curl_errno($ch)) {
    die('Curl error: ' . curl_error($ch));
}
$output = json_decode($output);
//Loop through all templates and display all the available templates in a table
echo '<table><thead><tr><th>Template Name</th><th>Template Image</th><th>Template Id</th></tr></thead>';
foreach($output as $template) {
    echo '<tr>';
    echo '<td>' . $template->template_name . '</td>';
    echo '<td><a href="'.$template->preview_url.'" target="_blank"><img src="'. $template->thumbnail_url. '"></a>' . '</td>';
    echo '<td>' . $template->template_id . '</td>';
    echo '</tr>';
}
echo '</table>';
?>

This will display all templates to choose from. You can then click on each image and see a live preview of the template. The page should produce something similar to this:

2) Create Site

File: step-2-create-site.php

API URL: https://api.dudamobile.com/api/sites...iscreen/create

Data:  template_id & url

Success response code: [http_code] => 200

Using the layout we've created, we will want to enable our users to select the template and then create a new site based off of the selection. We will also use Duda's option to import data from an existing URL. This filed is optional, but can be helpful for importing content into the selected template. For a little code maintainability, the main components of the program have been divided into functions.

The first thing we did was add a form next to the template. It adds a form to the right of the template and asks the user to input a URL and choose the template. 

create-site-input.jpg

We then add a check to the top of the code to see if a user submitted the form. If they have, we call the create site function to create the site and print out the unique site name. 

API URL: https://api.dudamobile.com/api/sites...reen/templates

URL Parameters: none

Success response code: [http_code] => 200

PHP Code example:

01 <?php
02 //Set API user and password
03 define("API_USER","xxxxxxxxxx");
04 define("API_PASS","yyyyyyyyyy");
05 //Check if a template was selected from page
06 if (isset($_GET['template_id'])) {
07     //if site was selected, use the template_id and original url (if set) to create a new site
08     $createdSite = createSite($_GET['template_id'],$_GET['original_url']);
09     echo $createdSite;
10 }
11 //if a template was note selected, display template selection
12 else {
13     displayTemplates();
14 }
15 function createSite($tempalte_id,$original_url) {
16     //create array with data
17     if($original_url) {
18         $data =array("template_id"=>$_GET['template_id'],"url"=>$original_url);   
19     } else {
20         $data = array("template_id"=>$_GET['template_id']);
21     }
22     //turn data into json to pass via cURL
23     $data = json_encode($data);
24     //Set cURL parameters
25     $ch = curl_init();
26     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
27     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/sites/multiscreen/create');
28     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
29     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
30     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
31     curl_setopt($ch, CURLOPT_TIMEOUT, 10);
32     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
33     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
34     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
35     //execute cURL call and get template data
36     $output = curl_exec($ch);
37     //check for errors in cURL
38     if(curl_errno($ch)) {
39         die('Curl error: ' . curl_error($ch));
40     }
41     $output = json_decode($output);
42     return $output->site_name;
43 }
44 function displayTemplates() {
45     //Set parameters to make cURL call to Duda
46     $ch = curl_init();
47     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
48     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/sites/multiscreen/templates');
49     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
50     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
51     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
52     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
53     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
54     //execute cURL call and get template data
55     $output = curl_exec($ch);
56     //check for errors in cURL
57     if(curl_errno($ch)) {
58         die('Curl error: ' . curl_error($ch));
59     }
60     $output = json_decode($output);
61     //Loop through all templates and display all the available templates in a table
62     echo '<table><thead><tr><th>Template Name</th><th>Template Image</th><th>Template Id</th></tr></thead>';
63     foreach($output as $template) {
64         echo '<tr>';
65         echo '<td>' . $template->template_name . '</td>';
66         echo '<td><a href="' . $template->preview_url . '" target="_blank"><img src="' . $template->thumbnail_url. '"></a>' . '</td>';
67         echo '<td><form method="GET" action=' . $_SERVER['PHP_SELF'] . '>';
68         echo '<input type="hidden" name="template_id" value="' . $template->template_id . '">';
69         echo '<input type="url" name="original_url" placeholder="Existing Site URL">';
70         echo '<button type="submit">Choose Site</button>';
71         echo '</form></td>';
72         echo '</tr>';
73     }
74     echo '</table>';
75 }
76 ?>

3) Create Account and Grant Access

The next step will allow us to accept an email input, create an account and grant access to the created site. To do this, we must alter our form to accept an email input. We then must create a sub-account based on the email provided. Finally, we have to grant access to the site on the sub-account. 

The code below will print the result as it happens. This is all transparent to the user. 

API URL: 

URL Parameters: Account Name (e-mail) and Site Name, returned after creating the first site.

PHP Code example:

001 <?php
002 //Set API user and password
003 define("API_USER","xxxxxxxxxx");
004 define("API_PASS","yyyyyyyyyy");
005 //Check if a template was selected from page
006 if (isset($_GET['template_id'])) {
007     //if site was selected, use the template_id and original url (if set) to create a new site
008     $createdSite = createSite($_GET['template_id'],$_GET['original_url']);
009     echo 'Site Created: ' . $createdSite . '<br/>';
010     $accountCreated = createSubAccount($_GET['email']);
011     echo 'Account created: ' . $accountCreated . '<br/>';
012     $grantAccess = grantAccountAccess($accountCreated,$createdSite);
013     echo 'Account granted access.<br/>';
014 }
015 //if a template was note selected, display template selection
016 else {
017     displayTemplates();
018 }
019 //Functions below
020 function grantAccountAccess($email,$siteName) {
021     $ch = curl_init();
022     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
023     //format URL to grant access to email and sitename passed
024     curl_setopt($ch, CURLOPT_URL, 'https://api.dudamobile.com/api/accounts/grant-access/'.$email.'/sites/'.$siteName);
025     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
026     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
027     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
028     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
029     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
030     //execute cURL call and get template data
031     $output = curl_exec($ch);
032     curl_close($ch);
033     return true;
034 }
035 function createSubAccount($emailToCreate) {
036     $data = '{"account_name":"'.$emailToCreate.'"}';
037     $ch = curl_init();
038     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
039     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/accounts/create');
040     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
041     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
042     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
043     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
044     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
045     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
046     //execute cURL call and get template data
047     $output = curl_exec($ch);
048     if(curl_getinfo($ch,CURLINFO_HTTP_CODE) == 204) {
049         curl_close($ch);
050         return $emailToCreate;
051     } else {
052         curl_close($ch);
053         die('Account creation failed, error: '. $output . '<br/>');
054     }
055 }
056 function createSite($tempalte_id,$original_url) {
057     //create array with data
058     if($original_url) {
059         $data =array("template_id"=>$_GET['template_id'],"url"=>$original_url);   
060     } else {
061         $data = array("template_id"=>$_GET['template_id']);
062     }
063     //turn data into json to pass via cURL
064     $data = json_encode($data);
065     //Set cURL parameters
066     $ch = curl_init();
067     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
068     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/sites/multiscreen/create');
069     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
070     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
071     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
072     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
073     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
074     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
075     //execute cURL call and get template data
076     $output = curl_exec($ch);
077     //check for errors in cURL
078     if(curl_errno($ch)) {
079         die('Curl error: ' . curl_error($ch));
080     }
081     $output = json_decode($output);
082     return $output->site_name;
083 }
084 function displayTemplates() {
085     //Set parameters to make cURL call to Duda
086     $ch = curl_init();
087     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
088     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/sites/multiscreen/templates');
089     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
090     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
091     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
092     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
093     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
094     //execute cURL call and get template data
095     $output = curl_exec($ch);
096     //check for errors in cURL
097     if(curl_errno($ch)) {
098         die('Curl error: ' . curl_error($ch));
099     }
100     $output = json_decode($output);
101     curl_close($ch);
102     //Loop through all templates and display all the available templates in a table
103     echo '<table><thead><tr><th>Template Name</th><th>Template Image</th><th>Template Id</th></tr></thead>';
104     foreach($output as $template) {
105         echo '<tr>';
106         echo '<td>' . $template->template_name . '</td>';
107         echo '<td><a href="'.$template->preview_url.'" target="_blank"><img src="' . $template->thumbnail_url. '"></a>' . '</td>';
108         echo '<td><form method="GET" action=' . $_SERVER['PHP_SELF'] . '>';
109         echo '<input type="hidden" name="template_id" value="' . $template->template_id . '">';
110         echo '<input type="url" name="original_url" placeholder="Existing Site URL">';
111         echo '<input type="email" name="email" placeholder="Your e-mail" required>';
112         echo '<button type="submit">Choose Site</button>';
113         echo '</form></td>';
114         echo '</tr>';
115     }
116     echo '</table>';
117 }
118 ?>

4) Logging the user into the editor

The final step is to log the user into the newly created site, inside of the white labeled editor. We will use all the information and components we've built so far: site name, email and successful access granting. To do this, we will generate an SSO signature and redirect the user to the URL of the editor. We've added a new function to generate the SSO link, using the site name and sub-account. 

In the final step, we add the SSO link function to generate a one-time login key. This allows us to redirect the user to the editor with the newly created site. 

File: step-4-genreate-sso.php

Parameters: Make sure below you fill in: API_USER, API_PASS, {your.customdomain.com}, {your_partner_key}, and {your_partner_secret_key}

001 <?php
002 //Set API user and password
003 define("API_USER","xxxxxxxxxx");
004 define("API_PASS","yyyyyyyyyy");
005 //Check if a template was selected from page
006 if (isset($_GET['template_id'])) {
007     //if site was selected, use the template_id and original url (if set) to create a new site
008     $createdSite = createSite($_GET['template_id'],$_GET['original_url']);
009     //echo 'Site Created: ' . $createdSite . '<br/>';
010     $accountCreated = createSubAccount($_GET['email']);
011     //echo 'Account created: ' . $accountCreated . '<br/>';
012     $grantAccess = grantAccountAccess($accountCreated,$createdSite);
013     //echo 'Account granted access.<br/>';
014     $sso_link = generateSSOLink($createdSite,$accountCreated);
015     header("Location: " . $sso_link);
016 }

Overview

Using the DudaAPI, you can build a full-fledged site creation implementation into your own platform. The flow for this would be as follows:

Display a list of templates --> User selects template they want --> Create the new site based off site selection (optional to include existing site URL to import content from) --> Create a sub-user account with user's email --> Grant access for the sub-user to access the newly created site --> Log the user into your branded editor so they can edit or build the newly created site.

The guide is broken into four steps, with the final one providing all the code needed to implement the flow described above.

Target Audience

DudaPro partners looking to integrate automatic multi-screen site creation and user login into an existing website. 

Essentials before getting started

Be a DudaPro Partner and have requested API access. Have your API credentials ready, including the SSO key and secret key. Also have a web server with PHP installed. 

Steps to implement:

Download Full implementation code:https://support.dudamobile.com/@api/deki/files/4928/multiscreen-full-white-label.zip

1) Get all templates and display them

File: step-1-preview-templates.php

The first step of implementing the white label setup is to display a preview of all available templates. In order to do this, we will call the DudaAPI to get an array of the available templates. We will then loop through the array and print the results in a table based layout. 

API URL: https://api.dudamobile.com/api/sites...reen/templates

URL Parameters: none

Success response code: [http_code] => 200

PHP Code example: (replace {parameter} with actual value)

01 <?php
02 //Set API user and password
03 define("API_USER","xxxxxxxxxx");
04 define("API_PASS","yyyyyyyyyy");
05 //Set parameters to make cURL call to Duda
06 $ch = curl_init();
07 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
09 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
10 curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
11 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
12 curl_setopt($ch, CURLOPT_TIMEOUT, 10);
13 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
14 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
15 //execute cURL call and get template data
16 $output = curl_exec($ch);
17 //check for errors in cURL
18 if(curl_errno($ch)) {
19     die('Curl error: ' . curl_error($ch));
20 }
21 $output = json_decode($output);
22 //Loop through all templates and display all the available templates in a table
23 echo '<table><thead><tr><th>Template Name</th><th>Template Image</th><th>Template Id</th></tr></thead>';
24 foreach($output as $template) {
25     echo '<tr>';
26     echo '<td>' . $template->template_name . '</td>';
27     echo '<td><a href="'.$template->preview_url.'" target="_blank"><img src="'. $template->thumbnail_url. '"></a>' . '</td>';
28     echo '<td>' . $template->template_id . '</td>';
29     echo '</tr>';
30 }
31 echo '</table>';
32 ?>

This will display all templates to choose from. You can then click on each image and see a live preview of the template. The page should produce something similar to this:

templates-preview.jpg

2) Create Site

File: step-2-create-site.php

API URL: https://api.dudamobile.com/api/sites...iscreen/create

Data:  template_id & url

Success response code: [http_code] => 200

Using the layout we've created, we will want to enable our users to select the template and then create a new site based off of the selection. We will also use Duda's option to import data from an existing URL. This filed is optional, but can be helpful for importing content into the selected template. For a little code maintainability, the main components of the program have been divided into functions.

The first thing we did was add a form next to the template. It adds a form to the right of the template and asks the user to input a URL and choose the template. 

create-site-input.jpg

We then add a check to the top of the code to see if a user submitted the form. If they have, we call the create site function to create the site and print out the unique site name. 

API URL: https://api.dudamobile.com/api/sites...reen/templates

URL Parameters: none

Success response code: [http_code] => 200

PHP Code example:

01 <?php
02 //Set API user and password
03 define("API_USER","xxxxxxxxxx");
04 define("API_PASS","yyyyyyyyyy");
05 //Check if a template was selected from page
06 if (isset($_GET['template_id'])) {
07     //if site was selected, use the template_id and original url (if set) to create a new site
08     $createdSite = createSite($_GET['template_id'],$_GET['original_url']);
09     echo $createdSite;
10 }
11 //if a template was note selected, display template selection
12 else {
13     displayTemplates();
14 }
15 function createSite($tempalte_id,$original_url) {
16     //create array with data
17     if($original_url) {
18         $data =array("template_id"=>$_GET['template_id'],"url"=>$original_url);   
19     } else {
20         $data = array("template_id"=>$_GET['template_id']);
21     }
22     //turn data into json to pass via cURL
23     $data = json_encode($data);
24     //Set cURL parameters
25     $ch = curl_init();
26     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
27     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/sites/multiscreen/create');
28     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
29     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
30     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
31     curl_setopt($ch, CURLOPT_TIMEOUT, 10);
32     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
33     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
34     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
35     //execute cURL call and get template data
36     $output = curl_exec($ch);
37     //check for errors in cURL
38     if(curl_errno($ch)) {
39         die('Curl error: ' . curl_error($ch));
40     }
41     $output = json_decode($output);
42     return $output->site_name;
43 }
44 function displayTemplates() {
45     //Set parameters to make cURL call to Duda
46     $ch = curl_init();
47     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
48     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/sites/multiscreen/templates');
49     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
50     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
51     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
52     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
53     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
54     //execute cURL call and get template data
55     $output = curl_exec($ch);
56     //check for errors in cURL
57     if(curl_errno($ch)) {
58         die('Curl error: ' . curl_error($ch));
59     }
60     $output = json_decode($output);
61     //Loop through all templates and display all the available templates in a table
62     echo '<table><thead><tr><th>Template Name</th><th>Template Image</th><th>Template Id</th></tr></thead>';
63     foreach($output as $template) {
64         echo '<tr>';
65         echo '<td>' . $template->template_name . '</td>';
66         echo '<td><a href="' . $template->preview_url . '" target="_blank"><img src="' . $template->thumbnail_url. '"></a>' . '</td>';
67         echo '<td><form method="GET" action=' . $_SERVER['PHP_SELF'] . '>';
68         echo '<input type="hidden" name="template_id" value="' . $template->template_id . '">';
69         echo '<input type="url" name="original_url" placeholder="Existing Site URL">';
70         echo '<button type="submit">Choose Site</button>';
71         echo '</form></td>';
72         echo '</tr>';
73     }
74     echo '</table>';
75 }
76 ?>

3) Create Account and Grant Access

The next step will allow us to accept an email input, create an account and grant access to the created site. To do this, we must alter our form to accept an email input. We then must create a sub-account based on the email provided. Finally, we have to grant access to the site on the sub-account. 

The code below will print the result as it happens. This is all transparent to the user. 

API URL: 

URL Parameters: Account Name (e-mail) and Site Name, returned after creating the first site.

PHP Code example:

001 <?php
002 //Set API user and password
003 define("API_USER","xxxxxxxxxx");
004 define("API_PASS","yyyyyyyyyy");
005 //Check if a template was selected from page
006 if (isset($_GET['template_id'])) {
007     //if site was selected, use the template_id and original url (if set) to create a new site
008     $createdSite = createSite($_GET['template_id'],$_GET['original_url']);
009     echo 'Site Created: ' . $createdSite . '<br/>';
010     $accountCreated = createSubAccount($_GET['email']);
011     echo 'Account created: ' . $accountCreated . '<br/>';
012     $grantAccess = grantAccountAccess($accountCreated,$createdSite);
013     echo 'Account granted access.<br/>';
014 }
015 //if a template was note selected, display template selection
016 else {
017     displayTemplates();
018 }
019 //Functions below
020 function grantAccountAccess($email,$siteName) {
021     $ch = curl_init();
022     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
023     //format URL to grant access to email and sitename passed
024     curl_setopt($ch, CURLOPT_URL, 'https://api.dudamobile.com/api/accounts/grant-access/'.$email.'/sites/'.$siteName);
025     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
026     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
027     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
028     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
029     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
030     //execute cURL call and get template data
031     $output = curl_exec($ch);
032     curl_close($ch);
033     return true;
034 }
035 function createSubAccount($emailToCreate) {
036     $data = '{"account_name":"'.$emailToCreate.'"}';
037     $ch = curl_init();
038     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
039     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/accounts/create');
040     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
041     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
042     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
043     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
044     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
045     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
046     //execute cURL call and get template data
047     $output = curl_exec($ch);
048     if(curl_getinfo($ch,CURLINFO_HTTP_CODE) == 204) {
049         curl_close($ch);
050         return $emailToCreate;
051     } else {
052         curl_close($ch);
053         die('Account creation failed, error: '. $output . '<br/>');
054     }
055 }
056 function createSite($tempalte_id,$original_url) {
057     //create array with data
058     if($original_url) {
059         $data =array("template_id"=>$_GET['template_id'],"url"=>$original_url);   
060     } else {
061         $data = array("template_id"=>$_GET['template_id']);
062     }
063     //turn data into json to pass via cURL
064     $data = json_encode($data);
065     //Set cURL parameters
066     $ch = curl_init();
067     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
068     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/sites/multiscreen/create');
069     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
070     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
071     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
072     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
073     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
074     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
075     //execute cURL call and get template data
076     $output = curl_exec($ch);
077     //check for errors in cURL
078     if(curl_errno($ch)) {
079         die('Curl error: ' . curl_error($ch));
080     }
081     $output = json_decode($output);
082     return $output->site_name;
083 }
084 function displayTemplates() {
085     //Set parameters to make cURL call to Duda
086     $ch = curl_init();
087     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
088     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/sites/multiscreen/templates');
089     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
090     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
091     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
092     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
093     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
094     //execute cURL call and get template data
095     $output = curl_exec($ch);
096     //check for errors in cURL
097     if(curl_errno($ch)) {
098         die('Curl error: ' . curl_error($ch));
099     }
100     $output = json_decode($output);
101     curl_close($ch);
102     //Loop through all templates and display all the available templates in a table
103     echo '<table><thead><tr><th>Template Name</th><th>Template Image</th><th>Template Id</th></tr></thead>';
104     foreach($output as $template) {
105         echo '<tr>';
106         echo '<td>' . $template->template_name . '</td>';
107         echo '<td><a href="'.$template->preview_url.'" target="_blank"><img src="' . $template->thumbnail_url. '"></a>' . '</td>';
108         echo '<td><form method="GET" action=' . $_SERVER['PHP_SELF'] . '>';
109         echo '<input type="hidden" name="template_id" value="' . $template->template_id . '">';
110         echo '<input type="url" name="original_url" placeholder="Existing Site URL">';
111         echo '<input type="email" name="email" placeholder="Your e-mail" required>';
112         echo '<button type="submit">Choose Site</button>';
113         echo '</form></td>';
114         echo '</tr>';
115     }
116     echo '</table>';
117 }
118 ?>

4) Logging the user into the editor

The final step is to log the user into the newly created site, inside of the white labeled editor. We will use all the information and components we've built so far: site name, email and successful access granting. To do this, we will generate an SSO signature and redirect the user to the URL of the editor. We've added a new function to generate the SSO link, using the site name and sub-account. 

In the final step, we add the SSO link function to generate a one-time login key. This allows us to redirect the user to the editor with the newly created site. 

File: step-4-genreate-sso.php

Parameters: Make sure below you fill in: API_USER, API_PASS, {your.customdomain.com}, {your_partner_key}, and {your_partner_secret_key}

001 <?php
002 //Set API user and password
003 define("API_USER","xxxxxxxxxx");
004 define("API_PASS","yyyyyyyyyy");
005 //Check if a template was selected from page
006 if (isset($_GET['template_id'])) {
007     //if site was selected, use the template_id and original url (if set) to create a new site
008     $createdSite = createSite($_GET['template_id'],$_GET['original_url']);
009     //echo 'Site Created: ' . $createdSite . '<br/>';
010     $accountCreated = createSubAccount($_GET['email']);
011     //echo 'Account created: ' . $accountCreated . '<br/>';
012     $grantAccess = grantAccountAccess($accountCreated,$createdSite);
013     //echo 'Account granted access.<br/>';
014     $sso_link = generateSSOLink($createdSite,$accountCreated);
015     header("Location: " . $sso_link);
016 }
017 //if a template was note selected, display template selection
018 else {
019     displayTemplates();
020 }
021 //Functions below
022 function generateSSOLink($siteName,$account) {
023     //Set editor custom domain --
024 $editor_url = '{your.customdomain.com}';
025 //Set SSO Parameters
026 $dm_sig_site = $siteName;
027 $dm_sig_user = $account;
028 $dm_sig_partner_key = '{your_partner_key}';
029 $dm_sig_timestamp = date_timestamp_get(date_create());
030 $secret_key = '{your_partner_secret_key}';
031 //Concatenate sso strings so it can be encrypted
032 $dm_sig_string =$secret_key.'user='.$dm_sig_user.'timestamp='.$dm_sig_timestamp.'site='.$dm_sig_site.'partner_key='.$dm_sig_partner_key;
033 //Encrypt values
034 $dm_sig = hash_hmac('sha1', $dm_sig_string, $secret_key);
035 //Create SSO link
036 $sso_link = 'http://' . $editor_url.'/home/site/'.$dm_sig_site.'?dm_sig_partner_key='.$dm_sig_partner_key.'&dm_sig_timestamp='.$dm_sig_timestamp.'&dm_sig_user='.$dm_sig_user.'&dm_sig_site='.$dm_sig_site.'&dm_sig='.$dm_sig;
037 //return SSO link
038 return $sso_link;
039 }
040 function grantAccountAccess($email,$siteName) {
041     $ch = curl_init();
042     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
043     //format URL to grant access to email and sitename passed
044     curl_setopt($ch, CURLOPT_URL, 'https://api.dudamobile.com/api/accounts/grant-access/'.$email.'/sites/'.$siteName);
045     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
046     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
047     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
048     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
049     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
050     //execute cURL call and get template data
051     $output = curl_exec($ch);
052     curl_close($ch);
053     return true;
054 }
055 function createSubAccount($emailToCreate) {
056     $data = '{"account_name":"'.$emailToCreate.'"}';
057     $ch = curl_init();
058     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
059     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/accounts/create');
060     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
061     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
062     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
063     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
064     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
065     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
066     //execute cURL call and get template data
067     $output = curl_exec($ch);
068     if(curl_getinfo($ch,CURLINFO_HTTP_CODE) == 204) {
069         curl_close($ch);
070         return $emailToCreate;
071     } else {
072         curl_close($ch);
073         die('Account creation failed, error: '. $output . '<br/>');
074     }
075 }
076 function createSite($tempalte_id,$original_url) {
077     //create array with data
078     if($original_url) {
079         $data =array("template_id"=>$_GET['template_id'],"url"=>$original_url);   
080     } else {
081         $data = array("template_id"=>$_GET['template_id']);
082     }
083     //turn data into json to pass via cURL
084     $data = json_encode($data);
085     //Set cURL parameters
086     $ch = curl_init();
087     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
088     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/sites/multiscreen/create');
089     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
090     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
091     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
092     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
093     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
094     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
095     //execute cURL call and get template data
096     $output = curl_exec($ch);
097     //check for errors in cURL
098     if(curl_errno($ch)) {
099         die('Curl error: ' . curl_error($ch));
100     }
101     $output = json_decode($output);
102     return $output->site_name;
103 }
104 function displayTemplates() {
105     //Set parameters to make cURL call to Duda
106     $ch = curl_init();
107     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
108     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/sites/multiscreen/templates');
109     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
110     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
111     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
112     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
113     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
114     //execute cURL call and get template data
115     $output = curl_exec($ch);
116     //check for errors in cURL
117     if(curl_errno($ch)) {
118         die('Curl error: ' . curl_error($ch));
119     }
120     $output = json_decode($output);
121     curl_close($ch);
122     //Loop through all templates and display all the available templates in a table
123     echo '<table><thead><tr><th>Template Name</th><th>Template Image</th><th>Template Id</th></tr></thead>';
124     foreach($output as $template) {
125         echo '<tr>';
126         echo '<td>' . $template->template_name . '</td>';
127         echo '<td><a href="'. $template->preview_url .'" target="_blank"><img src="' . $template->thumbnail_url. '"></a>' . '</td>';
128         echo '<td><form method="GET" action=' . $_SERVER['PHP_SELF'] . '>';
129         echo '<input type="hidden" name="template_id" value="' . $template->template_id . '">';
130         echo '<input type="url" name="original_url" placeholder="Existing Site URL">';
131         echo '<input type="email" name="email" placeholder="Your e-mail" required>';
132         echo '<button type="submit">Choose Site</button>';
133         echo '</form></td>';
134         echo '</tr>';
135     }
136     echo '</table>';
137 }
138 ?>

You can see a live demo here of the final step: https://dudasupport.com/dudaapi/use-...PI-Example.php

020 }
021 //Functions below
022 function generateSSOLink($siteName,$account) {
023     //Set editor custom domain --
024 $editor_url = '{your.customdomain.com}';
025 //Set SSO Parameters
026 $dm_sig_site = $siteName;
027 $dm_sig_user = $account;
028 $dm_sig_partner_key = '{your_partner_key}';
029 $dm_sig_timestamp = date_timestamp_get(date_create());
030 $secret_key = '{your_partner_secret_key}';
031 //Concatenate sso strings so it can be encrypted
032 $dm_sig_string =$secret_key.'user='.$dm_sig_user.'timestamp='.$dm_sig_timestamp.'site='.$dm_sig_site.'partner_key='.$dm_sig_partner_key;
033 //Encrypt values
034 $dm_sig = hash_hmac('sha1', $dm_sig_string, $secret_key);
035 //Create SSO link
036 $sso_link = 'http://' . $editor_url.'/home/site/'.$dm_sig_site.'?dm_sig_partner_key='.$dm_sig_partner_key.'&dm_sig_timestamp='.$dm_sig_timestamp.'&dm_sig_user='.$dm_sig_user.'&dm_sig_site='.$dm_sig_site.'&dm_sig='.$dm_sig;
037 //return SSO link
038 return $sso_link;
039 }
040 function grantAccountAccess($email,$siteName) {
041     $ch = curl_init();
042     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
043     //format URL to grant access to email and sitename passed
044     curl_setopt($ch, CURLOPT_URL, 'https://api.dudamobile.com/api/accounts/grant-access/'.$email.'/sites/'.$siteName);
045     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
046     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
047     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
048     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
049     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
050     //execute cURL call and get template data
051     $output = curl_exec($ch);
052     curl_close($ch);
053     return true;
054 }
055 function createSubAccount($emailToCreate) {
056     $data = '{"account_name":"'.$emailToCreate.'"}';
057     $ch = curl_init();
058     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
059     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/accounts/create');
060     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
061     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
062     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
063     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
064     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
065     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
066     //execute cURL call and get template data
067     $output = curl_exec($ch);
068     if(curl_getinfo($ch,CURLINFO_HTTP_CODE) == 204) {
069         curl_close($ch);
070         return $emailToCreate;
071     } else {
072         curl_close($ch);
073         die('Account creation failed, error: '. $output . '<br/>');
074     }
075 }
076 function createSite($tempalte_id,$original_url) {
077     //create array with data
078     if($original_url) {
079         $data =array("template_id"=>$_GET['template_id'],"url"=>$original_url);   
080     } else {
081         $data = array("template_id"=>$_GET['template_id']);
082     }
083     //turn data into json to pass via cURL
084     $data = json_encode($data);
085     //Set cURL parameters
086     $ch = curl_init();
087     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
088     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/sites/multiscreen/create');
089     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
090     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
091     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
092     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
093     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
094     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
095     //execute cURL call and get template data
096     $output = curl_exec($ch);
097     //check for errors in cURL
098     if(curl_errno($ch)) {
099         die('Curl error: ' . curl_error($ch));
100     }
101     $output = json_decode($output);
102     return $output->site_name;
103 }
104 function displayTemplates() {
105     //Set parameters to make cURL call to Duda
106     $ch = curl_init();
107     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
108     curl_setopt($ch, CURLOPT_URL,'https://api.dudamobile.com/api/sites/multiscreen/templates');
109     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
110     curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
111     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
112     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
113     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
114     //execute cURL call and get template data
115     $output = curl_exec($ch);
116     //check for errors in cURL
117     if(curl_errno($ch)) {
118         die('Curl error: ' . curl_error($ch));
119     }
120     $output = json_decode($output);
121     curl_close($ch);
122     //Loop through all templates and display all the available templates in a table
123     echo '<table><thead><tr><th>Template Name</th><th>Template Image</th><th>Template Id</th></tr></thead>';
124     foreach($output as $template) {
125         echo '<tr>';
126         echo '<td>' . $template->template_name . '</td>';
127         echo '<td><a href="'. $template->preview_url .'" target="_blank"><img src="' . $template->thumbnail_url. '"></a>' . '</td>';
128         echo '<td><form method="GET" action=' . $_SERVER['PHP_SELF'] . '>';
129         echo '<input type="hidden" name="template_id" value="' . $template->template_id . '">';
130         echo '<input type="url" name="original_url" placeholder="Existing Site URL">';
131         echo '<input type="email" name="email" placeholder="Your e-mail" required>';
132         echo '<button type="submit">Choose Site</button>';
133         echo '</form></td>';
134         echo '</tr>';
135     }
136     echo '</table>';
137 }
138 ?>

You can see a live demo here of the final step: https://dudasupport.com/dudaapi/use-...PI-Example.php

Full implementation code for this is also attached to this article.

×

Priority Phone Support

English phone support is available 18 hours a day,
Monday through Friday, 3am to 9pm (EST).

United States +1 866-776-1550 3am to 9pm (Eastern)
United Kingdom +44 (0)800-011-9071 8am to 2am (London)
France +33 (0)9-75-18-84-74 9am to 3am (Paris)
Israel +972 (0)3-720-8922 10am to 4am (Jerusalem)
Australia +61 (0)2-8880-9166 7pm to 1pm (Sydney)
To schedule a call in French, Portuguese, Hebrew or Russian, please email us at prioritysupport@dudamobile.com
×

Please Log in as a DudaPro

Priority Phone Support is available exclusively to DudaPros. Log in to your DudaPro account now to see our international support numbers.

Log In
Not a DudaPro? Start a free trial now!