mvtester/tester-testsdks-vsdks-sdk

1.0.1 2023-07-10 12:37 UTC

This package is auto-updated.

Last update: 2024-05-10 14:30:20 UTC


README

Introduction

The Verizon Edge Discovery Service API can direct your application clients to connect to the optimal service endpoints for your Multi-access Edge Computing (MEC) applications for every session. The Edge Discovery Service takes into account the current location of a device, its IP anchor location, current network traffic and other factors to determine which 5G Edge platform a device should connect to.

Verizon Terms of Service: https://www.verizon.com/business/5g-edge-portal/legal.html

Install the Package

Run the following command to install the package and automatically add the dependency to your composer.json file:

composer require "mvtester/tester-testsdks-vsdks-sdk:1.0.1"

Or add it to the composer.json file manually as given below:

"require": {
    "mvtester/tester-testsdks-vsdks-sdk": "1.0.1"
}

You can also view the package at: https://packagist.org/packages/mvtester/tester-testsdks-vsdks-sdk#1.0.1

Initialize the API Client

Note: Documentation for the client can be found here.

The following parameters are configurable for the API Client:

Parameter Type Description
vZM2mToken string M2M Session Token
environment Environment The API environment.
Default: Environment.PRODUCTION
timeout int Timeout for API calls in seconds.
Default: 0
enableRetries bool Whether to enable retries and backoff feature.
Default: false
numberOfRetries int The number of retries to make.
Default: 0
retryInterval float The retry time interval between the endpoint calls.
Default: 1
backOffFactor float Exponential backoff factor to increase interval between retries.
Default: 2
maximumRetryWaitTime int The maximum wait time in seconds for overall retrying requests.
Default: 0
retryOnTimeout bool Whether to retry on request timeout.
Default: true
httpStatusCodesToRetry array Http status codes to retry against.
Default: 408, 413, 429, 500, 502, 503, 504, 521, 522, 524
httpMethodsToRetry array Http methods to retry against.
Default: 'GET', 'PUT'
oauthClientId string OAuth 2 Client ID
oauthClientSecret string OAuth 2 Client Secret
oauthToken OauthToken Object for storing information about the OAuth token
oauthScopes string(OauthScopeEnum)[]

The API client can be initialized as follows:

$client = VerizonClientBuilder::init()
    ->oauthClientId('OAuthClientId')
    ->oauthClientSecret('OAuthClientSecret')
    ->vZM2mToken('VZ-M2M-Token')
    ->oauthScopes([
        VerizonLib\Models\OauthScopeEnum::DISCOVERYREAD,
        VerizonLib\Models\OauthScopeEnum::SERVICEPROFILEREAD,
        VerizonLib\Models\OauthScopeEnum::SERVICEPROFILEWRITE,
        VerizonLib\Models\OauthScopeEnum::SERVICEREGISTRYREAD,
        VerizonLib\Models\OauthScopeEnum::SERVICEREGISTRYWRITE,
        VerizonLib\Models\OauthScopeEnum::TS_MEC_FULLACCESS,
        VerizonLib\Models\OauthScopeEnum::TS_MEC_LIMITACCESS,
        VerizonLib\Models\OauthScopeEnum::TS_APPLICATION_RO,
        VerizonLib\Models\OauthScopeEnum::EDGEDISCOVERYREAD,
        VerizonLib\Models\OauthScopeEnum::EDGESERVICEPROFILEREAD,
        VerizonLib\Models\OauthScopeEnum::EDGESERVICEPROFILEWRITE,
        VerizonLib\Models\OauthScopeEnum::EDGESERVICEREGISTRYREAD,
        VerizonLib\Models\OauthScopeEnum::EDGESERVICEREGISTRYWRITE,
        VerizonLib\Models\OauthScopeEnum::READ,
        VerizonLib\Models\OauthScopeEnum::WRITE
    ])
    ->environment('Production')
    ->build();

API calls return an ApiResponse object that includes the following fields:

Field Description
getStatusCode Status code of the HTTP response
getHeaders Headers of the HTTP response as a Hash
getResult The deserialized body of the HTTP response as a String

Authorization

This API uses OAuth 2 Client Credentials Grant.

Client Credentials Grant

Your application must obtain user authorization before it can execute an endpoint call in case this SDK chooses to use OAuth 2.0 Client Credentials Grant. This authorization includes the following steps

