Example #1
0
        static async Task <DeviceAuthorizationResponse> RequestAuthorizationAsync()
        {
            var disco = await _cache.GetAsync();

            if (disco.IsError)
            {
                throw new Exception(disco.Error);
            }

            var client   = new HttpClient();
            var response = await client.RequestDeviceAuthorizationAsync(new DeviceAuthorizationRequest
            {
                Address  = disco.DeviceAuthorizationEndpoint,
                ClientId = "device"
            });

            if (response.IsError)
            {
                throw new Exception(response.Error);
            }

            Console.WriteLine($"user code   : {response.UserCode}");
            Console.WriteLine($"device code : {response.DeviceCode}");
            Console.WriteLine($"URL         : {response.VerificationUri}");
            Console.WriteLine($"Complete URL: {response.VerificationUriComplete}");

            Console.WriteLine($"\nPress enter to launch browser ({response.VerificationUri})");
            Console.ReadLine();

            Process.Start(new ProcessStartInfo(response.VerificationUri)
            {
                UseShellExecute = true
            });
            return(response);
        }