This example demonstrates how to integrate server side library

Configuring and running the Server Side Library

  1. Register an account or login to the Mobile Connect Developer Portal and create an application to obtain your sandbox credentials.
  2. Download the Mobile Connect Server Side project

    git clone https://github.com/Mobile-Connect/java_server_side_sdk.git
  3. Open the configuration file: \mobile-connect-demo\src\main\resources\config\OperatorData.json.

    Note: if you operate in the EU then you should use EU Discovery Service domain: eu.discover.mobileconnect.io

    Here are 9 parameters:

    {
      "clientID": your client Id,
      "clientSecret": your client Secret,
      "discoveryURL": your Discovery endpoint,
      "redirectURL": "http://your server side app host:8080/server_side_api/discovery_callback",
      "xRedirect": "True",
      "includeRequestIP": "False",
      "apiVersion": api version: "mc_v1.1" or "mc_v1.2",
      "scope": scopes,
      "acrValues":  acr_values
    }
  4. Build the project.
    You can configure your application (clientID, clientSecret, discoveryURL, redirectURL). You can also configure your parameters for auth request (xRedirect, . includeRequestIP, apiVersion, scope, acrValues)
  5. Download and install any missing dependencies
  6. Build the SDK using Maven repository:
    cd r2-java-sdk
    mvn clean install
  7. Import the generated mobile-connect-sdk-2.4.6.jar into your Java project.
  8. Run the MobileConnect demo:
    cd r2-java-sdk
    mvn spring-boot:run -pl mobile-connect-demo

Using the Server Side Application

With your configuration specified in the configuration file you have everything you need to make a successful call to the server side application.

Example request:
If you are using only msisdn the request to your server side part will be: http://localhost:8080/server_side_api/start_discovery?msisdn=447700900907
When you are using mcc and mnc it will be: http://localhost:8080/server_side_api/start_discovery?mcc=907&mnc=07
If you choose 'None' mode: http://localhost:8080/server_side_api/start_discovery

Send your request. Makes startDiscovery method call with your configuration in parameters:

@GetMapping("start_discovery")
@ResponseBody
public String startDiscovery(
        @RequestParam(required = false) final String msisdn,
        @RequestParam(required = false) final String mcc,
        @RequestParam(required = false) final String mnc,
        @RequestParam(required = false) final String sourceIp,
        final HttpServletRequest request)
{
    LOGGER.info("* Attempting discovery for msisdn={}, mcc={}, mnc={}",
            LogUtils.mask(msisdn, LOGGER, Level.INFO), sourceIp);

    this.getParameters();

    MobileConnectRequestOptions requestOptions =
            new MobileConnectRequestOptions.Builder()
                    .withDiscoveryOptions(new DiscoveryOptions.Builder()
                            .withClientIp(sourceIp).build())
                    .build();
    final MobileConnectStatus status =
            this.mobileConnectWebInterface.attemptDiscovery(request, msisdn, mcc, mnc, true, mobileConnectConfig.getIncludeRequestIp(), requestOptions);

    cachedParameters.setSdkSession(status.getSdkSession());

    return status.getUrl() != null ? status.getUrl() : startAuthentication(cachedParameters.getSdkSession(), status.getDiscoveryResponse().getResponseData().getSubscriberId(), request);

}

This method calls attemptDiscovery SDK method with your parameters from config file. And then startAuthentication method perfoms for getting authentication URL.
To generate the request parameters it uses getParameters method:
private void getParameters() {
    operatorParams = ReadAndParseFiles.ReadFile(Constants.ConfigFilePath);
    apiVersion = operatorParams.getApiVersion();
    includeRequestIP = operatorParams.getIncludeRequestIP().equals("True");
    this.cache = new ConcurrentCache.Builder().withJsonService(this.jsonService).build();
    try {
        mobileConnectConfig = new MobileConnectConfig.Builder()
                .withClientId(operatorParams.getClientID())
                .withClientSecret(operatorParams.getClientSecret())
                .withDiscoveryUrl(new URI(operatorParams.getDiscoveryURL()))
                .withRedirectUrl(new URI(operatorParams.getRedirectURL()))
                .withXRedirect(operatorParams.getXRedirect().equals("True") ? "APP" : "False")
                .build();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

If you follow the link:
1) msisdn mode: you call discoveryCallback method and will receive a token
@GetMapping("discovery_callback")
@ResponseBody
public MobileConnectWebResponse DiscoveryCallback(@RequestParam(required = false) final String state, final HttpServletRequest request)
{
    final MobileConnectRequestOptions options = new MobileConnectRequestOptions.Builder()
            .withAuthenticationOptions(new AuthenticationOptions.Builder()
                    .withContext(apiVersion.equals(Constants.Version2) ? Constants.ContextBindingMsg : null)
                    .withBindingMessage(apiVersion.equals(Constants.Version2) ? Constants.ContextBindingMsg : null)
                    .withClientName(clientName)
                    .build())
            .build();

    final URI requestUri = HttpUtils.extractCompleteUrl(request);
    MobileConnectStatus status = this.mobileConnectWebInterface.handleUrlRedirect(request, requestUri, cachedParameters.getSdkSession(), state, cachedParameters.getNonce(), options);

    cachedParameters.setAccessToken(status.getRequestTokenResponse().getResponseData().getAccessToken());
    return new MobileConnectWebResponse(status);
}

2) mcc_mnc mode or none mode: you will be redirected to the operator selection page. Here you can type your msisdn and process page.

In any case after getting URL with 'code' and 'state' parameters application returns the response with JSON, that contains the results information.

Discovery caching

Discovery response is cached in SDK with following rules:

  1. After succeed Discovery request, Discovery response is cached with used mcc/mnc, msisdn or sourceIp.
  2. Expiration time for Discovery Response cache is the same as "ttl" field in Discovery Response - if Discovery Response expired - that deleted from cache
  3. Next requests for Discovery with the same mcc/mnc, msisdn or sourceIp - Discovery request shouldn't be performed, Discovery response should be taken from cache
  4. If auth call respond with error - Discovery Response deleted from cache, and SDK redirect you to Discovery UI