From a31ac2bab387bce1ebd20397fee45835e7aa48cd Mon Sep 17 00:00:00 2001 From: Dominick Baier Date: Mon, 13 Feb 2017 11:50:35 +0100 Subject: [PATCH] Update .NET console client to v2 --- .../ConsoleSystemBrowser.csproj | 57 +++++++++---------- .../ConsoleSystemBrowser/Program.cs | 43 +++++++------- .../ConsoleSystemBrowser/packages.config | 51 +++++++++++++---- 3 files changed, 88 insertions(+), 63 deletions(-) diff --git a/ConsoleSystemBrowser/ConsoleSystemBrowser/ConsoleSystemBrowser.csproj b/ConsoleSystemBrowser/ConsoleSystemBrowser/ConsoleSystemBrowser.csproj index 0aeaea7..52bd5b2 100644 --- a/ConsoleSystemBrowser/ConsoleSystemBrowser/ConsoleSystemBrowser.csproj +++ b/ConsoleSystemBrowser/ConsoleSystemBrowser/ConsoleSystemBrowser.csproj @@ -33,63 +33,58 @@ 4 - - ..\packages\IdentityModel.1.13.0\lib\net45\IdentityModel.dll + + ..\packages\IdentityModel.2.5.1\lib\net45\IdentityModel.dll True - - ..\packages\IdentityModel.OidcClient.1.5.1\lib\net45\IdentityModel.OidcClient.dll + + ..\packages\IdentityModel.OidcClient.2.0.0\lib\net452\IdentityModel.OidcClient.dll True - - ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - True - - - ..\packages\PCLCrypto.2.0.147\lib\net45\PCLCrypto.dll + + ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.1.0\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll True - - ..\packages\PInvoke.BCrypt.0.3.2\lib\net40\PInvoke.BCrypt.dll + + ..\packages\Microsoft.Extensions.Logging.1.1.0\lib\netstandard1.1\Microsoft.Extensions.Logging.dll True - - ..\packages\PInvoke.Kernel32.0.3.2\lib\net40\PInvoke.Kernel32.dll + + ..\packages\Microsoft.Extensions.Logging.Abstractions.1.1.0\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll True - - ..\packages\PInvoke.NCrypt.0.3.2\lib\net40\PInvoke.NCrypt.dll + + ..\packages\Microsoft.IdentityModel.Logging.1.1.2\lib\net451\Microsoft.IdentityModel.Logging.dll True - - ..\packages\PInvoke.Windows.Core.0.3.2\lib\portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10\PInvoke.Windows.Core.dll + + ..\packages\Microsoft.IdentityModel.Tokens.5.1.2\lib\net451\Microsoft.IdentityModel.Tokens.dll True - - ..\packages\Serilog.1.5.7\lib\net45\Serilog.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\Serilog.1.5.7\lib\net45\Serilog.FullNetFx.dll + + + + + + ..\packages\System.IdentityModel.Tokens.Jwt.5.1.2\lib\net451\System.IdentityModel.Tokens.Jwt.dll True - - ..\packages\Serilog.Sinks.Literate.1.2.0\lib\net45\Serilog.Sinks.Literate.dll + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll True - - - - - ..\packages\Validation.2.2.8\lib\dotnet\Validation.dll - True - diff --git a/ConsoleSystemBrowser/ConsoleSystemBrowser/Program.cs b/ConsoleSystemBrowser/ConsoleSystemBrowser/Program.cs index 88d38cb..7f3b19a 100644 --- a/ConsoleSystemBrowser/ConsoleSystemBrowser/Program.cs +++ b/ConsoleSystemBrowser/ConsoleSystemBrowser/Program.cs @@ -1,5 +1,4 @@ using IdentityModel.OidcClient; -using Serilog; using System; using System.Diagnostics; using System.Net; @@ -12,12 +11,6 @@ class Program { static void Main(string[] args) { - // setup logging - Log.Logger = new LoggerConfiguration() - .MinimumLevel.Debug() - .WriteTo.LiterateConsole() - .CreateLogger(); - Console.WriteLine("+-----------------------+"); Console.WriteLine("| Sign in with OIDC |"); Console.WriteLine("+-----------------------+"); @@ -43,16 +36,22 @@ private async void SignIn() Console.WriteLine("Listening.."); http.Start(); - var options = new OidcClientOptions( - "https://demo.identityserver.io", - "native", - "secret", - "openid profile api", - redirectUri) + var options = new OidcClientOptions { - UseFormPost = true, - Style = OidcClientOptions.AuthenticationStyle.Hybrid + Authority = "https://demo.identityserver.io", + ClientId = "native.hybrid", + Scope = "openid profile api", + RedirectUri = redirectUri }; + + // "native", + // "secret", + // "openid profile api", + // redirectUri) + //{ + // UseFormPost = true, + // Style = OidcClientOptions.AuthenticationStyle.Hybrid + //}; var client = new OidcClient(options); var state = await client.PrepareLoginAsync(); @@ -80,12 +79,16 @@ private async void SignIn() responseOutput.Close(); Console.WriteLine($"Form Data: {formData}"); - var result = await client.ValidateResponseAsync(formData, state); + var result = await client.ProcessResponseAsync(formData, state); - if (result.Success) + if (result.IsError) + { + Console.WriteLine("\n\nError:\n{0}", result.Error); + } + else { Console.WriteLine("\n\nClaims:"); - foreach (var claim in result.Claims) + foreach (var claim in result.User.Claims) { Console.WriteLine("{0}: {1}", claim.Type, claim.Value); } @@ -98,10 +101,6 @@ private async void SignIn() Console.WriteLine("Refresh token:\n{0}", result.RefreshToken); } } - else - { - Console.WriteLine("\n\nError:\n{0}", result.Error); - } http.Stop(); } diff --git a/ConsoleSystemBrowser/ConsoleSystemBrowser/packages.config b/ConsoleSystemBrowser/ConsoleSystemBrowser/packages.config index 2585895..38e731e 100644 --- a/ConsoleSystemBrowser/ConsoleSystemBrowser/packages.config +++ b/ConsoleSystemBrowser/ConsoleSystemBrowser/packages.config @@ -1,14 +1,45 @@  - - + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file