public void Authenticated(CipheriseAuthenticationResponse eResponse, string strUserName, string strDeviceName, string strDeviceID) { m_strUserName = strUserName; m_strDeviceName = strDeviceName; m_strDeviceID = strDeviceID; m_eResponse = eResponse; }
static async Task <string> CipheriseExample(string strCipheriseServer, bool bVerbose) { Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); Cipherise.CipheriseSP.SetTraceLevel(bVerbose ? TraceLevel.Verbose : TraceLevel.Error); ICipheriseServiceProvider SP = Cipherise.CipheriseSP.CreateServiceProvider(strCipheriseServer); ///////////////////////////////////////////////////////// //Server Version ServerInfo SI = new ServerInfo(); if (false == await SP.Info(SI)) { Console.WriteLine("\nInfo() error: {0}", SI.m_strCipheriseError); return("Cipherise failed during Info()"); } ///////////////////////////////////////////////////////// //Register a service provider // This should happen only once. if (false == await SP.Register("My New Cipherise Service Provider")) { return("Cipherise failed during Register()"); } string strServiceID = SP.GetServiceProviderID(); Console.WriteLine("Service Provider created with ID: {0}", strServiceID); ///////////////////////////////////////////////////////// //Verify registration of the service provider. // Uses the current Service Id. // One could call SP.SetPreviousSessionID( otherID ) to change the Service Id. if (false == await SP.IsRegistered()) { return("Cipherise failed during IsRegistered()"); } ///////////////////////////////////////////////////////// //Set a user name. const string strUserName = "******"; ///////////////////////////////////////////////////////// //Enrol a user EnrolUser EU = new EnrolUser(strUserName); if (false == await SP.EnrolUser(EU)) { return("Cipherise failed during EnrolUser()"); } ///////////////////////////////////////////////////////// //Query a users devices DeviceData Device = new DeviceData(strUserName); if (false == await SP.RetrieveUsersDevices(Device)) { return("Cipherise failed during RetrieveUsersDevices()"); } while (true) { Console.WriteLine(); Console.WriteLine("P) Push Authentication"); Console.WriteLine("W) Wave Authentication"); Console.WriteLine("X) Exit"); Console.WriteLine("---------------------------"); Console.Write("Press P, W or X: "); char ch = GetChar("PWX"); if (ch == 'X') { Console.WriteLine(); Console.WriteLine(); break; } CipheriseAuthenticationResponse eResponse = CipheriseAuthenticationResponse.eCAR_Cancel; string strAuthUserName = strUserName; string strAuthDeviceID = Device.GetDeviceID(); AuthenticateBase Auth = null; if (ch == 'P') { ///////////////////////////////////////////////////////// //Send an authentication request to the users device. Console.WriteLine(); Console.WriteLine("Sending an authentication request to the device. Please acknowledge it..."); Auth = new AuthPush(strAuthUserName, strAuthDeviceID); } if (ch == 'W') { ///////////////////////////////////////////////////////// //Start a Wave authentication request, which will give the // user a WaveCode to scan with their phone/device. Auth = new WaveAuth(); } if (Auth != null) { if (false == await SP.Authenticate(Auth)) { return("Cipherise failed during Authenticate()"); } eResponse = Auth.GetResponse(); } Console.WriteLine(); if (eResponse == CipheriseAuthenticationResponse.eCAR_Accept) { Console.WriteLine("User '{0}' accepted authentication on device '{1}'.", Auth.GetUserName(), Auth.GetDeviceID()); } else if (eResponse == CipheriseAuthenticationResponse.eCAR_Cancel) { Console.WriteLine("Authentication was cancelled!"); } else if (eResponse == CipheriseAuthenticationResponse.eCAR_Report) { Console.WriteLine("Authentication was reported!"); } } ///////////////////////////////////////////////////////// //Revoke a users device from using this service provider. // The user will no long be able to use the device ID to authenticate. // Re-enrolling the user and their device will rectivate the device for this service provider. // Pass in an empty device ID list to revoke all devices for a user. RevokeUser RU = new RevokeUser(strUserName, new string[1] { Device.GetDeviceID() }); if (false == await SP.RevokeUser(RU)) { return("Cipherise failed during RevokeUser()"); } if (RU.GetInvalidDeviceIDCount() > 0) { return("Cipherise failed during RevokeUser() - contained a invalid ID"); } Console.WriteLine("User and device were revoked."); ///////////////////////////////////////////////////////// //Revoke a service provider. // This should happen only once. // The service ID will no longer be usable. // Users will no longer be able to authenticate. if (false == await SP.Revoke()) { return("Cipherise failed during Revoke()"); } Console.WriteLine("Service Provider was revoked."); return("Cipherise completed successfully."); }