{% extends "SsoHelpBundle:Layout:base.html.twig" %}

{% block title %}{{ parent() }} - Overwiew{% endblock %}

{% block body %}
    <h1>Help</h1>
    <div class="alert alert-info alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
                    aria-hidden="true">&times;</span></button>
        <strong>Info!</strong>
        <p>The webservice works xml based.
            To use the webservice, you need an useridentifier and since version 0.15.0 your username, which you may
            receive from your Identity-Provider (IdP).
            Use your username and password for login at your IdP. You can do this manually or by sending SAML-requests
            to the Idp.<br/><br/>
            If you want to use version2 you only have to modify your header to:<strong> "API-VERSION: 2"</strong>
        </p>
    </div>

    <div class="alert alert-danger alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
                    aria-hidden="true">&times;</span></button>
        <strong>Warning for bulk operations!</strong>
        <p>
            All services in version1 supporting bulk operations. This means that you can for example add multiple users
            with one request.<br/>
        </p>
        <br/>
        <h3 style="margin:0;">The version2 currently supports no bulk operations!!!</h3>
    </div>

    <h3>Simple Request Example</h3>
    <span class="label label-pill label-primary">version 1</span>
    <span class="label label-pill label-success">version 2</span>
    <br/><br/>
    <pre>
&lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;SsoRequest&gt;
   &lt;Credentials&gt;
        &lt;ServiceProvider&gt;
            &lt;ServiceToken&gt;V2030cOhc6Vttcxs67mXjcPJJNk7wxoAw8WUTk0IMYa&lt;/ServiceToken&gt;
            &lt;ServiceName&gt;MyService&lt;/ServiceName&gt;
        &lt;/ServiceProvider&gt;
        &lt;ServiceTrigger&gt;
            &lt;Username&gt;MyServiceConsumerName&lt;/Username&gt;
            &lt;UserIdentifier&gt;5e211de5c4aa76564fc590128beced60402c7b8036b725ba71&lt;/UserIdentifier&gt;
        &lt;/ServiceTrigger&gt;
        &lt;ApplicationUser&gt;
            &lt;Username&gt;MyApplicationUsername&lt;/Username&gt;
            &lt;UserIdentifier&gt;828efa02838efb200c0590128beced60402c72983f2cca9299&lt;/UserIdentifier&gt;
        &lt;/ApplicationUser&gt;
        &lt;ServiceCountry&gt;
            &lt;Code&gt;DE&lt;/Code&gt;
        &lt;/ServiceCountry&gt;
    &lt;/Credentials&gt;
    &lt;User&gt;
        &lt;Add&gt;
            &lt;Value&gt;
                &lt;UserType&gt;
                    &lt;Email&gt;JohnDoe@example.com&lt;/Email&gt;
                    &lt;Username&gt;JohnDoe&lt;/Username&gt;
                    &lt;Firstname&gt;John&lt;/Firstname&gt;
                    &lt;Lastname&gt;Doe&lt;/Lastname&gt;
                    &lt;Password&gt;secre_T8&lt;/Password&gt;
                    &lt;Active&gt;1&lt;/Active&gt;
                &lt;/UserType&gt;
            &lt;/Value&gt;
        &lt;/Add&gt;
    &lt;/User&gt;
