API Explorer 936 endpoints

Create (DAuth) User with Roles

POST /obp/v7.0.0/user-entitlements

OBPv4.0.0-createUserWithRoles No role required RoleEntitlementUserDAuth

This endpoint is used as part of the DAuth solution to grant Entitlements for Roles to a smart contract on the blockchain.

Put the smart contract address in username

For provider use "dauth"

This endpoint will create the User with username and provider if the User does not already exist.

Then it will create Entitlements i.e. grant Roles to the User.

Entitlements are used to grant System or Bank level roles to Users. (For Account level privileges, see Views)

i.e. Entitlements are used to create / consume system or bank level resources where as views / account access are used to consume / create customer level resources.

For a System level Role (.e.g CanGetAnyUser), set bank_id to an empty string i.e. "bank_id":""

For a Bank level Role (e.g. CanCreateAccount), set bank_id to a valid value e.g. "bank_id":"my-bank-id"

Note: The Roles actually granted will depend on the Roles that the calling user has.

If you try to grant Entitlements to a user that already exist (duplicate entitilements) you will get an error.

For information about DAuth see below:

<details> <summary style="display:list-item;cursor:s-resize;">DAuth</summary>

<h3><a href="#dauth-introduction-setup-and-usage">DAuth Introduction, Setup and Usage</a></h3> <p>DAuth is an experimental authentication mechanism that aims to pin an ethereum or other blockchain Smart Contract to an OBP "User".</p> <p>In the future, it might be possible to be more specific and pin specific actors (wallets) that are acting within the smart contract, but so far, one smart contract acts on behalf of one User.</p> <p>Thus, if a smart contract "X" calls the OBP API using the DAuth header, OBP will get or create a user called X and the call will proceed in the context of that User "X".</p> <p>DAuth is invoked by the REST client (caller) including a specific header (see step 3 below) in any OBP REST call.</p> <p>When OBP receives the DAuth token, it creates or gets a User with a username based on the smart_contract_address and the provider based on the network_name. The combination of username and provider is unique in OBP.</p> <p>If you are calling OBP-API via an API3 Airnode, the Airnode will take care of constructing the required header.</p> <p>When OBP detects a DAuth header / token it first checks if the Consumer is allowed to make such a call. OBP will validate the Consumer ip address and signature etc.</p> <p>Note: The DAuth flow does <em>not</em> require an explicit POST like Direct Login to create the token.</p> <p>Permissions may be assigned to an OBP User at any time, via the UserAuthContext, Views, Entitlements to Roles or Consents.</p> <p>Note: <em>DAuth is NOT enabled on this instance!</em></p> <p>Note: <em>The DAuth client is responsible for creating a token which will be trusted by OBP absolutely</em>!</p> <p>To use DAuth:</p> <h3><a href="#1-configure-obp-api-to-accept-dauth">1) Configure OBP API to accept DAuth.</a></h3> <p>Set up properties in your props file</p> <pre><code># -- DAuth --------------------------------------

Define secret used to validate JWT token

jwt.public_key_rsa=path-to-the-pem-file

Enable/Disable DAuth communication at all

In case isn't defined default value is false

allow_dauth=false

Define comma separated list of allowed IP addresses

dauth.host=127.0.0.1

-------------------------------------- DAuth--

