Skip to content

Service Requests

Angel Sanadinov edited this page Jul 19, 2017 · 4 revisions

Controllers: Basics | Use | Config | Service Requests | Users & Tokens

Overview

A ServiceConnection is normally used to make requests to services built with core3. Each instance can communicate with only one service at a time, so if access to more services is needed, multiple instances should be created.

While a ServiceConnection can also be used to communicate with a Workflow Engine service, it is probably easier to use a WorkflowEngineConnection (depending on the service implementation).

Requests can be sent to Microsoft's Graph API via the Graph Service Connection. For more information, check the appropriate wiki page.

Some other useful bits of information:

Auth0

When using Auth0 as the auth provider, having multiple routes is only possible by having multiple controllers, as the API configuration is bound to the route (API Identifier). Below is a simple example implementation with two routes/services.

Configuration

server.static {

  ...

  security {
    authentication {
      services {
        SOME_AUTH0_API_NAME_FOR_USER_SERVICE {
          id = "<some ID>"
          identifier = "https://<some host & port>/service/users"
        }
        SOME_AUTH0_API_NAME_FOR_CLIENT_SERVICE {
          id = "<some other ID>"
          identifier = "https://<some host & port>/service/clients"
        }
      }
      clients {
        SOME_AUTH0_CLIENT_NAME {
          //... standard client config for the current app ...
        }
      }
    }
  }

  ...

}

Setup

import akka.actor.ActorSystem
import akka.stream.Materializer
import com.google.inject.{AbstractModule, Provides, Singleton}
import core3.config.StaticConfig
import core3.http.requests.{auth0, WorkflowEngineConnection}
import play.api.Environment
import play.api.libs.ws.WSClient

import scala.concurrent.ExecutionContext

//simple container class
case class WorkflowEngineConnections(users: WorkflowEngineConnection, clients: WorkflowEngineConnection)

class Module extends AbstractModule {

  //... other providers ...

  @Provides
  @Singleton
  def provideEngineConnections(
    ws: WSClient,
    system: ActorSystem,
    environment: Environment
  )(implicit ec: ExecutionContext): WorkflowEngineConnections = {
    WorkflowEngineConnections(
      users = new WorkflowEngineConnection(
        system.actorOf(
          auth0.ServiceConnectionComponent.props(
            ws,
            StaticConfig.get.getConfig(
              "security.authentication.services.<SOME_AUTH0_API_NAME_FOR_USER_SERVICE>"
            ),
            StaticConfig.get.getConfig(
              "security.authentication.clients.<SOME_AUTH0_CLIENT_NAME>"
            )
          )
        )
      ),
      clients = new WorkflowEngineConnection(
        system.actorOf(
          auth0.ServiceConnectionComponent.props(
            ws,
            StaticConfig.get.getConfig(
              "security.authentication.services.<SOME_AUTH0_API_NAME_FOR_CLIENT_SERVICE>"
           ),
            StaticConfig.get.getConfig(
              "security.authentication.clients.<SOME_AUTH0_CLIENT_NAME>"
            )
          )
        )
      )
    )
  }

  //... other providers

}

Local

Configuration

server.static {

  ...

  security {
    authentication {
      services {
        SOME_LOCAL_AUTH_SERVICE_NAME {
          uri = "https://<some host & port>/service/users"
          serviceUser = "<some service user name>"
          serviceUserPassword = "<some service user password>"
        }
      }

      clients {
        SOME_LOCAL_AUTH_CLIENT_NAME {
          //... standard client config for the current app ...
        }
      }
    }
  }
}

Setup

import akka.actor.ActorSystem
import com.google.inject.{AbstractModule, Provides, Singleton}
import core3.config.StaticConfig
import core3.http.requests.{WorkflowEngineConnection, local}
import play.api.Environment
import play.api.libs.ws.WSClient

import scala.concurrent.ExecutionContext

class Module extends AbstractModule {

  //... other providers ...

  @Provides
  @Singleton
  def provideEngineConnection(
    ws: WSClient,
    system: ActorSystem,
    environment: Environment
  )(implicit ec: ExecutionContext): WorkflowEngineConnection = {
    new WorkflowEngineConnection(
      system.actorOf(
        local.ServiceConnectionComponent.props(
          ws,
          StaticConfig.get.getConfig(
            "security.authentication.services.<SOME_LOCAL_AUTH_SERVICE_NAME>"
          )
        )
      )
    )
  }

  //... other providers ...

}

Clone this wiki locally