In This Topic
This chapter shows how to work with the Eplan.IdentityClient.Authentification and Eplan.IdentityClient.Types namespaces.
First create an IEIdentityClient object and make sure you are signed in to EPLAN Cloud:
//Create IdentityClient instance
IEIdentityClient IdentityClient = EIdentityClient.Instance;
//Make sure you are sign in into EPLAN Cloud
Task<AuthenticationData> signInData = IdentityClient.Signin();
AuthenticationData signInResult = signInData.Result;
//Check if success
if (signInResult.IsSuccess)
new Decider().Decide(EnumDecisionType.eOkDecision, "Sign in success", "Result", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
Get example informations from user cloud profile:
//User profile informations
Task<IdentityClientResponse> userProfile = IdentityClient.GetUserProfile();
IdentityClientResponse getUserProfileResult = userProfile.Result;
//Show exmaple information
if (getUserProfileResult.IsSuccess)
{
string message = $"Organization Name: {getUserProfileResult.OrganizationName},\nEmail: {getUserProfileResult.Email}";
new Decider().Decide(EnumDecisionType.eOkDecision, message, "UserProfile success", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
}
Set ClientId name to work with specific API service in EPLAN Cloud:
//ClientId of specific EPLAN Cloud API application
string ClientId = "Proper_Client_Id_Name";
Use the GetHttpClient() method to work with EPLAN Cloud API endpoints:
//Initialize httpClient object
var url = "https://api.eplan.com/estockservice/v2.0/";
HttpClient httpClient = null;
IdentityClientResponse httpClientRespone = IdentityClient.GetHttpClient(strClientId, url, ref httpClient);
//Get collections
if (httpClientRespone.IsSuccess)
{
HttpResponseMessage GetAsyncResult = httpClient.GetAsync("collections").Result;
string message = $"Status: {GetAsyncResult.StatusCode.ToString()},\nResult: {GetAsyncResult.Content.ReadAsStringAsync().Result}";
new Decider().Decide(EnumDecisionType.eOkDecision, message, "Get result", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
}
The GetAccessToken() is called internally by GetHttpClient(), but it is still possible to use this method directly:
//Get access Token
IdentityClientResponse tokenResponse = IdentityClient.GetAccessToken(strClientId);
Sign out and exit:
//Sign out
Task<IdentityClientResponse> response = IdentityClient.Signout();
IdentityClientResponse signOutResult = response.Result;
if (signOutResult.IsSuccess)
new Decider().Decide(EnumDecisionType.eOkDecision, "Sign out success", "Result", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
//Exit IdentityClient
IdentityClientResponse exitResponse = IdentityClient.Exit();
if (exitResponse.IsSuccess)
new Decider().Decide(EnumDecisionType.eOkDecision, "Exit success", "Result", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);