</code></pre> <p>Please keep in mind that property jwt.public_key_rsa is used to validate JWT token to check it is not changed or corrupted during transport.</p> <h3><a href="#2-create-have-access-to-a-jwt">2) Create / have access to a JWT</a></h3> <p>The following videos are available:<br />

  • <a href="https://vimeo.com/644315074">DAuth in local environment</a></p> <p>HEADER:ALGORITHM & TOKEN TYPE</p> <pre><code>{ "alg": "RS256", "typ": "JWT" } </code></pre> <p>PAYLOAD:DATA</p> <pre><code>{ "smart_contract_address": "0xe123425E7734CE288F8367e1Bb143E90bb3F051224", "network_name": "AIRNODE.TESTNET.ETHEREUM", "msg_sender": "0xe12340927f1725E7734CE288F8367e1Bb143E90fhku767", "consumer_key": "0x1234a4ec31e89cea54d1f125db7536e874ab4a96b4d4f6438668b6bb10a6adb", "timestamp": "2021-11-04T14:13:40Z", "request_id": "0Xe876987694328763492876348928736497869273649" } </code></pre> <p>VERIFY SIGNATURE</p> <pre><code>RSASHA256( base64UrlEncode(header) + "." + base64UrlEncode(payload),

) your-RSA-key-pair </code></pre> <p>Here is an example token:</p> <pre><code>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzbWFydF9jb250cmFjdF9hZGRyZXNzIjoiMHhlMTIzNDI1RTc3MzRDRTI4OEY4MzY3ZTFCYjE0M0U5MGJiM0YwNTEyMjQiLCJuZXR3b3JrX25hbWUiOiJFVEhFUkVVTSIsIm1zZ19zZW5kZXIiOiIweGUxMjM0MDkyN2YxNzI1RTc3MzRDRTI4OEY4MzY3ZTFCYjE0M0U5MGZoa3U3NjciLCJjb25zdW1lcl9rZXkiOiIweDEyMzRhNGVjMzFlODljZWE1NGQxZjEyNWRiNzUzNmU4NzRhYjRhOTZiNGQ0ZjY0Mzg2NjhiNmJiMTBhNmFkYiIsInRpbWVzdGFtcCI6IjIwMjEtMTEtMDRUMTQ6MTM6NDBaIiwicmVxdWVzdF9pZCI6IjBYZTg3Njk4NzY5NDMyODc2MzQ5Mjg3NjM0ODkyODczNjQ5Nzg2OTI3MzY0OSJ9.XSiQxjEVyCouf7zT8MubEKsbOBZuReGVhnt9uck6z6k </code></pre> <h3><a href="#3-try-a-rest-call-using-the-header">3) Try a REST call using the header</a></h3> <p>Using your favorite http client:</p> <p>GET <a href="https://obp-api-sandbox.nmbbank.co.tz/obp/v3.0.0/users/current">https://obp-api-sandbox.nmbbank.co.tz/obp/v3.0.0/users/current</a></p> <p>Body</p> <p>Leave Empty!</p> <p>Headers:</p> <pre><code> DAuth: your-jwt-from-step-above </code></pre> <p>Here is it all together:</p> <p>GET <a href="https://obp-api-sandbox.nmbbank.co.tz/obp/v3.0.0/users/current">https://obp-api-sandbox.nmbbank.co.tz/obp/v3.0.0/users/current</a> HTTP/1.1<br /> Host: localhost:8080<br /> User-Agent: curl/7.47.0<br /> Accept: <em>/</em><br /> DAuth: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzbWFydF9jb250cmFjdF9hZGRyZXNzIjoiMHhlMTIzNDI1RTc3MzRDRTI4OEY4MzY3ZTFCYjE0M0U5MGJiM0YwNTEyMjQiLCJuZXR3b3JrX25hbWUiOiJFVEhFUkVVTSIsIm1zZ19zZW5kZXIiOiIweGUxMjM0MDkyN2YxNzI1RTc3MzRDRTI4OEY4MzY3ZTFCYjE0M0U5MGZoa3U3NjciLCJjb25zdW1lcl9rZXkiOiIweDEyMzRhNGVjMzFlODljZWE1NGQxZjEyNWRiNzUzNmU4NzRhYjRhOTZiNGQ0ZjY0Mzg2NjhiNmJiMTBhNmFkYiIsInRpbWVzdGFtcCI6IjIwMjEtMTEtMDRUMTQ6MTM6NDBaIiwicmVxdWVzdF9pZCI6IjBYZTg3Njk4NzY5NDMyODc2MzQ5Mjg3NjM0ODkyODczNjQ5Nzg2OTI3MzY0OSJ9.XSiQxjEVyCouf7zT8MubEKsbOBZuReGVhnt9uck6z6k</p> <p>CURL example</p> <pre><code>curl -v -H 'DAuth: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzbWFydF9jb250cmFjdF9hZGRyZXNzIjoiMHhlMTIzNDI1RTc3MzRDRTI4OEY4MzY3ZTFCYjE0M0U5MGJiM0YwNTEyMjQiLCJuZXR3b3JrX25hbWUiOiJFVEhFUkVVTSIsIm1zZ19zZW5kZXIiOiIweGUxMjM0MDkyN2YxNzI1RTc3MzRDRTI4OEY4MzY3ZTFCYjE0M0U5MGZoa3U3NjciLCJjb25zdW1lcl9rZXkiOiIweDEyMzRhNGVjMzFlODljZWE1NGQxZjEyNWRiNzUzNmU4NzRhYjRhOTZiNGQ0ZjY0Mzg2NjhiNmJiMTBhNmFkYiIsInRpbWVzdGFtcCI6IjIwMjEtMTEtMDRUMTQ6MTM6NDBaIiwicmVxdWVzdF9pZCI6IjBYZTg3Njk4NzY5NDMyODc2MzQ5Mjg3NjM0ODkyODczNjQ5Nzg2OTI3MzY0OSJ9.XSiQxjEVyCouf7zT8MubEKsbOBZuReGVhnt9uck6z6k' https://obp-api-sandbox.nmbbank.co.tz/obp/v3.0.0/users/current </code></pre> <p>You should receive a response like:</p> <pre><code>{ "user_id": "4c4d3175-1e5c-4cfd-9b08-dcdc209d8221", "email": "", "provider_id": "0xe123425E7734CE288F8367e1Bb143E90bb3F051224", "provider": "ETHEREUM", "username": "0xe123425E7734CE288F8367e1Bb143E90bb3F051224", "entitlements": { "list": [] } } </code></pre> <h3><a href="#under-the-hood">Under the hood</a></h3> <p>The file, dauth.scala handles the DAuth,</p> <p>We:</p> <pre><code>-> Check if Props allow_dauth is true -> Check if DAuth header exists -> Check if getRemoteIpAddress is OK -> Look for "token" -> parse the JWT token and getOrCreate the user -> get the data of the user </code></pre> <h3><a href="#more-information">More information</a></h3> <p>Parameter names and values are case sensitive.<br /> Each parameter MUST NOT appear more than once per request.</p>

