├── .gitignore ├── Api ├── Datastore │ └── users.json ├── appsettings.json ├── wwwroot │ └── web.config ├── Models │ ├── User.cs │ └── ApiDbContext.cs ├── Properties │ └── launchSettings.json ├── project.json ├── Api.xproj ├── Auth │ └── JWTAuth.cs ├── Startup.cs └── Controllers │ └── UsersController.cs ├── WpfClient ├── packages.config ├── App.config ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Globals.cs ├── App.xaml ├── App.xaml.cs ├── Models │ └── User.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Pages │ ├── LoginPage.xaml │ ├── RegistrationPage.xaml │ ├── LoginPage.xaml.cs │ ├── DetailsPage.xaml │ ├── RegistrationPage.xaml.cs │ └── DetailsPage.xaml.cs ├── Operations │ └── ApiOperations.cs └── WpfClient.csproj ├── LICENSE ├── Csharp-jwt-authentication-sample.sln └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /Api/Datastore/users.json: -------------------------------------------------------------------------------- 1 | [ ] -------------------------------------------------------------------------------- /WpfClient/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /WpfClient/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Api/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Verbose", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /WpfClient/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /WpfClient/Globals.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | using WpfClient.Models; 8 | 9 | namespace WpfClient 10 | { 11 | class Globals 12 | { 13 | public static User LoggedInUser { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WpfClient/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /WpfClient/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace WpfClient 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Api/wwwroot/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /WpfClient/Models/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace WpfClient.Models 8 | { 9 | class User 10 | { 11 | public int Id { get; set; } 12 | public string Username { get; set; } 13 | public string Firstname { get; set; } 14 | public string Middlename { get; set; } 15 | public string Lastname { get; set; } 16 | public int Age { get; set; } 17 | public string access_token { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Api/Models/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Api.Models 8 | { 9 | public class User 10 | { 11 | public int Id { get; set; } 12 | [Required] 13 | public string Username { get; set; } 14 | [Required] 15 | public string Password { get; set; } 16 | public string Firstname { get; set; } 17 | public string Middlename { get; set; } 18 | public string Lastname { get; set; } 19 | public int Age { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /WpfClient/MainWindow.xaml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Api/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:50369/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "api/values", 15 | "environmentVariables": { 16 | "Hosting:Environment": "Development" 17 | } 18 | }, 19 | "web": { 20 | "commandName": "web", 21 | "environmentVariables": { 22 | "Hosting:Environment": "Development" 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /WpfClient/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace WpfClient 17 | { 18 | /// 19 | /// Interaction logic for MainWindow.xaml 20 | /// 21 | public partial class MainWindow : Window 22 | { 23 | public MainWindow() 24 | { 25 | InitializeComponent(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Api/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "compilationOptions": { 4 | "emitEntryPoint": true 5 | }, 6 | 7 | "dependencies": { 8 | "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final", 9 | "Microsoft.AspNet.Mvc": "6.0.0-rc1-final", 10 | "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final", 11 | "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final", 12 | "Microsoft.Extensions.Configuration.FileProviderExtensions" : "1.0.0-rc1-final", 13 | "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final", 14 | "Microsoft.Extensions.Logging": "1.0.0-rc1-final", 15 | "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final", 16 | "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final", 17 | "Newtonsoft.Json": "8.0.3", 18 | "JWT": "1.3.4" 19 | }, 20 | 21 | "commands": { 22 | "web": "Microsoft.AspNet.Server.Kestrel" 23 | }, 24 | 25 | "frameworks": { 26 | "dnx451": { } 27 | }, 28 | 29 | "exclude": [ 30 | "wwwroot", 31 | "node_modules" 32 | ], 33 | "publishExclude": [ 34 | "**.user", 35 | "**.vspscc" 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /Api/Models/ApiDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | using Newtonsoft.Json; 8 | 9 | namespace Api.Models 10 | { 11 | public class ApiDbContext 12 | { 13 | private string datastore; 14 | 15 | public ApiDbContext() 16 | { 17 | this.datastore = "./Datastore"; 18 | InitializeFieldValues(); 19 | } 20 | 21 | private void InitializeFieldValues() 22 | { 23 | // Get users 24 | string filename = "/users.json"; 25 | string json = File.ReadAllText(this.datastore + filename); 26 | this.Users = JsonConvert.DeserializeObject>(json); 27 | } 28 | 29 | public List Users { get; set; } 30 | 31 | public void SaveChanges() 32 | { 33 | // Save users 34 | string json = JsonConvert.SerializeObject(this.Users); 35 | string filename = "/users.json"; 36 | File.WriteAllText(this.datastore + filename, json); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Api/Api.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | cb06044e-c84b-4163-8f45-c192ffab4f3f 10 | Api 11 | ..\artifacts\obj\$(MSBuildProjectName) 12 | ..\artifacts\bin\$(MSBuildProjectName)\ 13 | 14 | 15 | 2.0 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Prosper Otemuyiwa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /WpfClient/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace WpfClient.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /WpfClient/Pages/LoginPage.xaml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |