private void MainForm_Load(object sender, EventArgs e) { TrayHelper trayHelper = new TrayHelper(this); WebOcxAccess.init(this.axCryptCtl1); if (ConfigManager.Instance.Config.license == null) { ConfigManager.Instance.Config.license = Guid.NewGuid().ToString("B"); } String sh = ConfigManager.Instance.Config.sh; String password = ConfigManager.Instance.Config.password; String license = ConfigManager.Instance.Config.license; String PT_PWD = ConfigManager.Instance.Config.PT_PWD; if (sh != null) { usedShLabel.Text = sh; shBox.Text = sh; } if (password != null) { passwordBox.Text = password; passwordBox2.Text = password; } if (PT_PWD != null) { PT_PWD_textBox.Text = PT_PWD; PT_PWD_textBox2.Text = PT_PWD; } if (ConfigManager.Instance.Config.taskServerIP != null) { taskServerIPBox.Text = ConfigManager.Instance.Config.taskServerIP; } if (ConfigManager.Instance.Config.taskServerPort != null) { taskServerPortBox.Text = ConfigManager.Instance.Config.taskServerPort; } if (ConfigManager.Instance.Config.sh != null && ConfigManager.Instance.Config.PT_PWD != null && ConfigManager.Instance.Config.password != null && ConfigManager.Instance.Config.taskServerIP != null && ConfigManager.Instance.Config.taskServerPort != null) { TokenTask.tockenTaskRequestThreadInit(); } }
public async Task <BioIdToken> getTokenAsync() { string query = $"token?id={appID}&bcid=xxx&task=livenessdetection&livedetection=true&challenge=false&autoenroll=false"; var uri = new Uri(new Uri(apiUrl), query); var response = await httpClient.GetAsync(uri); if (!response.IsSuccessStatusCode) { return(null); } string access_token = await response.Content.ReadAsStringAsync(); // parse the token to find settings for the user interface string claimstring = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(access_token.Split('.')[1])); var claims = JObject.Parse(claimstring); TokenTask taskFlags = (TokenTask)claims["task"].Value <int>(); int recordings = (taskFlags & TokenTask.LiveDetection) == TokenTask.LiveDetection ? (taskFlags & TokenTask.Enroll) == TokenTask.Enroll ? 4 : 2 : 1; string challengesJson = "[]"; if ((taskFlags & TokenTask.ChallengeResponse) == TokenTask.ChallengeResponse) { recordings = 4; string challenges = (string)claims["challenge"]; if (!string.IsNullOrEmpty(challenges)) { challengesJson = challenges; string[][] challengeSequences = JsonConvert.DeserializeObject <string[][]>(challenges); if (challengeSequences.Length > 0 && challengeSequences[0].Length > 0) { recordings = challengeSequences[0].Length + 1; } } } return(new BioIdToken() { Task = (taskFlags & TokenTask.Enroll) == TokenTask.Enroll ? "enrollment" : (taskFlags & TokenTask.Identify) == TokenTask.Identify ? "identification" : (taskFlags & TokenTask.LiveOnly) == TokenTask.LiveOnly ? "livenessdetection" : "verification", MaxTries = (int)(taskFlags & TokenTask.MaxTriesMask), Recordings = recordings, ChallengeResponse = (taskFlags & TokenTask.ChallengeResponse) == TokenTask.ChallengeResponse, ChallengesJson = challengesJson, Token = access_token, ApiUrl = apiUrl, State = "encrypted_app_status", Trait = "Face,Periocular", AutoEnroll = (taskFlags & TokenTask.AutoEnroll) == TokenTask.AutoEnroll, AutoStart = false }); }
private void MainForm_Load(object sender, EventArgs e) { //TypeSelect form = new TypeSelect(); //DialogResult result = form.ShowDialog(); //if(result == DialogResult.OK) //{ // ConfigManager.Instance.Config.clientType = "USB"; //}else //{ // ConfigManager.Instance.Config.clientType = "PC"; //} TrayHelper trayHelper = new TrayHelper(this); WebOcxAccess.init(this.axCryptCtl1); if (ConfigManager.Instance.Config.license == null) { ConfigManager.Instance.Config.license = Guid.NewGuid().ToString("B"); } String taskServerIP = ConfigManager.Instance.Config.taskServerIP; String taskServerPort = ConfigManager.Instance.Config.taskServerPort; if (taskServerIP != null) { taskServerIPBox.Text = taskServerIP; } if (taskServerPort != null) { taskServerPortBox.Text = taskServerPort; } String controlVersion = ConfigManager.Instance.Config.controlVersion; if ("baiwang".Equals(controlVersion)) { baiwangRadioButton.Checked = true; } if (taskServerIP != null && taskServerPort != null) { TokenTask.tockenTaskRequestThreadInit(); } }
// Call the UUI public async Task <ActionResult> Uui(UuiFormModel model) { if (string.IsNullOrEmpty(model.ApiUrl)) { return(View("Index", new MessageViewModel { Theme = "danger", Heading = "Call to UUI failed!", Text = "Please specify the Web API endpoint." })); } try { bool skipIntro = false; // well lets start by fetching a BWS token using var httpClient = new HttpClient(); string credentials = Convert.ToBase64String(Encoding.GetEncoding("iso-8859-1").GetBytes($"{_appID}:{_appSecret}")); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials); string query = $"token?id={_appID}&bcid={model.BCID}&task={model.Operation}&livedetection=true&challenge={model.ChallengeResponse}&autoenroll={model.AutoEnroll}"; if (!model.ApiUrl.EndsWith("/")) { model.ApiUrl += "/"; } var uri = new Uri(new Uri(model.ApiUrl), query); var response = await httpClient.GetAsync(uri); if (!response.IsSuccessStatusCode) { return(View("Index", new MessageViewModel { Theme = "danger", Heading = "Call to UUI failed!", Text = response.Content.ReadAsStringAsync().Result })); } // lets read the token string access_token = await response.Content.ReadAsStringAsync(); // parse the token to find settings for the user interface string claimstring = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(access_token.Split('.')[1])); var claims = JObject.Parse(claimstring); TokenTask taskFlags = (TokenTask)claims["task"].Value <int>(); int recordings = (taskFlags & TokenTask.LiveDetection) == TokenTask.LiveDetection ? (taskFlags & TokenTask.Enroll) == TokenTask.Enroll ? 4 : 2 : 1; string challengesJson = "[]"; if ((taskFlags & TokenTask.ChallengeResponse) == TokenTask.ChallengeResponse) { recordings = 4; string challenges = (string)claims["challenge"]; if (!string.IsNullOrEmpty(challenges)) { challengesJson = challenges; string[][] challengeSequences = JsonConvert.DeserializeObject <string[][]>(challenges); if (challengeSequences.Length > 0 && challengeSequences[0].Length > 0) { recordings = challengeSequences[0].Length + 1; } } } // render the BWS unified user interface return(View("uui", new UuiViewModel { Task = (taskFlags & TokenTask.Enroll) == TokenTask.Enroll ? "enrollment" : (taskFlags & TokenTask.Identify) == TokenTask.Identify ? "identification" : (taskFlags & TokenTask.LiveOnly) == TokenTask.LiveOnly ? "livenessdetection" : "verification", MaxTries = (int)(taskFlags & TokenTask.MaxTriesMask), Recordings = recordings, MotionThreshold = MobileDevice.IsMobileDevice(Request) ? Constants.MotionThresholdMobile : Constants.MotionThreshold, ChallengeResponse = (taskFlags & TokenTask.ChallengeResponse) == TokenTask.ChallengeResponse, ChallengesJson = challengesJson, Token = access_token, ApiUrl = model.ApiUrl, ReturnUrl = $"{Request.Scheme}://{Request.Host}/home/uuicallback", State = "encrypted_app_status", Trait = model.Face ? (model.Periocular ? "Face,Periocular" : "Face") : "Periocular", AutoEnroll = (taskFlags & TokenTask.AutoEnroll) == TokenTask.AutoEnroll, SkipIntro = skipIntro })); } catch (Exception ex) { return(View("Index", new MessageViewModel { Theme = "danger", Heading = "Call to UUI failed!", Text = ex.Message })); } }