Exemplo n.º 1
0
        public async Task auth(string username, string message, SezameAuthCallbackType callback)
        {
            var webRequestHandler = new WebRequestHandler();

            webRequestHandler.ClientCertificates.Add(certificate); // X509Certificate
            var invoker = new SezameAuthenticationServiceInvoker(webRequestHandler, true);

            SezameResult response = null;
            var          timeout  = TimeSpan.FromSeconds(60);

            response = await invoker.RequestAuthenticationAsync(username, message, "auth", (int)Math.Ceiling(timeout.TotalMinutes));

            var status = response.GetParameter(SezameResultKey.AuthenticationStatus);

            if (status == "notlinked")
            {
                callback(SezameAuthenticationResultKey.NotPaired);
                return;
            }

            var authId = response.GetParameter(SezameResultKey.Id);

            var result = SezameAuthenticationResultKey.Timedout;

            if (status == "initiated")
            {
                result = await Task.Run <SezameAuthenticationResultKey>(async() =>
                {
                    int sleeptime     = 1000;
                    int loopPassCount = (int)Math.Ceiling(Math.Ceiling((double)timeout.TotalMilliseconds) / sleeptime);
                    while (loopPassCount > 0)
                    {
                        response = await invoker.CheckAuthenticationStatusAsync(authId);
                        status   = response.GetParameter(SezameResultKey.AuthenticationStatus);
                        if (status == "authorized")
                        {
                            return(SezameAuthenticationResultKey.Authenticated);
                        }
                        else if (status == "denied")
                        {
                            return(SezameAuthenticationResultKey.Denied);
                        }
                        loopPassCount--;
                        System.Threading.Thread.Sleep(sleeptime);
                    }
                    return(SezameAuthenticationResultKey.Timedout);
                });
            }

            callback(result);
        }
Exemplo n.º 2
0
        public async Task link(string username, SezameLinkCallbackType callback)
        {
            var webRequestHandler = new WebRequestHandler();

            webRequestHandler.ClientCertificates.Add(certificate); // X509Certificate
            var invoker = new SezameAuthenticationServiceInvoker(webRequestHandler, true);

            var linkResponse = await invoker.LinkAsync(username);

            var id         = linkResponse.GetParameter(SezameResultKey.Id);
            var clientcode = linkResponse.GetParameter(SezameResultKey.ClientCode);

            callback(id, clientcode);
        }