Pip.Services Logo
Roles Microservice

This is a user roles microservice from Pip.Services library. It provides basic role-based authorization mechanism for users.

The microservice currently supports the following deployment options:

  • Deployment platforms: Standalone Process, Seneca
  • External APIs: HTTP/REST, Seneca
  • Persistence: Flat Files, MongoDB

This microservice has no dependencies on other microservices.

Quick Links:


Logical contract of the microservice is presented below. For physical implementation (HTTP/REST), please, refer to documentation of the specific protocol.

class UserRolesV1 implements IStringIdentifiable {
  String id;
  List<String> roles;
  DateTime update_time;

abstract class IRolesV1 {
  Future<DataPage<UserRolesV1>> getRolesByFilter(
      String correlationId, FilterParams filter, PagingParams paging);

  Future<List<String>> getRolesById(String correlationId, String userId);

  Future<List<String>> setRoles(String correlationId, String userId, List<String> roles);

  Future<List<String>> grantRoles(String correlationId, String userId, List<String> roles);

  Future<List<String>> revokeRoles(String correlationId, String userId, List<String> roles);

  Future<bool> authorize(String correlationId, String userId, List<String> roles);


Right now the only way to get the microservice is to check it out directly from github repository

git clone git@github.com:pip-services-users/pip-services-roles-dart.git

Pip.Service team is working to implement packaging and make stable releases available for your as zip downloadable archieves.


Add config.yaml file to the root of the microservice folder and set configuration parameters.

Example of microservice configuration

# Container descriptor
- descriptor: "pip-services:context-info:default:default:1.0"
  name: "pip-services-roles"
  description: "Roles microservice for pip-services"

# Console logger
- descriptor: "pip-services:logger:console:default:1.0"
  level: "trace"

# Performance counters that posts values to log
- descriptor: "pip-services:counters:log:default:1.0"
  level: "trace"

# In-memory persistence. Use only for testing!
- descriptor: "pip-services-roles:persistence:memory:default:1.0"

# File persistence. Use it for testing of for simple standalone deployments
- descriptor: "pip-services-roles:persistence:file:default:1.0"
  path: {{FILE_PATH}}{{^FILE_PATH}}"./data/roles.json"{{/FILE_PATH}}

# MongoDB Persistence
- descriptor: "pip-services-roles:persistence:mongodb:default:1.0"
    uri: {{{MONGO_SERVICE_URI}}}
    database: {{MONGO_DB}}{{#^MONGO_DB}}app{{/^MONGO_DB}}
    username: {{MONGO_USER}}
    password: {{MONGO_PASS}}

# Default in-memory persistence
- descriptor: "pip-services-roles:persistence:memory:default:1.0"

# Default controller
- descriptor: "pip-services-roles:controller:default:default:1.0"

# Common HTTP endpoint
- descriptor: "pip-services:endpoint:http:default:1.0"
    protocol: "http"
    host: ""
    port: 8080

# HTTP endpoint version 1.0
- descriptor: "pip-services-roles:service:http:default:1.0"

# Heartbeat service
- descriptor: "pip-services:heartbeat-service:http:default:1.0"

# Status service
- descriptor: "pip-services:status-service:http:default:1.0"

For more information on the microservice configuration see Configuration Guide.

Start the microservice using the command:

dart ./bin/run.dart


The easiest way to work with the microservice is to use client SDK. The complete list of available client SDKs for different languages is listed in the Quick Links

If you use dart, then get references to the required libraries:

Add pip-services3-commons-dart, pip-services3-rpc-dart and pip-services_roles packages

import 'package:pip_services3_commons/pip_services3_commons.dart';
import 'package:pip_services3_rpc/pip_services3_rpc.dart';

import 'package:pip_services_roles/pip_services_roles.dart';

Define client configuration parameters that match the configuration of the microservice's external API

// Client configuration
var httpConfig = ConfigParams.fromTuples(
	"connection.protocol", "http",
	"connection.host", "localhost",
	"connection.port", 8080

Instantiate the client and open connection to the microservice

// Create the client instance
var client = RolesHttpClientV1(config);

// Configure the client

// Connect to the microservice
  await client.open(null)
}catch() {
  // Error handling...
// Work with the microservice
// ...

Now the client is ready to perform operations

final ROLES = ['Role 1', 'Role 2', 'Role 3'];

    // Set the roles
    try {
      var role = await client.setRoles('123', '1', ROLES);
      // Do something with the returned roles...
    } catch(err) {
      // Error handling...     
// Get the roles by id
try {
var role = await client.getRolesById(
    // Do something with roles...

    } catch(err) { // Error handling}
// Grant user a role
try {
var role = await client.grantRoles(
    // Do something with roles...

    } catch(err) { // Error handling}

// Authorize user
try {
var role = await client.authorize(
    // Do something with bool value(authorized or not authorized) ...

    } catch(err) { // Error handling}    


This microservice was created and currently maintained by

  • Sergey Seroukhov.
  • Nuzhnykh Egor