-
Notifications
You must be signed in to change notification settings - Fork 41
/
OnlineS2SSecretAuthenticationSettings.php
123 lines (103 loc) · 2.9 KB
/
OnlineS2SSecretAuthenticationSettings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace AlexaCRM\CRMToolkit;
/**
* SDK configuration class, used to create instance of AlexaCRM\CRMToolkit\Client class
*/
class OnlineS2SSecretAuthenticationSettings extends AbstractSettings {
/**
* Const definition for settings type
*/
const SETTINGS_TYPE = 'sharedSecretAuth';
/**
* Web API version.
*/
public $apiVersion = '9.0';
/**
* Identifier of the Azure Active Directory application registration
*
* @var string
*/
public $applicationId;
/**
* A key associated with the Azure Active Directory $applicationId
*
* @var string
*/
public $clientSecret;
/**
* Azure AD tenant ID.
*
* Optional, allows skipping tenant detection.
*/
public $tenantID = null;
/**
* Cache object for the settings
* @var mixed|null
*/
public $cache = null;
/**
* OnlineS2SSecretAuthenticationSettings constructor.
*
* @param $settings
*/
public function __construct( $settings ) {
$this->applicationId = $settings['applicationId'];
$this->clientSecret = $settings['clientSecret'];
if ( ! empty( $settings['cache'] ) ) {
$this->cache = $settings['cache'];
}
parent::__construct( $settings );
}
/**
* Check if all required settings are filled
*
* @return bool
*/
public function isFullSettings() {
return ( $this->discoveryUrl && $this->applicationId && $this->clientSecret && $this->organizationUrl
&& $this->loginUrl && ( ( $this->authMode === 'OnlineFederation' ) ? $this->crmRegion : true ) );
}
/**
* Returns Web API endpoint URI.
*/
public function getEndpointURI() {
return trim( $this->serverUrl, '/' ) . '/api/data/v' . $this->apiVersion . '/';
}
/**
* Validates settings input.
*
* @param array $settings
*/
protected function validateInput( $settings ) {
if ( ! isset( $settings["serverUrl"] ) ||
! isset( $settings["applicationId"] ) ||
! isset( $settings["clientSecret"] )
) {
throw new \InvalidArgumentException( 'applicationId, clientSecret or serverUrl is incorrect' );
}
if ( ! filter_var( $settings["serverUrl"], FILTER_VALIDATE_URL )
|| strpos( $settings["serverUrl"], "." ) === false
) {
throw new \InvalidArgumentException( 'Invalid serverUrl has been provided' );
}
if ( $settings['authMode'] !== 'OnlineFederation' ) {
throw new \InvalidArgumentException( 'Provided authentication mode <' . $this->authMode . '> is not supported' );
}
}
/**
* Validates URL parsing results.
*
* @param array $urlParts
*/
protected function validateUrl( $urlParts ) {
if ( ! is_array( $urlParts ) ) {
throw new \InvalidArgumentException( 'Invalid serverUrl has been provided' );
}
if ( ! isset( $urlParts["scheme"] ) ) {
throw new \InvalidArgumentException( 'serverUrl has been provided without a valid scheme (http:// or https://)' );
}
if ( ! isset( $urlParts["host"] ) ) {
throw new \InvalidArgumentException( 'Invalid serverUrl has been provided' );
}
}
}