The fetchToken() method will exchange the OAuth client credentials for an access token. The access token is an object containing information for authorizing client requests and refreshing the token itself.

You must have initialized the client with scopes for which you need permission to access.

try {
    $token = $client->getClientCredentialsAuth()->fetchToken();
    // re-build the client with oauth token
    $client = $client->toBuilder()->oauthToken($token)->build();
} catch (VerizonLib\Exceptions\ApiException $e) {
    // handle exception
}

The client can now make authorized endpoint calls.

Scopes

Scopes enable your application to only request access to the resources it needs while enabling users to control the amount of access they grant to your application. Available scopes are defined in the OauthScopeEnum enumeration.

Scope Name Description
DISCOVERYREAD Grant read-only access to discovery data
SERVICEPROFILEREAD Grant read-only access to service profile data
SERVICEPROFILEWRITE Grant write access to service profile data
SERVICEREGISTRYREAD Grant read-only access to Service registry data
SERVICEREGISTRYWRITE Grant write access to Service registry data
TS_MEC_FULLACCESS Full access for /serviceprofiles and /serviceendpoints.
TS_MEC_LIMITACCESS Limited access. Will not allow use of /serviceprofiles and /serviceendpoints but will allow discovery.
TS_APPLICATION_RO
EDGEDISCOVERYREAD
EDGESERVICEPROFILEREAD
EDGESERVICEPROFILEWRITE
EDGESERVICEREGISTRYREAD
EDGESERVICEREGISTRYWRITE
READ read access
WRITE read/write access

Storing an access token for reuse

It is recommended that you store the access token for reuse.

// store token
$_SESSION['access_token'] = $client->getClientCredentialsAuth()->getOauthToken();

Creating a client from a stored token

To authorize a client from a stored access token, just set the access token in Configuration along with the other configuration parameters before creating the client:

// load token later...
$token = $_SESSION['access_token'];

// re-build the client with oauth token
$client = $client->toBuilder()->oauthToken($token)->build();

Complete example

<?php
require_once __DIR__.'/vendor/autoload.php';

session_start();

// Client configuration
$client = VerizonClientBuilder::init()
    ->oauthClientId('OAuthClientId')
    ->oauthClientSecret('OAuthClientSecret')
    ->vZM2mToken('VZ-M2M-Token')
    ->oauthScopes([
        VerizonLib\Models\OauthScopeEnum::DISCOVERYREAD,
        VerizonLib\Models\OauthScopeEnum::SERVICEPROFILEREAD,
        VerizonLib\Models\OauthScopeEnum::SERVICEPROFILEWRITE,
        VerizonLib\Models\OauthScopeEnum::SERVICEREGISTRYREAD,
        VerizonLib\Models\OauthScopeEnum::SERVICEREGISTRYWRITE,
        VerizonLib\Models\OauthScopeEnum::TS_MEC_FULLACCESS,
        VerizonLib\Models\OauthScopeEnum::TS_MEC_LIMITACCESS,
        VerizonLib\Models\OauthScopeEnum::TS_APPLICATION_RO,
        VerizonLib\Models\OauthScopeEnum::EDGEDISCOVERYREAD,
        VerizonLib\Models\OauthScopeEnum::EDGESERVICEPROFILEREAD,
        VerizonLib\Models\OauthScopeEnum::EDGESERVICEPROFILEWRITE,
        VerizonLib\Models\OauthScopeEnum::EDGESERVICEREGISTRYREAD,
        VerizonLib\Models\OauthScopeEnum::EDGESERVICEREGISTRYWRITE,
        VerizonLib\Models\OauthScopeEnum::READ,
        VerizonLib\Models\OauthScopeEnum::WRITE
    ])
    ->environment('Production')
    ->build();



// Obtain access token, restore from cache if possible
if (isset($_SESSION['access_token'])) {
    $token = $_SESSION['access_token'];
    // re-build the client with oauth token
    $client = $client->toBuilder()->oauthToken($token)->build();
} else {
    try {
        // fetch an oauth token to authorize the client
        $token = $client->getClientCredentialsAuth()->fetchToken();
        // re-build the client with oauth token
        $client = $client->toBuilder()->oauthToken($token)->build();

        // store token
        $_SESSION['access_token'] = $token;
    } catch (VerizonLib\Exceptions\ApiException $e) {
        // handle exception
    }
}

// the client is now authorized; you can use $client to make endpoint calls

List of APIs

Classes Documentation