mdi/discovery-sdk

This package is abandoned and no longer maintained. No replacement package was suggested.

MDI Discovery SDK

1.1.3 2016-07-07 14:05 UTC

README

Mobile Connect SDK for PHP.

Usage

Getting started

This assumes that there is an Mobile Connect application created on the developer portal

See the getting started guide for PHP to get started.

Application key

Make sure you have the following from the key registration:

  • Client id
  • Client secret
  • Redirect uri

The key will look something like this:

Application   : Test Application
KeyName       : My first key
ClientId      : d0d7ef3c-0807-4b0b-8354-22537dc21c40
Client secret : 6b527f6b-2df0-4104-a322-1704b690cd75
Scopes        :
                profile
                email
Redirects     :
                http://example.com/auth/callback
                http://localhost/auth/callback

Configuration

Add this snippet to your project and replace the values from the key:

use Mdi\Ericsson\MobileConnectBase;

$mobileConnect = new MobileConnectBase([
    'client_id' => <Your client ID>,
    'client_secret' => <Your client secret>,
    'redirect_uri' => <The redirect back to your site>,
    'discovery_redirect_uri' <The redirect back to you site from the discovery service>,
]);

Authenticating

A prerequisite of being able to authenticate a user is that the application knows about the serving network of the user. Use the getLoginUrl() when you want authenticate the user. This will either create a URL to the Mobile Connect login and signup URL, or if the user has not yet been discovered to the Discovery service URL.

$mobileConnect->getLoginUrl([
    'scope' => 'profile email',
    'acr_values' => 2,
    'prompt' => '',
]);

The Discovery service

When the discovery service has identified the serving network of the user it will redirect the user back to the discovery_redirect_uri specified by you. The redirect URI will contain an hni parameter that should be used to call the discover method in the redirect request. This method will make sure the discovery data is being stored to your application.

$mobileConnect->discover([
    'hni' => isset($_GET['hni']) ? $_GET['hni'] : null,
]);

// Redirect back to your login page

Mobile Connect login & signup

User will be redirected to the OpenID Connect consent pages. After the user has either approved or rejected your application. A redirect will be made back to the redirect URI you defined when creating the key. Run the authorize() function in the redirect request.

$mobileConnect->authorize();

This method will look for the authentication headers in the $_REQUEST object and take care of the callbacks to Mobile Connect in order to exchange the OpenID Connect code header from the redirect and your client secret to an access token and a refresh token.

API

Use this method to see if the application is aware of the serving network of the user.

$mobileConnect->isDiscovered();

Use this method if you want to check it the user is authenticated.

$mobileConnect->isAuthenticated();

Use this method if you want to get information about the serving network of the user.

$mobileConnect->getDiscoveryData();

Use this method if you want to get information about the current user.

$mobileConnect->getUserinfo();

Use this method if you want to get information about the current user's token.

$mobileConnect->getToken();

Use this method if you want to get information about the current user's ID token.

$mobileConnect->getIdToken();

Use this method if you want to renew the current user's token information.

$mobileConnect->refreshToken();

Use this method if you want to revoke the current user's access to the application.

$mobileConnect->revokeToken();

License

Copyright 2015 Ericsson AB

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.