This example demonstrates how to integrate the SDK.
Download the Mobile Connect server side SDK project
Download the Mobile Connect server side project that contains the SDK and demo server side controller.
git clone https://github.com/Mobile-Connect/php_server_side_library.git
Note: Common steps for configuration and running the server side SDK: PHP Server Side SDK setup.
Using the SDK
The Mobile Connect SDK for PHPautomates much of the basic housekeeping and configuration tasks of your application’s integration with Mobile Connect. Many of these functions activate in the Discovery phase, independently of the Identity Gateway endpoint your application will ultimately call, and so are described here for your reference.
Discovery
Discovery is the process of determining an end-user's Mobile Connect Identity Provider, i.e. the Operator ID Gateway. The discovery response will provide with a number of endpoints and the operator specific credentials which will need to use with this ID Gateway.
The SDK has a method that accepts user's data as parameters and needs MobileConnectConfig object initialized as part of the MobileConnectWebInterface object - that's enough to make a successful call to the Mobile Connect Discovery endpoint, and the methods AttemptDiscovery
and HandleUrlRedirect
do just that, building and making the call, and then handling the response. The SDK also takes care of caching the response for re-use in a subsequent call – subject to the configured timeout.
The AttemptDiscovery
method build and make discovery call:
public function AttemptDiscovery($request, $msisdn, $mcc, $mnc, $sourceIp, $includeReqIp, $shouldProxyCookies,
MobileConnectRequestOptions $options) {
if (empty($sourceIp)) {
$sourceIp = $includeReqIp? $request->header("X-Forwarded-For") : null;
}
$options->setClientSideVersion($request->header(Header::CLIENT_SIDE_VERSION));
$options->setServerSideVersion(DefaultOptions::SERVER_SIDE_VERSION);
$options->setClientIp($sourceIp);
$cookies = $shouldProxyCookies ? $request->cookie() : null;
$response = MobileConnectInterfaceHelper::AttemptDiscovery($this->_discovery, $msisdn, $mcc, $mnc, $this->_config, $options, $cookies);
return $this->cacheIfRequired($response);
}
The HandleUrlRedirect
method handle discovery response:
public static function HandleUrlRedirect(DiscoveryService $discovery, $jwks, $redirectedUrl, $expectedState, $expectedNonce, MobileConnectConfig $config,
AuthenticationService $authentication = null, DiscoveryResponse $discoveryResponse = null,
MobileConnectRequestOptions $options = null) {
$query = parse_url($redirectedUrl, PHP_URL_QUERY);
parse_str($query, $queryValue);
if (isset($queryValue['code'])) {
return static::RequestToken($authentication, $jwks, $discoveryResponse, $redirectedUrl, $expectedState, $expectedNonce, $config, $options);
} else if(isset($queryValue['mcc_mnc'])) {
return static::AttemptDiscoveryAfterOperatorSelection($discovery, $redirectedUrl, $config);
}
$errorCode = "invalid_request";
if (isset($queryValue['error'])) {
$errorCode = $queryValue['error'];
}
$errorDesc = "Unable to parse next step using " . $redirectedUrl;
if (isset($queryValue['error_description'])) {
$errorDesc = $queryValue['error_description'];
}
else {
if (isset($queryValue['description'])) {
$errorDesc = $queryValue['description'];
}
}
return MobileConnectStatus::Error($errorCode, $errorDesc, null);
}
This SDK allows calls to Mobile Connect without first doing a Discovery call. It is a similar process to usual Mobile Connect Authentication but instead of calls to the Discovery Service a new function callDiscoveryEndpoint
is used to create the DiscoveryResponse
object.
To load the DiscoveryResponse
object:
public function callDiscoveryEndpoint($clientId, $clientSecret, $discoveryUrl,
DiscoveryOptions $options, $cacheDiscoveryResponse, array $cookies = null) {
ValidationUtils::validateParameter($clientId, "clientId");
ValidationUtils::validateParameter($clientSecret, "clientSecret");
ValidationUtils::validateParameter($discoveryUrl, "discoveryUrl");
ValidationUtils::validateParameter($options->getClientSideVersion(), "clientSideVersion");
ValidationUtils::validateParameter($options->getServerSideVersion(), "serverSideVersion");
if ($cacheDiscoveryResponse) {
$cachedValue = $this->getCachedValue($options);
if (!empty($cachedValue)) {
return $cachedValue;
}
}
try {
$queryParams = $this->getDiscoveryQueryParams($options);
$authentication = RestAuthentication::Basic($clientId, $clientSecret);
$response = new RestResponse();
if (empty($options->getMSISDN())) {
$response = $this->_client->get($discoveryUrl, $authentication, $options->getClientIp(),
$options->getClientSideVersion(), $options->getServerSideVersion(), $queryParams, $options->getXRedirect(), $cookies);
} else {
$response = $this->_client->post($discoveryUrl, $authentication, $queryParams,$options->getClientSideVersion(), $options->getServerSideVersion(), $options->getClientIp(),
$options->getXRedirect(), $cookies);
}
$discoveryResponse = new DiscoveryResponse($response);
$providerMetadata = null;
if ($discoveryResponse->getOperatorUrls() !== null) {
$providerMetadata = $this->retrieveProviderMetadata($discoveryResponse->getOperatorUrls()->getProviderMetadataUrl());
}
if (!empty($providerMetadata)) {
$discoveryResponse->setProviderMetadata($providerMetadata);
}
if ($cacheDiscoveryResponse) {
$this->addCachedValue($options, $discoveryResponse);
}
return $discoveryResponse;
} catch (Zend\Http\Exception\RuntimeException $ex) {
throw new MobileConnectEndpointHttpException($ex->getMessage(), $ex);
} catch (Zend\Http\Client\Exception\RuntimeException $ex) {
throw new MobileConnectEndpointHttpException($ex->getMessage(), $ex);
} catch (Exception $ex) {
throw new MobileConnectEndpointHttpException($ex->getMessage(), $ex);
}
}
Provider Metadata
A successful call to the Mobile Connect Discovery endpoint returns the end user’s Mobile Network Operator (MNO) and describes the Mobile Connect services that MNO supports, via a URI to the MNO’s Provider Metadata. The metadata describes the Identity Gateway endpoints (Mobile Connect services) your application or service can use and how those endpoints are configured – for example, the response types an endpoint can return, the subject identifier types supported, or the Identity Services encryption algorithms in use.
Although Provider Metadata is the primary source of information detailing the Identity Gateway configuration, it does not change often, so a cached version can be used without risk of expired data causing errors. The Mobile Connect SDK handles both the querying of the Provider Metadata and the caching.
- If the Provider Metadata URI returns no data, the cached metadata is used.
- Where the cached data is out of date (defaulting to 15-minute intervals) a subsequent query of the URI is attempted, and in the event of a second failed response, expired cached data is used.
- Should neither the cached data nor the Provider Metadata URI return data (such as an error upon first user login) default values are used.
Regardless of the source, the SDK parses the Provider Metadata into a discrete list of properties. See the OpenID Provider Metadata definition for a list of the metadata available, although you should note that Mobile Connect's implementation may not be exhaustive.
The ProviderMetadata object is available on DiscoveryResponse.ProviderMetadata
.
Supported Services
Before your application or service can call an Identity Gateway endpoint (scope), you need to know if the MNO supports the scope you are calling. The Mobile Connect SDK provides the method IsMobileConnectServiceSupported($scope)
in the discoveryReponse
, which can be accessed as follows:
$supported = $discoveryResponse->IsMobileConnectServiceSupported(“mc_authz mc_signup”)
The method accepts a comma- or space-separated list of scopes, which it then checks against the list of supported scopes in the Provider Metadata.
- If all of the scopes passed as arguments are present in the Provider Metadata, the function returns true.
- If any of the passed scopes are not present in the metadata, the function returns false.
- If the Provider Metadata is not available, or the scopes attribute is missing, null, or an empty string, the function returns an exception: “Provider Metadata scopes unavailable”
Mobile Connect Version Compatibility
The SDK implements version autodetection, this is a mechanism which helps to detect version by configuration parsing, provided values and additional analysis.
Identify gateway supported versions:
- If a Provider Metadata document is available then get a list of supported versions based on the
mc_version
value. - If the Provider Metadata document is not available the supported version will be
mc_v1.1
.
Identify request version:
- If the version value is not empty and the SDK supports this version (see note), then use this.
- If the version value is empty or the SDK doesn’t support the selected version then the scope and list of supported versions (based the ID Gateway) will be analysed to detect the version of MC API, which can be used. Verification order:
- If the list of supported versions contains
mc_di_v3.0
and the scope is valid for this version, then this version will be used. - Otherwise, if the list of supported versions contains
mc_di_r2_v2.3
and the scope is valid for this version, then this version will be used. - Otherwise, if the list of supported versions contains
mc_v2.0
and the scope is valid for this version, then this version will be used. - Otherwise, if list of supported versions contains
mc_v1.1
and the scope is valid only for this version, then this version will be used. - Otherwise, if the list of supported versions contains only
mc_v1.2
and the scope is valid for this version, then this version will be used (but a warning will indicate that version is deprecated). - If current scope doesn’t match with versions included in list of supported versions, the SDK will throw invalid scope exception.
- If the list of supported versions contains
NOTE: mc_v1.1
, mc_v1.2
, mc_v2.0
, mc_di_r2_v2.3
, mc_di_v3.0
are supported by the SDK, but mc_v1.2
, mc_v2.0
, mc_di_r2_v2.3
versions are deprecated.
Versions and supported scopes:
Version | Supported Scopes | Deprecated Scopes |
---|---|---|
mc_v1.1 | "openid", "openid mc_india_tc", "openid mc_mnv_validate", "openid mc_mnv_validate_plus", "openid mc_attr_vm_share", "openid mc_attr_vm_share_hash" | |
[deprecated] mc_v2.0 | "openid mc_authn", "opeind mc_identity_signup", "openid mc_india_tc", "openid mc_mnv_validate", "openid mc_mnv_validate_plus", "openid mc_attr_vm_share", "openid mc_attr_vm_share_hash" | "openid mc_authz", "openid mc_identity_phonenumber", "openid mc_identity_nationalid" |
[deprecated] mc_di_r2_v2.3 | "openid mc_authn", "opeind mc_identity_signup", "openid mc_kyc_plain", "openid mc_kyc_hashed", "openid mc_india_tc", "openid mc_mnv_validate", "openid mc_mnv_validate_plus", "openid mc_attr_vm_share", "openid mc_attr_vm_share_hash" | "openid mc_authz", "openid mc_identity_phonenumber", "openid mc_identity_nationalid" |
mc_di_v3.0 | "openid mc_authn", "opeind mc_signup", "openid mc_kyc_plain", "openid mc_kyc_hashed", "openid mc_india_tc", "openid mc_mnv_validate", "openid mc_mnv_validate_plus", "openid mc_attr_vm_share", "openid mc_attr_vm_share_hash" | "openid mc_authz", "openid mc_phonenumber", "openid mc_nationalid" |
Note: the SDKs have not been developed for Server Initiated mode.
This algorithm is implemented in the VersionDetection
class.
The getCurrentVersion
method takes three parameters:
version
(from configuration)scope
(from configuration)ProviderMetadata
(from DiscoveryResponse).
The method parses and verifies parameters and then returns the correct MC API version depending upon the conditions.
public static function getCurrentVersion($version, $scope, $providerMetadata) {
$supportedVersions = VersionDetection::getSupportedVersions($providerMetadata);
if (!empty($version) && VersionDetection::isVersionSupported($version)) {
return $version;
} else {
$currentScopes = HttpUtils::convertToListBySpace($scope);
if (in_array(Version::MC_DI_V3_0, $supportedVersions) && VersionDetection::containsScopesV3_0($currentScopes)) {
return Version::MC_DI_V3_0;
}
if (in_array(Version::MC_DI_R2_V2_3, $supportedVersions) && VersionDetection::containsScopesV2_3($currentScopes)) {
return Version::MC_DI_R2_V2_3;
} else if (in_array(Version::MC_V2_0, $supportedVersions) && VersionDetection::containsScopesV2_0($currentScopes)) {
return Version::MC_V2_0;
} else if (in_array(Version::MC_V1_1, $supportedVersions) && VersionDetection::containsScopesV1_1($currentScopes)) {
return Version::MC_V1_1;
} else if(in_array(Version::MC_V1_2, $supportedVersions) && sizeof($supportedVersions) == 1 && VersionDetection::containsScopesV2_0($currentScopes)) {
return Version::MC_V1_2;
} else {
throw new InvalidScopeException($scope, $version);
}
}
}
The VersionDetection::getCurrentVersion
method calls in each method of MobileConnectInterface class to detect correct version.
public static function StartAuthentication(IAuthenticationService $authentication, DiscoveryResponse $discoveryResponse,
$encryptedMSISDN, $state, $nonce, MobileConnectConfig $config, MobileConnectRequestOptions $options)
{
try {
$clientId = $discoveryResponse->getResponseData()['response']['client_id'];
$authorizationUrl = $discoveryResponse->getOperatorUrls()->getAuthorizationUrl();
$authOptions = empty($options) ? new AuthenticationOptions() : $options->getAuthenticationOptions();
$version = VersionDetection::getCurrentVersion($authOptions->getVersion(), $authOptions->getScope(), $discoveryResponse->getProviderMetadata());
$response = $authentication->StartAuthentication($clientId, $authorizationUrl, $config->getRedirectUrl(),
$state, $nonce, $encryptedMSISDN, $version, $authOptions);
} catch (\InvalidArgumentException $e) {
return MobileConnectStatus::Error("invalid_argument", "An argument was found to be invalid during the process. " . $e->getMessage(), $e);
} catch (MCSDK\Exceptions\MobileConnectEndpointHttpException $e) {
return MobileConnectStatus::Error("http_failure", "An HTTP failure occured while calling the discovery endpoint, the endpoint may be inaccessible", $e);
} catch (Exception $e) {
return MobileConnectStatus::Error("unknown_error", "An unknown error occured while calling the Discovery service to obtain operator details", $e);
} catch (InvalidScopeException $e) {
return MobileConnectStatus::Error("invalid_scope", $e->getMessage());
}
return MobileConnectStatus::Authorization($response->getUrl(), $state, $nonce);
}
Using version the auto-detection mechanism in the MobileConnectInterface
class ensures that the verifications and request generation in Authentication and Token Services are correct. Furthermore it allows the automatic processing of version, regardless of using only SDK or Server Side SDK.
Mobile Connect Constants
The server side SDK provides a number of constants for referencing the Mobile Connect services by scope. They are available in the MCLibrary\MobileConnectConstants
class, and can be called using the following syntax:
MCLibrary\MobileConnectConstants::MOBILECONNECTIDENTITYPHONE
The above example calls the scope "openid mc_identity_phonenumber"
. You can pass multiple scopes as a space-separated string; the SDK will remove any duplicates before making the call to the Identity Gateway.
Mobile Connect Product | Constant Identifier | Literal Value |
---|---|---|
Authentication | OPENID | "openid" |
Authentication | AUTHN | "openid mc_authn" |
Identity: Signup | IDENTITY_SIGNUP | "openid mc_identity_signup" |
Identity: Signup DI 3.0 | MC_SIGNUP | "openid mc_signup" | KYC Plain | MOBILE_CONNECT_KYC_PLAIN | "openid mc_kyc_plain" |
KYC Hashed | MOBILE_CONNECT_KYC_HASHED | "openid mc_kyc_hashed" |
Mobile Connect Product | Constant Identifier | Literal Value |
---|---|---|
Authorisation | AUTHZ | "openid mc_authz" |
Identity: Phone Number | IDENTITY_PHONE | "openid mc_identity_phonenumber" |
Identity: Phone Number DI 3.0 | MC_PHONE | "openid mc_phonenumber" |
Identity: National ID | IDENTITY_NATIONALID | "openid mc_identity_nationalid" |
Identity: National ID DI 3.0 | MC_NATIONALID | "openid mc_nationalid" |
Login Hint Support
You have the option to provide the login hint to the Identity Gateway using one of three formats: MSISDN, encrypted MSISDN, and PCR. Your decision on how to provide the login hint is governed by two factors:
- The login hint formats supported by the Identity Gateway.
- Whether you are a “Trusted Service Provider”; an unencrypted MSISDN is only accepted from a trusted provider – attempting to send one if you are not trusted returns an error.
The Mobile Connect server side SDK provides functions to test for login hint support in the Identity Gateway, namely:
LoginHint::IsSupportedForMSISDN()
LoginHint::IsSupportedForEncryptedMSISDN()
LoginHint::IsSupportedForPCR()
Each function checks the login_hint_methods_supported
attribute in the Provider Metadata returned from the Discovery endpoint.
Once you have decided how to provide the login hint, the SDK offers a further three functions to build it for you:
LoginHint::GenerateForMSISDN($MSISDN)
LoginHint::GenerateForEncryptedMSISDN($encryptedMSISDN)
LoginHint::GenerateForPCR ($PCR)
Login Hint Token Support
You have the option to provide the login hint token to the Identity Gateway. The SDK supports sending the Authorize request with login_hint_token (if it's passed in Authentification options) parameter except login_hint. The value should be equals to the subscriber_id_token in the Discovery Respose.
id_token Validation
A successful response from the Identity Gateway includes an id_token – a JSON Web Token, which validates against a JSON Web Keyset (JWKS), available at a URL specified in the Provider Metadata attribute jwks_uri
.
The server side SDK performs a number of automatic validation actions to ensure the integrity of the response source, such as checking whether the token has expired. It also fetches the data from the jwks_uri
location and stores it alongside the associated Discovery response, where it is cached. The following functions are then available to you to support id_token validation:
checkIDTokenSignature(id_token, $keyset)
verifies the signature of the id_token based on theJWKS
data. A successful validation returnstrue
; a failed validation returnsfalse
; a missing JWKS certificate returns an error.JWKeysetService::RetrieveJWKS($url)
allows you to fetch all of the keys from the JWKS data.-
returnMatchingJWKSEntries
allows you to fetch specific keys matching the following parameters:kty
– key type (e.g. RSA)alg
– algorithm (e.g. RS256)use
– sig (signature) or enc (encryption)kid
– key identifier
(Deprecated) Using Mobile Connect Authorisation
The SDK allows you to call the Identity Gateway with the scope
parameter set to “mc_authz”
, which signifies an authorisation request for a single transaction (the id_token and access token returned from the Gateway have a timeout set to zero, so expire after a single use).
To make a successful authorisation call, you must provide the following additional parameters:
client_name
– specifies the name of the application/service requesting authorisation. This value is taken from Options and must match the Application Short Name.context
– specifies the reason for the authorisation request, and should be built from the data describing the transaction requiring authorisation. The context is displayed on the authenticating (mobile) device only.binding_message
– specifies a reference string to display on the device from which the authorisation request was invoked, and on the authenticating (mobile) device, allowing the user to visually verify that the confirmation message originated from their transaction request.
Note: the authorisation prompt displayed to the user combines all three parameters, which cannot exceed 93 bytes in total.
The following example shows how to add the additional options to the authentication call described in Using Mobile Connect Authentication, resulting in a correctly configured call to the authorisation service.
public static function StartAuthentication(IAuthenticationService $authentication, DiscoveryResponse $discoveryResponse,
$encryptedMSISDN, $state, $nonce, MobileConnectConfig $config, MobileConnectRequestOptions $options)
{
try {
$clientId = $discoveryResponse->getResponseData()['response']['client_id'];
$authorizationUrl = $discoveryResponse->getOperatorUrls()->getAuthorizationUrl();
$authOptions = empty($options) ? new AuthenticationOptions() : $options->getAuthenticationOptions();
$version = VersionDetection::getCurrentVersion($authOptions->getVersion(), $authOptions->getScope(), $discoveryResponse->getProviderMetadata());
$response = $authentication->StartAuthentication($clientId, $authorizationUrl, $config->getRedirectUrl(),
$state, $nonce, $encryptedMSISDN, $version, $authOptions);
} catch (\InvalidArgumentException $e) {
return MobileConnectStatus::Error("invalid_argument", "An argument was found to be invalid during the process. " . $e->getMessage(), $e);
} catch (MCSDK\Exceptions\MobileConnectEndpointHttpException $e) {
return MobileConnectStatus::Error("http_failure", "An HTTP failure occured while calling the discovery endpoint, the endpoint may be inaccessible", $e);
} catch (Exception $e) {
return MobileConnectStatus::Error("unknown_error", "An unknown error occured while calling the Discovery service to obtain operator details", $e);
} catch (InvalidScopeException $e) {
return MobileConnectStatus::Error("invalid_scope", $e->getMessage());
}
return MobileConnectStatus::Authorization($response->getUrl(), $state, $nonce);
}
After that client side makes redirects session and gets the code
. Client side sends this code
to the SDK, which uses this code
for RequestToken
method performing.
public static function RequestToken(IAuthenticationService $authentication, IJWKeysetService $jwks, DiscoveryResponse $discoveryResponse,
$redirectedUrl, $expectedState, $expectedNonce, MobileConnectConfig $config, MobileConnectRequestOptions $options = null) {
$response = null;
$query = parse_url($redirectedUrl, PHP_URL_QUERY);
parse_str($query, $queryValue);
if(empty($expectedState)) {
return MobileConnectStatus::Error("required_arg_missing", "ExpectedState argument was not supplied, this is needed to prevent Cross-Site Request Forgery", null);
}
if (empty($expectedNonce)) {
return MobileConnectStatus::Error("required_arg_missing", "expectedNonce argument was not supplied, this is needed to prevent Replay Attacks", null);
}
$actualState = $queryValue['state'];
if ($expectedState != $actualState) {
return MobileConnectStatus::Error("invalid_state", "State values do not match, this could suggest an attempted Cross-Site Request Forgery", null);
}
try {
$code = $queryValue['code'];
$clientId = $config->getClientId();
if (!empty($discoveryResponse) && !empty($discoveryResponse->getResponseData()) && isset($discoveryResponse->getResponseData()['response']['client_id'])) {
$clientId = $discoveryResponse->getResponseData()['response']['client_id'];
}
$clientSecret = $config->getClientSecret();
if (!empty($discoveryResponse) && !empty($discoveryResponse->getResponseData()) && isset($discoveryResponse->getResponseData()['response']['client_secret'])) {
$clientSecret = $discoveryResponse->getResponseData()['response']['client_secret'];
}
$requestTokenUrl = null;
if (!empty($discoveryResponse) && !empty($discoveryResponse->getOperatorUrls()) && !empty($discoveryResponse->getOperatorUrls()->getRequestTokenUrl())) {
$requestTokenUrl = $discoveryResponse->getOperatorUrls()->getRequestTokenUrl();
}
$issuer = $discoveryResponse->getProviderMetadata()["issuer"];
$response = $authentication->RequestToken($clientId, $clientSecret, $requestTokenUrl, $config->getRedirectUrl(), $code);
$jwKeySet = $jwks->RetrieveJWKS($discoveryResponse->getOperatorUrls()->getJWKSUrl());
$authOptions = empty($options) ? new AuthenticationOptions() : $options->getAuthenticationOptions();
$version = VersionDetection::getCurrentVersion($authOptions->getVersion(), $authOptions->getScope(), $discoveryResponse->getProviderMetadata());
return static::HandleTokenResponse($authentication, $response, $clientId, $issuer, $expectedNonce, $jwKeySet,
$version, $options);
} catch(Exception $ex) {
return MobileConnectStatus::Error("unknown_error", "A failure occured while requesting a token", $ex);
}
return MobileConnectStatus::Complete($response);
}
If scope value maches "profile", "email", "adderss", "phone" or "mc_identity_phonenumber", "mc_identity_signup", "mc_identity_signupplus", "mc_identity_nationalid", "mc_phonenumber", "mc_signup", "mc_nationalid","mc_kyc_plain", "mc_kyc_hashed",
requestUserInfo
or requestIdentity
respectively will be performed and the JSON response will be returned as identity response in the the Token JSON response.Using Mobile Connect Identity and Attributes
Note: Identity Phone Number and Identity National Id are deprecated but still supported in the SDK
A successful call to the Authorisation endpoint returns an id_token identifying the user, and an access token that grants your application permission to request their personal information (referred to as Claims). This information contains a range of data; the exact data you can request is specified in the access token, and is limited to those Claims the end user has permitted as part of the original authorisation request.
Note: the access token is for single use only, and expires immediately upon use.
You request access to the Identity endpoint by specifying the appropriate scope. The SDK provides constants that you can pass when requesting specific Identity products:
- (Deprecated) Identity: Phone Number –
MC_PHONE
- Identity: Sign-up –
MC_SIGNUP
- (Deprecated) Identity: National Identity –
MC_NATIONALID
Upon successful authorisation, the SDK provides an IdentityResponse with the user information JSON available as a property. The following example can be used to convert the JSON data to a class - IdentityData
- which is provided with all recognised claims.
public function RequestIdentity($premiumInfoUrl, $accessToken)
{
ValidationUtils::validateParameter($premiumInfoUrl, "premiumInfoUrl");
return $this->RequestUserInfo($premiumInfoUrl, $accessToken);
}
public function RequestUserInfo($userInfoUrl, $accessToken)
{
ValidationUtils::validateParameter($userInfoUrl, "userInfoUrl");
ValidationUtils::validateParameter($accessToken, "accessToken");
try
{
$response = new RestResponse();
$auth = RestAuthentication::Bearer($accessToken);
$response = $this->_client->get($userInfoUrl, $auth, null, null, null);
return new IdentityResponse($response);
}
catch (Exception $ex)
{
throw new MobileConnectEndpointHttpException($ex->getMessage(), $ex);
}
}
The following example shows how to add the additional Authorisation and Identity options to the Authentication call described in Using Mobile Connect Authentication, resulting in a correctly configured call to the Identity: Phone Number service.
Note: calls to Identity: Sign-up and Identity: National ID are structured in exactly the same way, but using the scopes “mc_signup” (“mc_identity_signup”) and “mc_nationalid” (“mc_identity_nationalid”) as applicable.
KYC Support for DI 2.3 and DI 3.0
The SDK allows to use KYC product with the scope
parameter set to "mc_kyc_plain"
or "mc_kyc_hashed"
. Current version must be set to “mc_di_r2_v2.3” or "mc_di_v3.0"
.
To make a successful authorisation call, you must provide the KYC Claims.
You can use split claims:
or concatenated claims:
The server side SDK performs a number of automatic claims validation:
private function validateKycParams($options) {
$kycClaims = $options->getClaims();
if((strpos($options->getScope(), Scope::KYC_PLAIN) !== false) && ($options->getVersion() == DefaultOptions::VERSION_DI_2_3)) {
if (!empty($kycClaims->getName())) {
ValidationUtils::validateParameter($kycClaims->getAddress(), Parameters::ADDRESS);
}
else if (!empty($kycClaims->getGivenName())) {
$params = implode(Constants::SPACE, array(
empty($kycClaims->getFamilyName())? Parameters::FAMILY_NAME: null,
empty($kycClaims->getHousenoOrHousename())? Parameters::HOUSENO_OR_HOUSENAME: null,
empty($kycClaims->getPostalCode())? Parameters::POSTAL_CODE: null,
empty($kycClaims->getCountry())? Parameters::COUNTRY: null,
empty($kycClaims->getTown())? Parameters::TOWN: null));
ValidationUtils::validateParameter(null, $params);
}
else {
ValidationUtils::validateParameter(null, Parameters::NAME.Constants::OR.Parameters::GIVEN_NAME );
}
}
if((strpos($options->getScope(), Scope::KYC_HASHED) !== false) && ($options->getVersion() == DefaultOptions::VERSION_DI_2_3)) {
if (!empty($kycClaims->getNameHashed())) {
ValidationUtils::validateParameter($kycClaims->getAddressHashed(), Parameters::ADDRESS_HASHED);
}
else if (!empty($kycClaims->getGivenNameHashed())) {
$params = implode(Constants::SPACE, array(
empty($kycClaims->getFamilyNameHashed())? Parameters::FAMILY_NAME_HASHED: null,
empty($kycClaims->getHousenoOrHousenameHashed())? Parameters::HOUSENO_OR_HOUSENAME_HASHED: null,
empty($kycClaims->getPostalCodeHashed())? Parameters::POSTAL_CODE_HASHED: null,
empty($kycClaims->getCountryHashed())? Parameters::COUNTRY_HASHED: null,
empty($kycClaims->getTownHashed())? Parameters::TOWN_HASHED: null));
ValidationUtils::validateParameter(null, $params);
}
else {
ValidationUtils::validateParameter(null, Parameters::NAME_HASHED.Constants::OR.Parameters::GIVEN_NAME_HASHED);
}
}
}
After successful validation claims are added to authorisation request as query parameter "claims". The value of claims parameter is presented as:
{"premiuminfo": {"claim_name": {"value": "claim_value"}, ...}}