</details>

<br></br>

User Authentication is Required. The User must be logged in. The Application must also be authenticated.

JSON request body fields (5)
bank_id
gh.29.uk
provider
ETHEREUM
role_name
roles
CanCreateMyUser
username
felixsmith
JSON response body fields (5)
bank_id
gh.29.uk
entitlement_id
list
role_name
user_id
9ca9a7e4-6d02-40e3-a129-0b2bf89de9b1
Example request body
{
  "username": "felixsmith",
  "provider": "dauth.ETHEREUM",
  "roles": [
    {
      "bank_id": "gh.29.uk",
      "role_name": "CanCreateBranch"
    }
  ]
}
Example success response
{
  "list": [
    {
      "entitlement_id": "",
      "role_name": "",
      "bank_id": "gh.29.uk",
      "user_id": "9ca9a7e4-6d02-40e3-a129-0b2bf89de9b1"
    }
  ]
}
Possible errors (8)
  • OBP-20001: User not logged in. Authentication is required!
  • OBP-10001: Incorrect json format.
  • OBP-10007: Incorrect Role name:
  • OBP-30205: This entitlement is a Bank Role. Please set bank_id to a valid bank id.
  • OBP-30206: This entitlement is a System Role. Please set bank_id to empty string.
  • OBP-30216: Entitlement already exists for the user.
  • OBP-20103: Invalid DAuth User Provider.
  • OBP-50000: Unknown Error.
Implemented by OBPv4.0.0 createUserWithRoles Originally /obp/v4.0.0/user-entitlements