![]() | AuthenticateControllerLoginUser Method |
Namespace: MedTunnelSvc.Controllers
private string LoginUser(string applicationId, string locationId, string medTunnelId, string password, int expiration = 10) { //namespaces to include //using System; //using System.Net; //using System.Web.Script.Serialization; string url; string downloadString; Result webResult; string token = ""; JavaScriptSerializer serializer = new JavaScriptSerializer(); UserCredentials userLoginInfo = new UserCredentials(); UserToken userToken = new UserToken(); using (WebClient client = new WebClient()) { client.Headers[HttpRequestHeader.ContentType] = "application/json"; userLoginInfo.ApplicationId = applicationId; userLoginInfo.LocationId = locationId; userLoginInfo.MedTunnelId = medTunnelId; userLoginInfo.Password = password; userLoginInfo.ExpirationInMinutes = expiration; var data = serializer.Serialize(userLoginInfo); url = "https://server.medtunnel.com/MedTunnelSvc/api/Authenticate/LoginUser"; //send the PUT request to the API downloadString = client.UploadString(url, "PUT", data); //get the Result object webResult = serializer.Deserialize<Result>(downloadString); if (webResult.ReturnCode == 1) { userToken = (UserToken)serializer.Deserialize<UserToken>(webResult.Data.ToString()); if (userToken != null && userToken.UserId > 0) { token = userToken.Token; } else { token = ""; } } else { token = ""; } } return token; }
curl -X PUT -k -H "Content-Type: application/json" -d "{ 'MedTunnelId':'yourMedTunnelId@yourGroup', 'Password':'yourPassword', 'ApplicationId':'yourApplicationId', 'LocationId':'yourLocationId', 'ExpirationInMinutes':'50' }" https://server.medtunnel.com/MedTunnelSvc/api/Authenticate/LoginUser