Exemplo n.º 1
0
        public static async Task AuthenticateAsync()
        {
            #region Device Level

            // Set Personal Info
            var personalInfo = new PersonalInfo
            {
                AadhaarNumber = "999999990019",
                Demographic   = new Demographic
                {
                    Identity = new Identity
                    {
                        Name        = "Shivshankar Choudhury",
                        DateOfBirth = new DateTime(1968, 5, 13, 0, 0, 0),
                        Gender      = Gender.Male,
                        Phone       = "2810806979",
                        Email       = "*****@*****.**"
                    },
                    Address = new Address
                    {
                        Street  = "12 Maulana Azad Marg",
                        State   = "New Delhi",
                        Pincode = "110002"
                    }
                }
            };
            personalInfo.Biometrics.Add(new Biometric
            {
                Type     = BiometricType.Minutiae,
                Position = BiometricPosition.LeftIndex,
                Data     = BiometricData
            });

            // Set Device Info
            var deviceContext = new AuthContext
            {
                DeviceInfo = Configuration.Current.DeviceInfo.Create(),
                Info       = new AuthInfo()
            };

            // Encrypt Data
            var sessionKey = new SessionKey(Configuration.Current.UidaiEncryption, false);
            await deviceContext.EncryptAsync(personalInfo, sessionKey);

            #endregion

            #region Device To Agency
            // TODO: Wrap DeviceContext{T} into AUA specific protocol and send it to AUA.
            // On Device Side:
            // var deviceXml = deviceContext.ToXml();
            // var wrapped = WrapIntoAuaProtocol(deviceXml);

            // On Agency Side:
            // var auaXml = UnwrapFromAuaProtocol(wrapped);
            // var auaContext = new AuthContext();
            // auaContext.FromXml(auaXml);
            #endregion

            #region Agency Level

            // Perform Authentication
            var apiClient = new AuthClient
            {
                AgencyInfo = Configuration.Current.AgencyInfo,
                Request    = new AuthRequest(deviceContext)
                {
                    Signer = XmlSignature
                },
                Response = new AuthResponse {
                    Verifier = XmlSignature
                }
            };
            await apiClient.GetResponseAsync();

            Console.WriteLine(string.IsNullOrEmpty(apiClient.Response.ErrorCode)
                ? $"Is the user authentic: {apiClient.Response.IsAuthentic}"
                : $"Error Code: {apiClient.Response.ErrorCode}");

            // Review Error
            apiClient.Response.Info.Decode();
            var mismatch = string.Join(", ", apiClient.Response.Info.GetMismatch());
            if (!string.IsNullOrEmpty(mismatch))
            {
                Console.WriteLine($"Mismatch Attributes: {mismatch}");
            }

            #endregion

            #region Agency To Device
            // TODO: Wrap AuthResponse into AUA specific protocol and send it to device.
            #endregion
        }