# \OneLogin_Saml2_Auth

Main class of PHP Toolkit

## Summary

Methods
Properties
Constants
__construct()
getSettings()
setStrict()
setSchemasPath()
processResponse()
processSLO()
redirectTo()
isAuthenticated()
getAttributes()
getAttributesWithFriendlyName()
getNameId()
getNameIdFormat()
getNameIdNameQualifier()
getNameIdSPNameQualifier()
getSessionIndex()
getSessionExpiration()
getErrors()
getLastErrorReason()
getAttribute()
getAttributeWithFriendlyName()
login()
logout()
getSSOurl()
getSLOurl()
getSLOResponseUrl()
getLastRequestID()
buildRequestSignature()
buildResponseSignature()
getLastMessageId()
getLastAssertionId()
getLastAssertionNotOnOrAfter()
getLastRequestXML()
getLastResponseXML()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
buildMessageSignature()
$_settings
$_attributes
$_attributesWithFriendlyName
$_nameid
$_nameidFormat
$_nameidNameQualifier
$_nameidSPNameQualifier
$_authenticated
$_sessionIndex
$_sessionExpiration
$_lastMessageId
$_lastAssertionId
$_lastAssertionNotOnOrAfter
$_errors
$_errorReason
$_lastRequestID
$_lastRequest
$_lastResponse
N/A

File
  Auth.php
Package
  Default
Class hierarchy
  \OneLogin_Saml2_Auth

## Tags

None found

## Properties

### $_settings

    $_settings : \OneLogin_Saml2_Settings

Settings data.

#### Type

\OneLogin_Saml2_Settings

#

## Tags

None found

### $_attributes

    $_attributes : array

User attributes data.

#### Type

array

#

## Tags

None found

### $_attributesWithFriendlyName

    $_attributesWithFriendlyName : array

User attributes data with FriendlyName index.

#### Type

array

#

## Tags

None found

### $_nameid

    $_nameid : string

NameID

#### Type

string

#

## Tags

None found

### $_nameidFormat

    $_nameidFormat : string

NameID Format

#### Type

string

#

## Tags

None found

### $_nameidNameQualifier

    $_nameidNameQualifier : string

NameID NameQualifier

#### Type

string

#

## Tags

None found

### $_nameidSPNameQualifier

    $_nameidSPNameQualifier : string

NameID SP NameQualifier

#### Type

string

#

## Tags

None found

### $_authenticated

    $_authenticated : boolean

If user is authenticated.

#### Type

boolean

#

## Tags

None found

### $_sessionIndex

    $_sessionIndex : string

SessionIndex. When the user is logged, this stored it from the AuthnStatement of the SAML Response

#### Type

string

#

## Tags

None found

### $_sessionExpiration

    $_sessionExpiration : integer|null

SessionNotOnOrAfter. When the user is logged, this stored it from the AuthnStatement of the SAML Response

#### Type

integer|null

#

## Tags

None found

### $_lastMessageId

    $_lastMessageId : string

The ID of the last message processed

#### Type

string

#

## Tags

None found

### $_lastAssertionId

    $_lastAssertionId : string

The ID of the last assertion processed

#### Type

string

#

## Tags

None found

### $_lastAssertionNotOnOrAfter

    $_lastAssertionNotOnOrAfter : integer

The NotOnOrAfter value of the valid SubjectConfirmationData node (if any) of the last assertion processed

#### Type

integer

#

## Tags

None found

### $_errors

    $_errors : array

If any error.

#### Type

array

#

## Tags

None found

### $_errorReason

    $_errorReason : string|null

Reason of the last error.

#### Type

string|null

#

## Tags

None found

### $_lastRequestID

    $_lastRequestID : string

Last AuthNRequest ID or LogoutRequest ID generated by this Service Provider

#### Type

string

#

## Tags

None found

### $_lastRequest

    $_lastRequest : string

The most recently-constructed/processed XML SAML request (AuthNRequest, LogoutRequest)

#### Type

string

#

## Tags

None found

### $_lastResponse

    $_lastResponse : string|\DomDocument|null

The most recently-constructed/processed XML SAML response (SAMLResponse, LogoutResponse). If the SAMLResponse was encrypted, by default tries to return the decrypted XML

#### Type

string|\DomDocument|null

#

## Tags

None found

## Methods

### __construct()

    __construct(array|object|null  $oldSettings = null, boolean  $spValidationOnly = false)

Initializes the SP SAML instance.

#### Parameters

array|object|null | $oldSettings | Setting data (You can provide a OneLogin_Saml_Settings, the settings object of the Saml folder implementation)
boolean | $spValidationOnly | if you only as an SP , you should set it to false if not you should set it to true

#### Throws

\OneLogin_Saml2_Error

#

## Tags

None found

### getSettings()

    getSettings() : \OneLogin_Saml2_Settings

Returns the settings info

#### Returns

\OneLogin_Saml2_Settings —

The settings data.

#

## Tags

None found

### setStrict()

    setStrict(boolean  $value)

