Previous Topic

Next Topic

Inhoudsopgave

Book Index

Authentication

For security and license purposes, it is necessary for all users to retrieve a token that allows them access to the SFC service. This goes for the machines as well. Tokens are retrieved from the Authentication Service. To receive one, a user needs a user name and a password, preferably encrypted.

Add an anonymous token

An anonymous token needs to be added to the AuthenticationHeader of the calls you will use:

_httpClient.DefaultRequestHeaders.Authorization = AuthenticationHeaderValue.Parse("Bearer " + "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJpc3MiOiJJc2FoIEF1dGhlbnRpY2F0aW9uIFNlcnZpY2UiLCJhdWQiOiJJc2FoIFdlYiBTZXJ2aWNlcyIsIm5iZiI6MTQ0ODAyNTY3MSwiZXhwIjoxNjcyNTIyMjAwMCwiSXNhaFVzZXJOYW1lIjoiTWFjaGluZU9wZXJhdGlvbnMiLCJNYWNoaW5lQXV0aGVudGljYXRpb24iOiJ0cnVlIn0.C9zrjyBstUNb3hK1e3kiAVYM1hwer09mbm5VO/b6fdstHoW3G1tAMrZA9n8ElEkqYqBkJCzs46QKnp1kawyNdZbyahsfYEBZ7czRoLCVr74ozwI6yC8Do1LwRO820voTBa+bQlHEh0nGlj++k+5odX/MIVf1eX9VkgBqAjOUbITRVwIT5ia260t5ZC0UI9gy1xr7k5wievliLSkrAIVmX++7nQOUzZgKOlHSu3/vmuBA1PCPOtE6l4brnrBc04ohzBAKt3CfZG4gXxeeVOwHPd1YEzSaePzGKlo725Zwk4/u44mDiee2fGfPAzjBLcL2radEJ5OAHjZuIuGIYambJZ+oDGmGUy55Fy/RImd6secT3DJhx5TIgBbEjPiDje32Q9BYAvogplHvzlzpHI9tOCQXG44APjxN9PjW1fFy3+7cVixgMM9zGwRHkeAjNSQluO+GXOygcjIr11GW4moZVY5ak2IOuM127FBfPJLnmKT8Lb0GgLnBpNXeV4rtKkemSYTRheeF8GcDHgWdR29S+RJT3MhvdEPpR3JDox6EgiuttbUd3fAFZD8u98iqkjn/zZxKsQY2io4bFfDfdmZXM9cTMKt8IlADdsM5jOm0txgvjd11cFfSlwp4A1tpRrXNMGw03ypMZ2DY9Lk+msSZEnIzDkJJ3illbDXBHZ5iGDI=");

Retrieving a token

PUT:byte[] /MachineOperationService/users/{UserCode}/secure/token

The following instructions apply:

UserCode

For this parameter, use the machine's user code. Isah recommends you give each machine its own user name.

Content: byte[]

Byte[] holds the password that needs to be encrypted using 3DES and the public key "MACHOPERATION_PUBLIC_KEY". Below is a code example in .NET:

private static byte[] Encrypt(string password)

{

var toEncrypt = Encoding.UTF8.GetBytes(password);

var encryptor = new TripleDESCryptoServiceProvider

{

Key = Encoding.ASCII.GetBytes("MACHOPERATION_PUBLIC_KEY"),

Mode = CipherMode.ECB,

Padding = PaddingMode.PKCS7

};

var transform = encryptor.CreateEncryptor();

var result = transform.TransformFinalBlock(toEncrypt, 0, toEncrypt.Length);

encryptor.Clear();

return result;

}

Alternative method for retrieving a token

PUT:string /MachineOperationService/users/{UserCode}/unsecure/token

The following instructions apply:

UserCode

For this parameter, use the machine's user code. Isah recommends you give each machine its own user name.

Content: string

This is the password. Warning: Isah recommends using the first method, in which the password is encrypted. Use this second method only if it is not possible to use 3DES encryption.

Result

The result of this code is a string that holds a token granting a 15-minute permission for the SFC service. You need to use this token to execute the calls on the SFC service, using the same method you used to add the anonymous token. After 15 minutes, you need to retrieve a new token.