Example #1
0
        /// <summary>
        /// Callback that is invoked once the authentication request is processed or expires.
        /// </summary>
        /// <param name="request"></param>
        private static void OnVerificationResponse(AuthResponse request, NtkService boundApi)
        {
            /**
             * 3. ApprovalGranted is a convenience property, but it does not perform
             * signature validation.
             *
             * In a real-world scenario, you could now verify the response payload
             * to be sure of the received data.
             */

            Console.WriteLine("SUCCESS: verification response: {0}", request.ApprovalGranted);
            Console.WriteLine("Storing keytoken {0} for user ID {1}", request.KeyToken, request.UserId);
            userKeyTokens.Add(request.KeyToken, request.UserId);
        }
Example #2
0
        /// <summary>
        /// Callback that is invoked once the API instance is bound to a Notakey application.
        ///
        /// From this point on, you can request authentication for users.
        /// </summary>
        /// <param name="address"></param>
        private static void OnBound(AccessToken token, NtkService boundApi, string userName)
        {
            // store api reference to be used in messaging demo
            ntkApi = boundApi;
            Console.WriteLine("SUCCESS: bound to {0} with token {1}", ntkApi.BoundParams.ApplicationEndpoint.AbsolutePath, token.Token);
            Console.WriteLine("Access token valid until {0} UTC", token.ValidBefore.ToString());
            Console.WriteLine("Requesting verification for user '{0}' ...", userName);

            // Store token for later reuse
            myToken = token;

            /* 2. Now that we are bound to an application,
             * we can invoke PerformFullVerification and other
             * methods.
             *
             * PerformFullVerification will return once the result is known
             * (approved/denied) or the request expires (by default 5 minutes).
             */
            ntkApi
            .PerformFullVerification(userName, "Notakey .NET Demo", "This is an example authentication request sent from the .NET example application", Path.GetRandomFileName())
            .SingleAsync()
            .Finally(() => waitEvent.Set())
            .Subscribe(resp => OnVerificationResponse(resp, boundApi), OnVerificationError);
        }
Example #3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Binding to API ...");

            /**
             * 1. The first task is to bind a SimpleApi instance to an API (endpoint + access_id combination)
             * After the api instance is bound to the remote API, it can be used to perform other operations.
             *
             * NOTE: before you are bound to an application, do not use any other functions!
             */

            // demo
            var api = new NtkService("https://demoapi.notakey.com/api", "235879a9-a3f3-42b4-b13a-4836d0fd3bf8");

            var userName = "******";

            // You can also detect if API is in good shape before requesting anything
            // api
            //     .PerformHealthCheck()
            //     .Subscribe(hc => Console.WriteLine("Health: {0} = {1}",
            //         hc.FirstOrDefault(x => x.Key == "STATUS").Key,
            //         hc.FirstOrDefault(x => x.Key == "STATUS").Value));

            // Bind to API with client ID and secret
            api
            .Bind("469082d815d273fa6c410338f4e6e817a68772ca3766ad4fc3bfb4ae28b72525",
                  "d8281809e82d95d8279448d0f7c3a806691fc307a4bc66018b19ce57b4019cf6",
                  new List <string> {
                "urn:notakey:auth", "urn:notakey:keyservice"
            })
            .SingleAsync()
            .Subscribe(myToken => OnBound(myToken, api, userName), OnBindError);

            waitEvent.WaitOne();

            Console.WriteLine("Finished first authentication request");

            api
            .Bind(myToken)
            .SingleAsync()
            .Subscribe(myToken => OnBound(myToken, api, userName), OnBindError);

            waitEvent.Reset();

            waitEvent.WaitOne();

            Console.WriteLine("Finished second authentication request");

            if (userKeyTokens.Count != 2)
            {
                Console.WriteLine("Some or all key tokens are missing, cannot continue");
                Console.ReadLine();
                return;
            }

            Console.WriteLine("Will perform end-to-end encrypted message demo");


            MessagingTest();

            Console.WriteLine("All operations complete, press any key");
            Console.ReadLine();
        }