Set the strict mode active/disable

#### Parameters

boolean | $value | Strict parameter

#### Throws

\OneLogin_Saml2_Error

#

## Tags

None found

### setSchemasPath()

    setSchemasPath(string  $path) : $this

Set schemas path

#### Parameters

string | $path |

#### Returns

$this

#

## Tags

None found

### processResponse()

    processResponse(string|null  $requestId = null)

Process the SAML Response sent by the IdP.

#### Parameters

string|null | $requestId | The ID of the AuthNRequest sent by this SP to the IdP

#### Throws

\OneLogin_Saml2_Error
\OneLogin_Saml2_ValidationError

#

## Tags

None found

### processSLO()

    processSLO(boolean  $keepLocalSession = false, string|null  $requestId = null, boolean  $retrieveParametersFromServer = false, callable  $cbDeleteSession = null, boolean  $stay = false) : string|null

Process the SAML Logout Response / Logout Request sent by the IdP.

#### Parameters

boolean | $keepLocalSession | When false will destroy the local session, otherwise will keep it
string|null | $requestId | The ID of the LogoutRequest sent by this SP to the IdP
boolean | $retrieveParametersFromServer | True if we want to use parameters from $_SERVER to validate the signature
callable | $cbDeleteSession | Callback to be executed to delete session
boolean | $stay | True if we want to stay (returns the url string) False to redirect

#### Throws

\OneLogin_Saml2_Error

#### Returns

string|null

#

## Tags

None found

### redirectTo()

    redirectTo(string  $url = '', array  $parameters = array(), boolean  $stay = false) : string|null

Redirects the user to the url past by parameter or to the url that we defined in our SSO Request.

#### Parameters

string | $url | The target URL to redirect the user.
array | $parameters | Extra parameters to be passed as part of the url
boolean | $stay | True if we want to stay (returns the url string) False to redirect

#### Throws

\OneLogin_Saml2_Error

#### Returns

string|null

#

## Tags

None found

### isAuthenticated()

    isAuthenticated() : boolean

Checks if the user is authenticated or not.

#### Returns

boolean —

True if the user is authenticated

#

## Tags

None found

### getAttributes()

    getAttributes() : array

Returns the set of SAML attributes.

#### Returns

array —

Attributes of the user.

#

## Tags

None found

### getAttributesWithFriendlyName()

    getAttributesWithFriendlyName() : array

Returns the set of SAML attributes indexed by FriendlyName

#### Returns

array —

Attributes of the user.

#

## Tags

None found

### getNameId()

    getNameId() : string

Returns the nameID

#### Returns

string —

The nameID of the assertion

#

## Tags

None found

### getNameIdFormat()

    getNameIdFormat() : string

Returns the nameID Format

#### Returns

string —

The nameID Format of the assertion

#

## Tags

None found

### getNameIdNameQualifier()

    getNameIdNameQualifier() : string

Returns the nameID NameQualifier

#### Returns

string —

The nameID NameQualifier of the assertion

#

## Tags

None found

### getNameIdSPNameQualifier()

    getNameIdSPNameQualifier() : string

Returns the nameID SP NameQualifier

#### Returns

string —

The nameID SP NameQualifier of the assertion

#

## Tags

None found

### getSessionIndex()

    getSessionIndex() : string|null

Returns the SessionIndex

#### Returns

string|null —

The SessionIndex of the assertion

#

## Tags

None found

### getSessionExpiration()

    getSessionExpiration() : integer|null

Returns the SessionNotOnOrAfter

#### Returns

integer|null —

The SessionNotOnOrAfter of the assertion

#

## Tags

None found

### getErrors()

    getErrors() : array

Returns if there were any error

#### Returns

array —

Errors

#

## Tags

None found

### getLastErrorReason()

    getLastErrorReason() : string|null

Returns the reason for the last error

#### Returns

string|null —

Error reason

#

## Tags

None found

### getAttribute()

    getAttribute(string  $name) : array|null

Returns the requested SAML attribute

#### Parameters

string | $name | The requested attribute of the user.

#### Returns

array|null —

Requested SAML attribute ($name).

#

## Tags

None found

### getAttributeWithFriendlyName()

    getAttributeWithFriendlyName(string  $friendlyName) : array|null

Returns the requested SAML attribute indexed by FriendlyName

#### Parameters

string | $friendlyName | The requested attribute of the user.

#### Returns

array|null —

Requested SAML attribute ($friendlyName).

#

## Tags

None found

### login()

    login(string|null  $returnTo = null, array  $parameters = array(), boolean  $forceAuthn = false, boolean  $isPassive = false, boolean  $stay = false, boolean  $setNameIdPolicy = true, string  $nameIdValueReq = null) : string|null

Initiates the SSO process.

#### Parameters

