Skip to content

BlueRainSoftware/id4i-api_client-sample-csharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CircleCI Support Chat API Client Version

ID4i API Client Example - C#

ID4i provides globally unique IDs for single workpieces and a platform to manage, and exchange data bound to IDs in an inter-organizational manner. For details, please refer to http://id4i.de.

This repository contains all example C# .Net API Client for ID4i. For detailed documentation of ID4i see https://backend.id4i.de/docs/reference/en/reference.html#_tutorials

The sources of the client library we use to connect to ID4i along with further documentation is available here: https://github.com/BlueRainSoftware/id4i-api_client-csharp

Prerequisites

  • .NET Core SDK >= 1.3

Preparation

To be able to connect to ID4i with an API client, you need to register and set up an API key for your application first. Using this key, you can sign JWTs to send as Authorization header for subsequent requests.

  1. If you do not already have an ID4i sandbox account, please register at https://sandbox.id4i.de and log in.

  2. Navigate to API Keys and select New API Key

    readme new api key
    Figure 1. New API Key
  3. Give your key a label and enter an application secret (or let the application generate one for you). [1]

    readme new api key 2
    Figure 2. API Key Label and Secret
  4. Save your secret resp. your public key in a secure location. For security reasons, you won’t be able to display this key again in ID4i.

  5. Activate the key on the details page

    readme new api key 3
    Figure 3. API Key Activation
Warning
Do not store your API Keys and Secrets with the source code of your application. Either supply the key as a configuration property of your application or retrieve it from your own server when required in the application. Use a separate API Key for each deployment of your application.

Run

Once you have set up your API key, you need to set the environment variables ID4I_API_KEY and ID4I_API_SECRET to reflect your key. You can then run the project using dotnet run.

You should see some information about the version running on the https://sandbox.id4i.de now:

$ dotnet run

class AppInfoPresentation {
  Branch: sandbox
  CommitTime: 2018-03-16T14:51:47+0000
  Name: ID4i
  Revision: 4584e5c
  Version: 0.6.0
}

How this project was set up

dotnet new console -o ID4iClientSample
dotnet add package BlueRain.ID4i
dotnet add package System.IdentityModel.Tokens.Jwt

Build within docker

We provide a Dockerfile to run the build on non-windows machines. To build the container and run the sample, do the following.

$ docker build -t id4i-csharp-sample:latest .
Step 1/5 : FROM microsoft/dotnet:1-sdk
 ---> 6946b52e7215
Step 2/5 : WORKDIR /app
 ---> Using cache
 ---> 4ce559a3c5b1
Step 3/5 : COPY ID4iClientSample/* /app/
 ---> Using cache
 ---> 6391678eb4ba
Step 4/5 : RUN dotnet restore
 ---> Using cache
 ---> fa0829d486fb
Step 5/5 : RUN dotnet build
 ---> Using cache
 ---> f5ebc4895e10
Successfully built f5ebc4895e10
Successfully tagged id4i-csharp-sample:latest

# built successfully, now run
$ docker run \
 -e ID4I_API_KEY=<your API key> \ (1)
 -e ID4I_API_SECRET=<your API key secret> \ (2)
 id4i-csharp-sample \ (3)
 dotnet run (4)

{
    "name": "ID4i",
    "revision": "3089680",
    "branch": "sandbox",
    "commitTime": "2018-04-23T13:12:13+0000",
    "version": "0.6.0",
    "productionMode": true
}
  1. A valid API Key, this is passed to the container as environment varibale

  2. Your API key secret, required to sign the JWT. Exposed in the container’s environment as well

  3. The image to start

  4. The command to run in the image


1. When using asymmetric signing, you would use your public key here.

About

ID4i API client example in C# .NET

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published