1<?php
2
3class OneLogin_Saml_AuthRequest
4{
5
6    /**
7     * @var OneLogin_Saml2_Auth object
8     */
9    protected $auth;
10
11    /**
12     * Constructs the OneLogin_Saml2_Auth, initializing
13     * the SP SAML instance.
14     *
15     * @param array|object $settings SAML Toolkit Settings
16     */
17    public function __construct($settings)
18    {
19        $this->auth = new OneLogin_Saml2_Auth($settings);
20    }
21
22    /**
23     * Obtains the SSO URL containing the AuthRequest
24     * message deflated.
25     *
26     * @param string|null $returnTo
27     *
28     * @return string
29     *
30     * @throws OneLogin_Saml2_Error
31     */
32    public function getRedirectUrl($returnTo = null)
33    {
34        $settings = $this->auth->getSettings();
35        $authnRequest = new OneLogin_Saml2_AuthnRequest($settings);
36        $parameters = array('SAMLRequest' => $authnRequest->getRequest());
37        if (!empty($returnTo)) {
38            $parameters['RelayState'] = $returnTo;
39        } else {
40            $parameters['RelayState'] = OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery();
41        }
42        $url = OneLogin_Saml2_Utils::redirect($this->auth->getSSOurl(), $parameters, true);
43        return $url;
44    }
45
46    /**
47     * @return string
48     */
49    protected function _generateUniqueID()
50    {
51        return OneLogin_Saml2_Utils::generateUniqueID();
52    }
53
54    /**
55     * @return string
56     */
57    protected function _getTimestamp()
58    {
59        $date = new DateTime('now', new DateTimeZone('UTC'));
60        $timestamp = $date->format("Y-m-d\TH:i:s\Z");
61        return $timestamp;
62    }
63}
64