&lt;/SsoRequest&gt;</pre>
    <p>The <a href="{{ path('_sso_help_type_servicetoken') }}">ServiceToken</a> is unique for your application. It must
        be generated manually by your webservice-administator. Your Permissions are bind to this Token.
        The <a href="{{ path('_sso_help_type_servicename') }}">ServiceName</a> is not checked yet, but must be present
        and should not be emtpy. The <a href="{{ path('_sso_help_type_string') }}">Username</a> within the
        ServiceTrigger-Tag is the consumers username, you used, to get your
        <a href="{{ path('_sso_help_type_useridentifier') }}">UserIdentifier</a> from the IdP.</p>
    <p><strong>New: </strong> The ApplicationUser contains additional credentials of applications logged in user to
        filter the service results. This is only necessary if the used token has restricted data access. The strength
        of the filter depends on the current projects needs.</p>
    <p>The <a href="{{ path('_sso_help_type_servicecountrycode') }}">Country-Code</a> is not used yet, but will be
        important in future releases. It must be present and must be a ISO-3166-1 alpha-2 string.</p>
    <p>The element <strong>User</strong> represents the controller-name, the element <strong>Add</strong> the
        action-name. Everything inside the action-tag depents on the selected controller-action-combination.</p>
    <h2>Example for a more complex xml-request</h2>
    <p>It is possible, to process more than one action in one request. The actions must be from the same type in the
        same controller.</p>
    <pre>&lt;SsoRequest&gt;
    &lt;Credentials&gt;
        &lt;ServiceProvider&gt;
            &lt;ServiceToken&gt;V2030cOhc6Vttcxs6r6bmtI2ZOrJ7mXjcPJJNk7wxoAw8WUTk0IMYa&lt;/ServiceToken&gt;
            &lt;ServiceName&gt;MyService&lt;/ServiceName&gt;
        &lt;/ServiceProvider&gt;
        &lt;ServiceTrigger&gt;
            &lt;Username&gt;MyServiceConsumerName&lt;/Username&gt;
            &lt;UserIdentifier&gt;5e211de5c4aa765610417388f590128beced60402c7b8036b725ba71&lt;/UserIdentifier&gt;
        &lt;/ServiceTrigger&gt;
        &lt;ApplicationUser&gt;
            &lt;Username&gt;MyApplicationUsername&lt;/Username&gt;
            &lt;UserIdentifier&gt;828efa02838efb200c0590128beced60402c72983f2cca9299&lt;/UserIdentifier&gt;
        &lt;/ApplicationUser&gt;
        &lt;ServiceCountry&gt;
            &lt;Code&gt;DE&lt;/Code&gt;
        &lt;/ServiceCountry&gt;
    &lt;/Credentials&gt;
    &lt;User&gt;
        &lt;Add&gt;
            &lt;Value&gt;
                &lt;UserType&gt;
                    &lt;Email&gt;JohnDoe1@example.com&lt;/Email&gt;
                    &lt;Username&gt;JohnDoe1&lt;/Username&gt;
                    &lt;Firstname&gt;John1&lt;/Firstname&gt;
                    &lt;Lastname&gt;Doe1&lt;/Lastname&gt;
                    &lt;Password&gt;secre_T81&lt;/Password&gt;
                    &lt;Active&gt;1&lt;/Active&gt;
                &lt;/UserType&gt;
            &lt;/Value&gt;
        &lt;/Add&gt;
        &lt;Add&gt;
            &lt;Value&gt;
                &lt;UserType&gt;
                    &lt;Email&gt;JohnDoe2@example.com&lt;/Email&gt;
                    &lt;Username&gt;JohnDoe2&lt;/Username&gt;
                    &lt;Firstname&gt;John2&lt;/Firstname&gt;
                    &lt;Lastname&gt;Doe2&lt;/Lastname&gt;
                    &lt;Password&gt;secre_T82&lt;/Password&gt;
                    &lt;Active&gt;1&lt;/Active&gt;
                &lt;/UserType&gt;
            &lt;/Value&gt;
        &lt;/Add&gt;
        &lt;Add&gt;
            &lt;Value&gt;
                &lt;UserType&gt;
                    &lt;Email&gt;JohnDoe3@example.com&lt;/Email&gt;
                    &lt;Username&gt;JohnDoe3&lt;/Username&gt;
                    &lt;Firstname&gt;John3&lt;/Firstname&gt;
                    &lt;Lastname&gt;Doe3&lt;/Lastname&gt;
                    &lt;Password&gt;secre_T83&lt;/Password&gt;
                    &lt;Active&gt;1&lt;/Active&gt;
                &lt;/UserType&gt;
            &lt;/Value&gt;
        &lt;/Add&gt;
    &lt;/User&gt;
&lt;/SsoRequest&gt;</pre>
    <h2>Sample curl request with php (using .htacces )</h2>
    <pre>
// url ot the webservice
$url = "{{ app.request.scheme }}://{{ app.request.host }}{{ path('_sso_webservice_service') }}";

// .htaccess username
$username = "sso";

// .htaccess password
$password = "xxxxx";

// curls header !
$headers = array(
	'API-VERSION: 1',
	'API-CONTROLLER: User',
	'API-ACTION: Add',
	'Content-Type: text/xml'
);

$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $url);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_USERPWD, $username.":".$password);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($connection, CURLOPT_TIMEOUT, 200);

curl_setopt($connection, CURLOPT_POSTFIELDS, $xml);
$response = curl_exec($connection);
$c_error  = curl_error($connection);
if ($c_error) {
	$c_error_no = curl_errno($connection);
	throw new ErrorException("Server Error " . $c_error_no . ' : ' . $c_error);
}
curl_close($connection);
header("Content-type: text/xml");
echo $response;
    </pre>


{% endblock %}

