You may want to have the wp2print site linked to an external site in such a way that users do not need to log-in 2 times when moving from the external site to the wp2print site. Users are expected to login to the external site first. In the external site, the user will click a button. The user will then be re-directed to the wp2print already logged-in. This entire process is called "Single Sign-on".
wp2print contains an API that permits account functions from external sites. The API includes 3 methods:
The exists method allows the external site to test whether an account already exists for a given username. The data method allows the external site to create new user accounts and to update the data in an existing user's account in wp2print. The login method allows the user to be automatically logged in when they arrive from the external site.
All POSTs attempting to use the single sign-on API must contain a FORM field "hash":
The “hash” field is the SHA256 hash of the concatenation of the API Key, username, and unix time fields.
Here is an example of a hash calculation for the case where:
API Key: 1234567890abcde
user: myuser
unixtime: 1506450751
hash = sha256("1234567890abcdemyuser1506450751")
External websites can test whether an account already exists for a given username via the exists method from the Single Sign-On API. The external website should assemble a FORM and POST this to the wp2print site. The FORM should contain the following items:
<form action="[URL for wp2print site]" method="POST">
<input type="hidden" name="method" value="exists">
<input type="hidden" name="user" value="[username in wp2print site]">
<input type="hidden" name="time" value="[unix time]">
<input type="hidden" name="hash" value="[hash]">
<input type="submit" value="SUBMIT">
</form>
If the user account already exists, you will receive response: TRUE
If the user account does not exist, you will receive response: FALSE
External websites can create a new user account in wp2print sites by using the data method of the Single Sign-On API. The external website should assemble a FORM and POST this to the wp2print site. The FORM must contain first 5 elements as shown below. All the other FORM elements are optional.
Note that the value for the FORM field "user" = "admin". The key field used to identify the wp2print account to be created is the email field.
<form action="https://[mydomain.com]" method="POST">
/* Required fields */
<input type="hidden" name="method" value="data">
<input type="hidden" name="user" value="admin">
<input type="hidden" name="time" value="[unix time]">
<input type="hidden" name="hash" value="[hash]">
<input type="hidden" name="email" value="[Email address of new user account in wp2print]">
/* End required fields */
/* Optional fields */
<input type="hidden" name="firstName" value="[New value]">
<input type="hidden" name="lastName" value="[New value]">
<input type="hidden" name="billing_first_name" value="[New value]">
<input type="hidden" name="billing_last_name" value="[New value]">
<input type="hidden" name="billing_company" value="[New value]">
<input type="hidden" name="billing_address_1" value="[New value]">
<input type="hidden" name="billing_address_2" value="[New value]">
<input type="hidden" name="billing_city" value="[New value]">
<input type="hidden" name="billing_postcode" value="[New value]">
<input type="hidden" name="billing_country" value="[ISO 2-character code for new country]">
<input type="hidden" name="billing_state" value="[ISO 2-character code for new state]">
<input type="hidden" name="billing_email" value="[New value]">
<input type="hidden" name="billing_phone" value="[New value]">
<input type="hidden" name="shipping_first_name" value="[New value]">
<input type="hidden" name="shipping_last_name" value="[New value]">
<input type="hidden" name="shipping_company" value="[New value]">
<input type="hidden" name="shipping_address_1" value="[New value]">
<input type="hidden" name="shipping_address_2" value="[New value]">
<input type="hidden" name="shipping_city" value="[New value]">
<input type="hidden" name="shipping_postcode" value="[New value]">
<input type="hidden" name="shipping_country" value="[ISO 2-character code for new country]">
<input type="hidden" name="shipping_state" value="[ISO 2-character code for new state]">
<input type="hidden" name="groupid" value="[numeric groupID]">
/* End optional fields */
<input type="submit" value="SUBMIT">
</form>
External websites can update a user's account data in wp2print sites by using the data method from the Single Sign-On API. The external website should assemble a FORM and POST this to the wp2print site. The FORM must contain first 5 elements as shown below. All the other FORM elements are required only for those fields that are to be updated.
Note that the value for the FORM field "user" = "admin". The key field used to identify the wp2print account to be updated is the wp2print e-mail address field.
It is not possible to update the wp2print username field or the wp2print e-mail field for the user:
<form action="https://[mydomain.com]" method="POST">
/* Required fields */
<input type="hidden" name="method" value="data">
<input type="hidden" name="user" value="admin">
<input type="hidden" name="time" value="[unix time]">
<input type="hidden" name="hash" value="[hash]">
<input type="hidden" name="email" value="[Email address of user account in wp2print]">
/* End required fields */
/* Optional fields */
<input type="hidden" name="firstName" value="[New value]">
<input type="hidden" name="lastName" value="[New value]">
<input type="hidden" name="billing_first_name" value="[New value]">
<input type="hidden" name="billing_last_name" value="[New value]">
<input type="hidden" name="billing_company" value="[New value]">
<input type="hidden" name="billing_address_1" value="[New value]">
<input type="hidden" name="billing_address_2" value="[New value]">
<input type="hidden" name="billing_city" value="[New value]">
<input type="hidden" name="billing_postcode" value="[New value]">
<input type="hidden" name="billing_country" value="[ISO 2-character code for new country]">
<input type="hidden" name="billing_state" value="[ISO 2-character code for new state]">
<input type="hidden" name="billing_email" value="[New value]">
<input type="hidden" name="billing_phone" value="[New value]">
<input type="hidden" name="shipping_first_name" value="[New value]">
<input type="hidden" name="shipping_last_name" value="[New value]">
<input type="hidden" name="shipping_company" value="[New value]">
<input type="hidden" name="shipping_address_1" value="[New value]">
<input type="hidden" name="shipping_address_2" value="[New value]">
<input type="hidden" name="shipping_city" value="[New value]">
<input type="hidden" name="shipping_postcode" value="[New value]">
<input type="hidden" name="shipping_country" value="[ISO 2-character code for new country]">
<input type="hidden" name="shipping_state" value="[ISO 2-character code for new state]">
<input type="hidden" name="groupid" value="[numeric groupID]">
/* End optional fields */
<input type="submit" value="SUBMIT">
</form>
External websites can automatically log users in to wp2print sites by using the login method from the Single Sign-On API. The external website should assemble a FORM and POST this to the wp2print site. The FORM should contain the following items:
<form action="[URL for wp2print site]" method="POST">
<input type="hidden" name="method" value="login">
<input type="hidden" name="user" value="[username in wp2print site]">
<input type="hidden" name="time" value="[unix time]">
<input type="hidden" name="hash" value="[hash]">
<input type="submit" value="SUBMIT">
</form>