string|null | $returnTo | The target URL the user should be returned to after login.
array | $parameters | Extra parameters to be added to the GET
boolean | $forceAuthn | When true the AuthNRequest will set the ForceAuthn='true'
boolean | $isPassive | When true the AuthNRequest will set the Ispassive='true'
boolean | $stay | True if we want to stay (returns the url string) False to redirect
boolean | $setNameIdPolicy | When true the AuthNRueqest will set a nameIdPolicy element
string | $nameIdValueReq | Indicates to the IdP the subject that should be authenticated

#### Throws

\OneLogin_Saml2_Error

#### Returns

string|null —

If $stay is True, it return a string with the SLO URL + LogoutRequest + parameters

#

## Tags

None found

### logout()

    logout(string|null  $returnTo = null, array  $parameters = array(), string|null  $nameId = null, string|null  $sessionIndex = null, boolean  $stay = false, string|null  $nameIdFormat = null, string|null  $nameIdNameQualifier = null,   $nameIdSPNameQualifier = null) : string|null

Initiates the SLO process.

#### Parameters

string|null | $returnTo | The target URL the user should be returned to after logout.
array | $parameters | Extra parameters to be added to the GET
string|null | $nameId | The NameID that will be set in the LogoutRequest.
string|null | $sessionIndex | The SessionIndex (taken from the SAML Response in the SSO process).
boolean | $stay | True if we want to stay (returns the url string) False to redirect
string|null | $nameIdFormat | The NameID Format will be set in the LogoutRequest.
string|null | $nameIdNameQualifier | The NameID NameQualifier will be set in the LogoutRequest.
| $nameIdSPNameQualifier |

#### Throws

\OneLogin_Saml2_Error

#### Returns

string|null —

If $stay is True, it return a string with the SLO URL + LogoutRequest + parameters

#

## Tags

None found

### getSSOurl()

    getSSOurl() : string

Gets the IdP SSO url.

#### Returns

string —

The url of the IdP Single Sign On Service

#

## Tags

None found

### getSLOurl()

    getSLOurl() : string|null

Gets the IdP SLO url.

#### Returns

string|null —

The url of the IdP Single Logout Service

#

## Tags

None found

### getSLOResponseUrl()

    getSLOResponseUrl() : string|null

Gets the IdP SLO response url.

#### Returns

string|null —

The response url of the IdP Single Logout Service

#

## Tags

None found

### getLastRequestID()

    getLastRequestID() : string

Gets the ID of the last AuthNRequest or LogoutRequest generated by the Service Provider.

#### Returns

string —

The ID of the Request SAML message.

#

## Tags

None found

### buildRequestSignature()

    buildRequestSignature(string  $samlRequest, string  $relayState, string  $signAlgorithm = \XMLSecurityKey::RSA_SHA1) : string

Generates the Signature for a SAML Request

#### Parameters

string | $samlRequest | The SAML Request
string | $relayState | The RelayState
string | $signAlgorithm | Signature algorithm method

#### Throws

\OneLogin_Saml2_Error

#### Returns

string —

A base64 encoded signature

#

## Tags

None found

### buildResponseSignature()

    buildResponseSignature(string  $samlResponse, string  $relayState, string  $signAlgorithm = \XMLSecurityKey::RSA_SHA1) : string

Generates the Signature for a SAML Response

#### Parameters

string | $samlResponse | The SAML Response
string | $relayState | The RelayState
string | $signAlgorithm | Signature algorithm method

#### Throws

\OneLogin_Saml2_Error

#### Returns

string —

A base64 encoded signature

#

## Tags

None found

### getLastMessageId()

    getLastMessageId() : string

#### Returns

string —

The ID of the last message processed

#

## Tags

None found

### getLastAssertionId()

    getLastAssertionId() : string

#### Returns

string —

The ID of the last assertion processed

#

## Tags

None found

### getLastAssertionNotOnOrAfter()

    getLastAssertionNotOnOrAfter() : integer

#### Returns

integer —

The NotOnOrAfter value of the valid SubjectConfirmationData node (if any) of the last assertion processed

#

## Tags

None found

### getLastRequestXML()

    getLastRequestXML() : string

Returns the most recently-constructed/processed XML SAML request (AuthNRequest, LogoutRequest)

#### Returns

string —

The Request XML

#

## Tags

None found

### getLastResponseXML()

    getLastResponseXML() : string|null

Returns the most recently-constructed/processed XML SAML response (SAMLResponse, LogoutResponse).

If the SAMLResponse was encrypted, by default tries to return the decrypted XML.

#### Returns

string|null —

The Response XML

#

## Tags

None found

### buildMessageSignature()

    buildMessageSignature(string  $samlMessage, string  $relayState, string  $signAlgorithm = \XMLSecurityKey::RSA_SHA256, string  $type = "SAMLRequest") : string

Generates the Signature for a SAML Response

#### Parameters

string | $samlMessage | The SAML Response
string | $relayState | The RelayState
string | $signAlgorithm | Signature algorithm method
string | $type | "SAMLRequest" or "SAMLResponse"

#### Throws

\OneLogin_Saml2_Error

#### Returns

string —

A base64 encoded signature

#

## Tags

None found

### Auth.php