├── .gitattributes ├── .gitignore ├── BlazorAccountsManager ├── Client │ ├── App.razor │ ├── BlazorAccountsManager.Client.csproj │ ├── Helpers │ │ ├── ApiAuthenticationStateProvider.cs │ │ └── ExtensionMethods.cs │ ├── Pages │ │ ├── Admin │ │ │ ├── AccountManager.razor │ │ │ └── AccountManager.razor.cs │ │ ├── Authentication.razor │ │ ├── Counter.razor │ │ ├── FetchData.razor │ │ ├── Index.razor │ │ └── UserPages │ │ │ ├── Login.razor │ │ │ ├── Logout.razor │ │ │ └── Register.razor │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Services │ │ ├── AuthService │ │ │ ├── AuthService.cs │ │ │ └── IAuthService.cs │ │ └── UserAccountManager │ │ │ ├── IUserAccountManager.cs │ │ │ └── UserAccountManager.cs │ ├── Shared │ │ ├── Components │ │ │ ├── ToolTip.razor │ │ │ └── ToolTip.razor.css │ │ ├── LoginDisplay.razor │ │ ├── MainLayout.razor │ │ ├── MainLayout.razor.css │ │ ├── NavMenu.razor │ │ ├── NavMenu.razor.css │ │ ├── RedirectToLogin.razor │ │ └── SurveyPrompt.razor │ ├── _Imports.razor │ └── wwwroot │ │ ├── css │ │ ├── app.css │ │ ├── bootstrap │ │ │ ├── bootstrap.min.css │ │ │ └── bootstrap.min.css.map │ │ └── open-iconic │ │ │ ├── FONT-LICENSE │ │ │ ├── ICON-LICENSE │ │ │ ├── README.md │ │ │ └── font │ │ │ ├── css │ │ │ └── open-iconic-bootstrap.min.css │ │ │ └── fonts │ │ │ ├── open-iconic.eot │ │ │ ├── open-iconic.otf │ │ │ ├── open-iconic.svg │ │ │ ├── open-iconic.ttf │ │ │ └── open-iconic.woff │ │ ├── favicon.ico │ │ ├── icon-192.png │ │ └── index.html ├── Server │ ├── Areas │ │ └── Identity │ │ │ └── Pages │ │ │ └── Shared │ │ │ └── _LoginPartial.cshtml │ ├── BlazorAccountsManager.Server.csproj │ ├── Controllers │ │ ├── AuthController.cs │ │ ├── UserAccountController.cs │ │ └── WeatherForecastController.cs │ ├── Data │ │ └── DataContext.cs │ ├── Pages │ │ ├── Error.cshtml │ │ └── Error.cshtml.cs │ ├── Program.cs │ ├── Properties │ │ ├── launchSettings.json │ │ ├── serviceDependencies.json │ │ └── serviceDependencies.local.json │ ├── Services │ │ ├── AuthService │ │ │ ├── AuthService.cs │ │ │ └── IAuthService.cs │ │ └── UserAccountService │ │ │ ├── IUserAccountService.cs │ │ │ └── UserAccountService.cs │ ├── appsettings.Development.json │ └── appsettings.json └── Shared │ ├── BlazorAccountsManager.Shared.csproj │ ├── Dtos │ ├── LoginDto.cs │ ├── RegisterDto.cs │ └── UserAccountDto.cs │ ├── Enums │ └── Roles.cs │ ├── Helpers │ └── Policies.cs │ ├── Models │ ├── ApplicationUser.cs │ └── ServiceResponse.cs │ └── WeatherForecast.cs ├── BlazorAccountsManagerApp.sln ├── README.md ├── screenshot1.jpg └── screenshot2.jpg /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/App.razor: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | @if (context.User.Identity?.IsAuthenticated != true) 7 | { 8 | 9 | } 10 | else 11 | { 12 |

You are not authorized to access this resource.

13 | } 14 |
15 | 16 |
Authorizing...
17 |
18 |
19 | 20 |
21 | 22 | Not found 23 | 24 |

Sorry, there's nothing at this address.

25 |
26 |
27 |
28 |
-------------------------------------------------------------------------------- /BlazorAccountsManager/Client/BlazorAccountsManager.Client.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Helpers/ApiAuthenticationStateProvider.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components.Authorization; 2 | using System.Net.Http.Headers; 3 | using System.Text.Json; 4 | 5 | namespace BlazorAccountsManager.Client.Helpers 6 | { 7 | public class ApiAuthenticationStateProvider : AuthenticationStateProvider 8 | { 9 | private readonly HttpClient _httpClient; 10 | private readonly ILocalStorageService _localStorage; 11 | 12 | public ApiAuthenticationStateProvider(HttpClient httpClient, ILocalStorageService localStorage) 13 | { 14 | _httpClient = httpClient; 15 | _localStorage = localStorage; 16 | } 17 | 18 | 19 | 20 | public override async Task GetAuthenticationStateAsync() 21 | { 22 | var savedToken = await _localStorage.GetItemAsync("authToken"); 23 | 24 | if (string.IsNullOrWhiteSpace(savedToken)) 25 | { 26 | return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())); 27 | } 28 | 29 | _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", savedToken); 30 | 31 | return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity(ParseClaimsFromJwt(savedToken), "jwt"))); 32 | } //GetAuthenticationStateAsync 33 | 34 | 35 | 36 | 37 | public void MarkUserAsAuthenticated(string token) 38 | { 39 | var authenticatedUser = new ClaimsPrincipal(new ClaimsIdentity(ParseClaimsFromJwt(token), "jwt")); 40 | var authState = Task.FromResult(new AuthenticationState(authenticatedUser)); 41 | NotifyAuthenticationStateChanged(authState); 42 | } //MarkUserAsAuthenticated 43 | 44 | 45 | 46 | public void MarkUserAsLoggedOut() 47 | { 48 | var anonymousUser = new ClaimsPrincipal(new ClaimsIdentity()); 49 | var authState = Task.FromResult(new AuthenticationState(anonymousUser)); 50 | NotifyAuthenticationStateChanged(authState); 51 | } //MarkUserAsLoggedOut 52 | 53 | 54 | 55 | private IEnumerable ParseClaimsFromJwt(string jwt) 56 | { 57 | var claims = new List(); 58 | var payload = jwt.Split('.')[1]; 59 | var jsonBytes = ParseBase64WithoutPadding(payload); 60 | var keyValuePairs = JsonSerializer.Deserialize>(jsonBytes); 61 | 62 | keyValuePairs.TryGetValue(ClaimTypes.Role, out object roles); 63 | 64 | if (roles != null) 65 | { 66 | if (roles.ToString().Trim().StartsWith("[")) 67 | { 68 | var parsedRoles = JsonSerializer.Deserialize(roles.ToString()); 69 | 70 | foreach (var parsedRole in parsedRoles) 71 | { 72 | claims.Add(new Claim(ClaimTypes.Role, parsedRole)); 73 | } 74 | } 75 | else 76 | { 77 | claims.Add(new Claim(ClaimTypes.Role, roles.ToString())); 78 | } 79 | 80 | keyValuePairs.Remove(ClaimTypes.Role); 81 | } 82 | 83 | claims.AddRange(keyValuePairs.Select(kvp => new Claim(kvp.Key, kvp.Value.ToString()))); 84 | 85 | return claims; 86 | } //ParseClaimsFromJwt 87 | 88 | 89 | 90 | 91 | private static byte[] ParseBase64WithoutPadding(string base64) 92 | { 93 | switch (base64.Length % 4) 94 | { 95 | case 2: base64 += "=="; break; 96 | case 3: base64 += "="; break; 97 | } 98 | return Convert.FromBase64String(base64); 99 | } //ParseBase64WithoutPadding 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Helpers/ExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | using System.Collections.Specialized; 3 | using System.Web; 4 | 5 | namespace BlazorAccountsManager.Client.Helpers 6 | { 7 | public static class ExtensionMethods 8 | { 9 | public static NameValueCollection QueryString(this NavigationManager navigationManager) 10 | { 11 | return HttpUtility.ParseQueryString(new Uri(navigationManager.Uri).Query); 12 | } 13 | 14 | public static string QueryString(this NavigationManager navigationManager, string key) 15 | { 16 | return navigationManager.QueryString()[key]; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Pages/Admin/AccountManager.razor: -------------------------------------------------------------------------------- 1 | @page "/admin/account-manager" 2 | @using Microsoft.AspNetCore.Authorization 3 | @attribute [Authorize(Policy = "IsSuperAdmin")] 4 | 5 |

Account Manager

6 | 7 | @if (showError) 8 | { 9 | 12 | } 13 | 14 | @if (showInfo) 15 | { 16 | 19 | } 20 | 21 | 22 | 23 | @if (UserAccountManager.UserList == null) 24 | { 25 | Loading... 26 | } 27 | else 28 | { 29 | if (!isInAccountEditMode) { 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | @foreach(var user in UserAccountManager.UserList) { 44 | 45 | 57 | 62 | 63 | 64 | 65 | 72 | 81 | 82 | } 83 | 84 | 85 | 86 | 91 | 92 | 93 |
UserIdUsernameEmailRole
46 | @if (user.IsSuperUser) 47 | { 48 | 49 | 50 | 51 | } 52 | else 53 | { 54 | 55 | } 56 | 58 | 59 | @user.UserId.Substring(0, 5) ... 60 | 61 | @user.UserName@user.Email@user.UserRole 66 | 67 | 70 | 71 | 73 | 74 | 79 | 80 |
87 | 90 |
94 | } 95 | if (isInAccountEditMode) 96 | { 97 |
98 |
Edit/Add User
99 |
100 | 101 | 102 |
103 |
104 | 105 | 106 | 107 |
108 |
109 | 110 | 111 | 112 |
113 |
114 | 115 | 116 |
117 |
118 |
119 |
120 | 121 | 122 | 123 |
124 |
125 | 126 | 127 | 128 |
129 |
130 | @if (string.IsNullOrEmpty(user.UserId)) 131 | { 132 |
133 |
134 | 135 | 136 | 137 |
138 |
139 | 140 | 141 | 142 |
143 |
144 | } 145 | 146 |
147 | 148 | 149 | @foreach (var role in Enum.GetValues(typeof(Roles))) 150 | { 151 | 152 | } 153 | 154 |
155 | 156 |
157 |
158 | 159 | 160 |
161 |
162 | 163 |
164 |
165 | 168 |
169 |
170 | 173 |
174 |
175 |
176 |
177 |
178 | } 179 | 180 | } 181 |
182 | 183 |

You're not authorized to view this page.

184 |
185 |
-------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Pages/Admin/AccountManager.razor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | 3 | namespace BlazorAccountsManager.Client.Pages.Admin 4 | { 5 | public partial class AccountManager 6 | { 7 | [Inject] IUserAccountManager UserAccountManager { get; set; } 8 | 9 | bool showError = false; 10 | bool showInfo = false; 11 | string message = string.Empty; 12 | bool isInAccountEditMode = false; 13 | UserAccountDto user = new UserAccountDto(); 14 | 15 | 16 | protected override async Task OnInitializedAsync() 17 | { 18 | await UserAccountManager.GetUserAccounts(); 19 | } //OnInitializedAsync 20 | 21 | 22 | private async Task AddUserAccount() 23 | { 24 | user = new UserAccountDto(); 25 | isInAccountEditMode = true; 26 | } //AddUserAccount 27 | 28 | 29 | private async Task EditUser(string userId) 30 | { 31 | var result = await UserAccountManager.GetUserDetails(userId); 32 | if (result.Success) 33 | user = result.Data; 34 | 35 | isInAccountEditMode = true; 36 | } //EditUser 37 | 38 | 39 | private void CancelEdit() 40 | { 41 | user = new UserAccountDto(); 42 | isInAccountEditMode = false; 43 | } //CancelEdit 44 | 45 | 46 | private async Task UpdateUserAccount() 47 | { 48 | showError = false; 49 | showInfo = false; 50 | message = string.Empty; 51 | if (!string.IsNullOrEmpty(user.UserId)) 52 | { 53 | var result = await UserAccountManager.UpdateUserAccount(user); 54 | 55 | if (result.Success) 56 | { 57 | showInfo = true; 58 | message = result.Message; 59 | } 60 | else 61 | { 62 | showError = true; 63 | message = result.Message; 64 | } 65 | } 66 | else 67 | { 68 | var result = await UserAccountManager.CreateNewUserAccount(user); 69 | if (result.Success) 70 | { 71 | showInfo = true; 72 | message = result.Message; 73 | } 74 | else 75 | { 76 | showError = true; 77 | message = result.Message; 78 | } 79 | } 80 | 81 | user = new UserAccountDto(); 82 | await UserAccountManager.GetUserAccounts(); 83 | isInAccountEditMode = false; 84 | } //UpdateUserAccount 85 | 86 | 87 | private async Task DeleteUser(string userId) 88 | { 89 | var result = await UserAccountManager.DeleteUserAccount(userId); 90 | if (result.Success) 91 | { 92 | showInfo = true; 93 | message = result.Message; 94 | await UserAccountManager.GetUserAccounts(); 95 | } 96 | else 97 | { 98 | showError = true; 99 | message = result.Message; 100 | } 101 | } //DeleteUser 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Pages/Authentication.razor: -------------------------------------------------------------------------------- 1 | @page "/authentication/{action}" 2 | @using Microsoft.AspNetCore.Components.WebAssembly.Authentication 3 | 4 | 5 | @code{ 6 | [Parameter] public string? Action { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Pages/Counter.razor: -------------------------------------------------------------------------------- 1 | @page "/counter" 2 | 3 | Counter 4 | 5 |

Counter

6 | 7 |

Current count: @currentCount

8 | 9 | 10 | 11 | @code { 12 | private int currentCount = 0; 13 | 14 | private void IncrementCount() 15 | { 16 | currentCount++; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Pages/FetchData.razor: -------------------------------------------------------------------------------- 1 | @page "/fetchdata" 2 | @using Microsoft.AspNetCore.Authorization 3 | @using Microsoft.AspNetCore.Components.WebAssembly.Authentication 4 | @using BlazorAccountsManager.Shared 5 | @attribute [Authorize] 6 | @inject HttpClient Http 7 | 8 | Weather forecast 9 | 10 |

Weather forecast

11 | 12 |

This component demonstrates fetching data from the server.

13 | 14 | @if (forecasts == null) 15 | { 16 |

Loading...

17 | } 18 | else 19 | { 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | @foreach (var forecast in forecasts) 31 | { 32 | 33 | 34 | 35 | 36 | 37 | 38 | } 39 | 40 |
DateTemp. (C)Temp. (F)Summary
@forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
41 | } 42 | 43 | @code { 44 | private WeatherForecast[]? forecasts; 45 | 46 | protected override async Task OnInitializedAsync() 47 | { 48 | try 49 | { 50 | forecasts = await Http.GetFromJsonAsync("WeatherForecast"); 51 | } 52 | catch (AccessTokenNotAvailableException exception) 53 | { 54 | exception.Redirect(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Pages/Index.razor: -------------------------------------------------------------------------------- 1 | @page "/" 2 | 3 | Index 4 | 5 |

Hello, world!

6 | 7 | Welcome to your new app. 8 | 9 | 10 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Pages/UserPages/Login.razor: -------------------------------------------------------------------------------- 1 | @page "/login" 2 | @inject IAuthService AuthService 3 | @inject NavigationManager NavManager 4 | 5 | Login 6 | 7 | @if (ShowErrors) 8 | { 9 | 12 | } 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 |
22 |
23 | 24 | 25 | 26 |
27 | 28 |
29 | 30 | @code { 31 | private LoginDto loginDto = new LoginDto(); 32 | private bool ShowErrors; 33 | private string Error = ""; 34 | bool isShow; 35 | 36 | private async Task HandleLogin() { 37 | ShowErrors = false; 38 | 39 | var result = await AuthService.Login(loginDto); 40 | 41 | if (result.Success) 42 | { 43 | var returnUrl = NavManager.QueryString("returnUrl") ?? "/"; 44 | NavManager.NavigateTo(returnUrl); 45 | } 46 | else 47 | { 48 | ShowErrors = true; 49 | Error = result.Message; 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Pages/UserPages/Logout.razor: -------------------------------------------------------------------------------- 1 | @page "/logout" 2 | @inject IAuthService AuthService 3 | @inject NavigationManager NavManager 4 | 5 | Logout 6 | 7 | @code { 8 | protected override async Task OnInitializedAsync() 9 | { 10 | await AuthService.Logout(); 11 | NavManager.NavigateTo("/"); 12 | } 13 | } -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Pages/UserPages/Register.razor: -------------------------------------------------------------------------------- 1 | @page "/register" 2 | @inject IAuthService AuthService 3 | @inject NavigationManager NavigationManager 4 | 5 |

Register

6 | 7 | 8 | 9 |
10 |
11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 |
20 |
21 |
22 | 23 | 24 | 25 |
26 | 27 |
28 | 29 | 30 | 31 |
32 | 33 |
34 |
35 | 36 | 37 | 38 |
39 |
40 | 41 | 42 | 43 |
44 |
45 | 46 | 47 | 48 | 49 |
50 | @message 51 |
52 |
53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | @code { 62 | RegisterDto user = new RegisterDto(); 63 | string message = string.Empty; 64 | string messageCssClass = string.Empty; 65 | 66 | async Task HandleRegistration() 67 | { 68 | var result = await AuthService.Register(user); 69 | message = result.Message; 70 | if (result.Success) 71 | NavigationManager.NavigateTo("/login"); 72 | else 73 | messageCssClass = "text-danger"; 74 | } 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | } 92 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Program.cs: -------------------------------------------------------------------------------- 1 | global using BlazorAccountsManager.Client; 2 | global using BlazorAccountsManager.Client.Helpers; 3 | global using BlazorAccountsManager.Client.Services.AuthService; 4 | global using BlazorAccountsManager.Client.Services.UserAccountManager; 5 | global using BlazorAccountsManager.Shared.Helpers; 6 | global using BlazorAccountsManager.Shared.Models; 7 | global using BlazorAccountsManager.Shared.Dtos; 8 | global using BlazorAccountsManager.Shared.Enums; 9 | global using Blazored.LocalStorage; 10 | global using System.Net.Http.Json; 11 | global using System.Security.Claims; 12 | 13 | using Microsoft.AspNetCore.Components.Authorization; 14 | using Microsoft.AspNetCore.Components.Web; 15 | using Microsoft.AspNetCore.Components.WebAssembly.Hosting; 16 | 17 | 18 | var builder = WebAssemblyHostBuilder.CreateDefault(args); 19 | builder.RootComponents.Add("#app"); 20 | builder.RootComponents.Add("head::after"); 21 | 22 | builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); 23 | 24 | builder.Services.AddScoped(); 25 | builder.Services.AddScoped(); 26 | 27 | 28 | builder.Services.AddBlazoredLocalStorage(); 29 | builder.Services.AddAuthorizationCore(config => 30 | { 31 | config.AddPolicy(Policies.IsSuperAdmin, Policies.IsSuperAdminPolicy()); 32 | config.AddPolicy(Policies.IsAdmin, Policies.IsAdminPolicy()); 33 | config.AddPolicy(Policies.IsUser, Policies.IsUserPolicy()); 34 | }); 35 | builder.Services.AddScoped(); 36 | 37 | await builder.Build().RunAsync(); 38 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:13686", 7 | "sslPort": 44319 8 | } 9 | }, 10 | "profiles": { 11 | "BlazorAccountsManager": { 12 | "commandName": "Project", 13 | "dotnetRunMessages": true, 14 | "launchBrowser": true, 15 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 16 | "applicationUrl": "https://localhost:7058;http://localhost:5058", 17 | "environmentVariables": { 18 | "ASPNETCORE_ENVIRONMENT": "Development" 19 | } 20 | }, 21 | "IIS Express": { 22 | "commandName": "IISExpress", 23 | "launchBrowser": true, 24 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Services/AuthService/AuthService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components.Authorization; 2 | using System.Net.Http.Headers; 3 | 4 | namespace BlazorAccountsManager.Client.Services.AuthService 5 | { 6 | public class AuthService : IAuthService 7 | { 8 | private readonly HttpClient _httpClient; 9 | private readonly AuthenticationStateProvider _authenticationStateProvider; 10 | private readonly ILocalStorageService _localStorage; 11 | private readonly AuthenticationStateProvider _authStateProvider; 12 | 13 | public AuthService(HttpClient httpClient, 14 | AuthenticationStateProvider authenticationStateProvider, 15 | ILocalStorageService localStorage, 16 | AuthenticationStateProvider authStateProvider) 17 | { 18 | _httpClient = httpClient; 19 | _authenticationStateProvider = authenticationStateProvider; 20 | _localStorage = localStorage; 21 | _authStateProvider = authStateProvider; 22 | } 23 | 24 | 25 | public async Task> Login(LoginDto loginDto) 26 | { 27 | var response = await _httpClient.PostAsJsonAsync("api/auth/Login", loginDto); 28 | var result = await response.Content.ReadFromJsonAsync>(); 29 | if (result.Success) 30 | { 31 | await _localStorage.SetItemAsync("authToken", result.Data); 32 | ((ApiAuthenticationStateProvider)_authenticationStateProvider).MarkUserAsAuthenticated(result.Data); 33 | _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", result.Data); 34 | return result; 35 | } 36 | return result; 37 | } //Login 38 | 39 | 40 | public async Task> Register(RegisterDto registerDto) 41 | { 42 | var response = await _httpClient.PostAsJsonAsync("api/auth/Register", registerDto); 43 | var result = await response.Content.ReadFromJsonAsync>(); 44 | return result; 45 | } 46 | 47 | 48 | public async Task IsUserAuthenticated() 49 | { 50 | return (await _authStateProvider.GetAuthenticationStateAsync()).User.Identity.IsAuthenticated; 51 | } //IsUserAuthenticated 52 | 53 | 54 | public async Task Logout() 55 | { 56 | await _localStorage.RemoveItemAsync("authToken"); 57 | ((ApiAuthenticationStateProvider)_authenticationStateProvider).MarkUserAsLoggedOut(); 58 | _httpClient.DefaultRequestHeaders.Authorization = null; 59 | } //Logout 60 | 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Services/AuthService/IAuthService.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorAccountsManager.Client.Services.AuthService 2 | { 3 | public interface IAuthService 4 | { 5 | Task> Login(LoginDto loginDto); 6 | Task> Register(RegisterDto registerDto); 7 | Task Logout(); 8 | Task IsUserAuthenticated(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Services/UserAccountManager/IUserAccountManager.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorAccountsManager.Client.Services.UserAccountManager 2 | { 3 | public interface IUserAccountManager 4 | { 5 | event Action OnChange; 6 | List UserList { get; set; } 7 | Task GetUserAccounts(); 8 | Task> GetUserDetails(string userId); 9 | Task> CreateNewUserAccount(UserAccountDto userAccount); 10 | Task> UpdateUserAccount(UserAccountDto userAccount); 11 | Task> DeleteUserAccount(string userId); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Services/UserAccountManager/UserAccountManager.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorAccountsManager.Client.Services.UserAccountManager 2 | { 3 | public class UserAccountManager : IUserAccountManager 4 | { 5 | private readonly HttpClient _http; 6 | public UserAccountManager(HttpClient http) 7 | { 8 | _http = http; 9 | } 10 | 11 | 12 | public event Action OnChange; 13 | 14 | 15 | public List UserList { get; set; } = new List(); 16 | 17 | 18 | 19 | public async Task GetUserAccounts() 20 | { 21 | var response = await _http.GetFromJsonAsync>>("api/UserAccount/GetUserAccounts"); 22 | 23 | if (response != null && response.Data != null) 24 | UserList = response.Data; 25 | } //GetUserAccounts 26 | 27 | 28 | 29 | public async Task> GetUserDetails(string userId) 30 | { 31 | var response = await _http.GetFromJsonAsync>($"api/UserAccount/GetUserDetails/{userId}"); 32 | return response; 33 | } //GetUserAccount 34 | 35 | 36 | 37 | 38 | 39 | public async Task> CreateNewUserAccount(UserAccountDto userAccount) 40 | { 41 | var response = await _http.PostAsJsonAsync("api/auth/CreateUserAccount", userAccount); 42 | var result = await response.Content.ReadFromJsonAsync>(); 43 | return result; 44 | } 45 | 46 | 47 | public async Task> UpdateUserAccount(UserAccountDto userAccount) 48 | { 49 | var response = await _http.PostAsJsonAsync("api/auth/UpdateUserAccount", userAccount); 50 | var result = await response.Content.ReadFromJsonAsync>(); 51 | return result; 52 | } //UpdateUserAccount 53 | 54 | 55 | public async Task> DeleteUserAccount(string userId) 56 | { 57 | var response = await _http.DeleteAsync($"api/auth/DeleteUserAccount/{userId}"); 58 | var result = await response.Content.ReadFromJsonAsync>(); 59 | return result; 60 | } //DeleteUserAccount 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Shared/Components/ToolTip.razor: -------------------------------------------------------------------------------- 1 | 
2 | @Text 3 | @ChildContent 4 |
5 | 6 | @code { 7 | [Parameter] public RenderFragment? ChildContent { get; set; } 8 | [Parameter] public string Text { get; set; } = string.Empty; 9 | } -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Shared/Components/ToolTip.razor.css: -------------------------------------------------------------------------------- 1 | .tooltip-wrapper { 2 | position: relative; 3 | display: inline-block; 4 | cursor: help; 5 | } 6 | 7 | .tooltip-wrapper span { 8 | visibility: hidden; 9 | position: absolute; 10 | width: 120px; 11 | bottom: 100%; 12 | left: 50%; 13 | margin-left: -60px; 14 | background-color: #363636; 15 | color: #fff; 16 | text-align: center; 17 | padding: 5px 0; 18 | border-radius: 6px; 19 | z-index: 1; 20 | } 21 | 22 | .tooltip-wrapper span::after { 23 | content: ""; 24 | position: absolute; 25 | top: 100%; 26 | left: 50%; 27 | margin-left: -5px; 28 | border-width: 5px; 29 | border-style: solid; 30 | border-color: #555 transparent transparent transparent; 31 | } 32 | 33 | .tooltip-wrapper:hover span { 34 | visibility: visible; 35 | } 36 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Shared/LoginDisplay.razor: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Components.Authorization 2 | @using Microsoft.AspNetCore.Components.WebAssembly.Authentication 3 | @inject IAuthService AuthService 4 | 5 | 6 | 7 | Hello, @context.User.Identity?.Name! 8 | Log out 9 | 10 | 11 | Register 12 | Log in 13 | 14 | 15 | 16 | @code{ 17 | 18 | } 19 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | 3 |
4 | 7 | 8 |
9 |
10 | 11 |
12 | 13 |
14 | @Body 15 |
16 |
17 |
18 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Shared/MainLayout.razor.css: -------------------------------------------------------------------------------- 1 | .page { 2 | position: relative; 3 | display: flex; 4 | flex-direction: column; 5 | } 6 | 7 | main { 8 | flex: 1; 9 | } 10 | 11 | .sidebar { 12 | background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); 13 | } 14 | 15 | .top-row { 16 | background-color: #f7f7f7; 17 | border-bottom: 1px solid #d6d5d5; 18 | justify-content: flex-end; 19 | height: 3.5rem; 20 | display: flex; 21 | align-items: center; 22 | } 23 | 24 | .top-row ::deep a, .top-row ::deep .btn-link { 25 | white-space: nowrap; 26 | margin-left: 1.5rem; 27 | text-decoration: none; 28 | } 29 | 30 | .top-row ::deep a:hover, .top-row ::deep .btn-link:hover { 31 | text-decoration: underline; 32 | } 33 | 34 | .top-row ::deep a:first-child { 35 | overflow: hidden; 36 | text-overflow: ellipsis; 37 | } 38 | 39 | @media (max-width: 640.98px) { 40 | .top-row:not(.auth) { 41 | display: none; 42 | } 43 | 44 | .top-row.auth { 45 | justify-content: space-between; 46 | } 47 | 48 | .top-row ::deep a, .top-row ::deep .btn-link { 49 | margin-left: 0; 50 | } 51 | } 52 | 53 | @media (min-width: 641px) { 54 | .page { 55 | flex-direction: row; 56 | } 57 | 58 | .sidebar { 59 | width: 250px; 60 | height: 100vh; 61 | position: sticky; 62 | top: 0; 63 | } 64 | 65 | .top-row { 66 | position: sticky; 67 | top: 0; 68 | z-index: 1; 69 | } 70 | 71 | .top-row.auth ::deep a:first-child { 72 | flex: 1; 73 | text-align: right; 74 | width: 0; 75 | } 76 | 77 | .top-row, article { 78 | padding-left: 2rem !important; 79 | padding-right: 1.5rem !important; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Shared/NavMenu.razor: -------------------------------------------------------------------------------- 1 |  9 | 10 |
11 | 43 |
44 | 45 | @code { 46 | private bool collapseNavMenu = true; 47 | 48 | private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null; 49 | 50 | private void ToggleNavMenu() 51 | { 52 | collapseNavMenu = !collapseNavMenu; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Shared/NavMenu.razor.css: -------------------------------------------------------------------------------- 1 | .navbar-toggler { 2 | background-color: rgba(255, 255, 255, 0.1); 3 | } 4 | 5 | .top-row { 6 | height: 3.5rem; 7 | background-color: rgba(0,0,0,0.4); 8 | } 9 | 10 | .navbar-brand { 11 | font-size: 1.1rem; 12 | } 13 | 14 | .oi { 15 | width: 2rem; 16 | font-size: 1.1rem; 17 | vertical-align: text-top; 18 | top: -2px; 19 | } 20 | 21 | .nav-item { 22 | font-size: 0.9rem; 23 | padding-bottom: 0.5rem; 24 | } 25 | 26 | .nav-item:first-of-type { 27 | padding-top: 1rem; 28 | } 29 | 30 | .nav-item:last-of-type { 31 | padding-bottom: 1rem; 32 | } 33 | 34 | .nav-item ::deep a { 35 | color: #d7d7d7; 36 | border-radius: 4px; 37 | height: 3rem; 38 | display: flex; 39 | align-items: center; 40 | line-height: 3rem; 41 | } 42 | 43 | .nav-item ::deep a.active { 44 | background-color: rgba(255,255,255,0.25); 45 | color: white; 46 | } 47 | 48 | .nav-item ::deep a:hover { 49 | background-color: rgba(255,255,255,0.1); 50 | color: white; 51 | } 52 | 53 | @media (min-width: 641px) { 54 | .navbar-toggler { 55 | display: none; 56 | } 57 | 58 | .collapse { 59 | /* Never collapse the sidebar for wide screens */ 60 | display: block; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Shared/RedirectToLogin.razor: -------------------------------------------------------------------------------- 1 | @inject NavigationManager Navigation 2 | 3 | @code { 4 | protected override void OnInitialized() 5 | { 6 | Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/Shared/SurveyPrompt.razor: -------------------------------------------------------------------------------- 1 | 
2 | 3 | @Title 4 | 5 | 6 | Please take our 7 | brief survey 8 | 9 | and tell us what you think. 10 |
11 | 12 | @code { 13 | // Demonstrates how a parent component can supply parameters 14 | [Parameter] 15 | public string? Title { get; set; } 16 | } 17 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using System.Net.Http.Json 3 | @using Microsoft.AspNetCore.Components.Authorization 4 | @using Microsoft.AspNetCore.Components.Forms 5 | @using Microsoft.AspNetCore.Components.Routing 6 | @using Microsoft.AspNetCore.Components.Web 7 | @using Microsoft.AspNetCore.Components.Web.Virtualization 8 | @using Microsoft.AspNetCore.Components.WebAssembly.Http 9 | @using Microsoft.JSInterop 10 | @using Blazored.LocalStorage 11 | @using BlazorAccountsManager.Client 12 | @using BlazorAccountsManager.Client.Shared 13 | @using BlazorAccountsManager.Client.Shared.Components 14 | @using BlazorAccountsManager.Client.Services.AuthService 15 | @using BlazorAccountsManager.Client.Services.UserAccountManager; -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/wwwroot/css/app.css: -------------------------------------------------------------------------------- 1 | @import url('open-iconic/font/css/open-iconic-bootstrap.min.css'); 2 | 3 | html, body { 4 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 5 | } 6 | 7 | h1:focus { 8 | outline: none; 9 | } 10 | 11 | a, .btn-link { 12 | color: #0071c1; 13 | } 14 | 15 | .btn-primary { 16 | color: #fff; 17 | background-color: #1b6ec2; 18 | border-color: #1861ac; 19 | } 20 | 21 | .content { 22 | padding-top: 1.1rem; 23 | } 24 | 25 | .valid.modified:not([type=checkbox]) { 26 | outline: 1px solid #26b050; 27 | } 28 | 29 | .invalid { 30 | outline: 1px solid red; 31 | } 32 | 33 | .validation-message { 34 | color: red; 35 | } 36 | 37 | #blazor-error-ui { 38 | background: lightyellow; 39 | bottom: 0; 40 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); 41 | display: none; 42 | left: 0; 43 | padding: 0.6rem 1.25rem 0.7rem 1.25rem; 44 | position: fixed; 45 | width: 100%; 46 | z-index: 1000; 47 | } 48 | 49 | #blazor-error-ui .dismiss { 50 | cursor: pointer; 51 | position: absolute; 52 | right: 0.75rem; 53 | top: 0.5rem; 54 | } 55 | 56 | .blazor-error-boundary { 57 | background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121; 58 | padding: 1rem 1rem 1rem 3.7rem; 59 | color: white; 60 | } 61 | 62 | .blazor-error-boundary::after { 63 | content: "An error has occurred." 64 | } 65 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/wwwroot/css/open-iconic/FONT-LICENSE: -------------------------------------------------------------------------------- 1 | SIL OPEN FONT LICENSE Version 1.1 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | PREAMBLE 6 | The goals of the Open Font License (OFL) are to stimulate worldwide 7 | development of collaborative font projects, to support the font creation 8 | efforts of academic and linguistic communities, and to provide a free and 9 | open framework in which fonts may be shared and improved in partnership 10 | with others. 11 | 12 | The OFL allows the licensed fonts to be used, studied, modified and 13 | redistributed freely as long as they are not sold by themselves. The 14 | fonts, including any derivative works, can be bundled, embedded, 15 | redistributed and/or sold with any software provided that any reserved 16 | names are not used by derivative works. The fonts and derivatives, 17 | however, cannot be released under any other type of license. The 18 | requirement for fonts to remain under this license does not apply 19 | to any document created using the fonts or their derivatives. 20 | 21 | DEFINITIONS 22 | "Font Software" refers to the set of files released by the Copyright 23 | Holder(s) under this license and clearly marked as such. This may 24 | include source files, build scripts and documentation. 25 | 26 | "Reserved Font Name" refers to any names specified as such after the 27 | copyright statement(s). 28 | 29 | "Original Version" refers to the collection of Font Software components as 30 | distributed by the Copyright Holder(s). 31 | 32 | "Modified Version" refers to any derivative made by adding to, deleting, 33 | or substituting -- in part or in whole -- any of the components of the 34 | Original Version, by changing formats or by porting the Font Software to a 35 | new environment. 36 | 37 | "Author" refers to any designer, engineer, programmer, technical 38 | writer or other person who contributed to the Font Software. 39 | 40 | PERMISSION & CONDITIONS 41 | Permission is hereby granted, free of charge, to any person obtaining 42 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 43 | redistribute, and sell modified and unmodified copies of the Font 44 | Software, subject to the following conditions: 45 | 46 | 1) Neither the Font Software nor any of its individual components, 47 | in Original or Modified Versions, may be sold by itself. 48 | 49 | 2) Original or Modified Versions of the Font Software may be bundled, 50 | redistributed and/or sold with any software, provided that each copy 51 | contains the above copyright notice and this license. These can be 52 | included either as stand-alone text files, human-readable headers or 53 | in the appropriate machine-readable metadata fields within text or 54 | binary files as long as those fields can be easily viewed by the user. 55 | 56 | 3) No Modified Version of the Font Software may use the Reserved Font 57 | Name(s) unless explicit written permission is granted by the corresponding 58 | Copyright Holder. This restriction only applies to the primary font name as 59 | presented to the users. 60 | 61 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 62 | Software shall not be used to promote, endorse or advertise any 63 | Modified Version, except to acknowledge the contribution(s) of the 64 | Copyright Holder(s) and the Author(s) or with their explicit written 65 | permission. 66 | 67 | 5) The Font Software, modified or unmodified, in part or in whole, 68 | must be distributed entirely under this license, and must not be 69 | distributed under any other license. The requirement for fonts to 70 | remain under this license does not apply to any document created 71 | using the Font Software. 72 | 73 | TERMINATION 74 | This license becomes null and void if any of the above conditions are 75 | not met. 76 | 77 | DISCLAIMER 78 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 81 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 82 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 83 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 84 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 85 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 86 | OTHER DEALINGS IN THE FONT SOFTWARE. 87 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/wwwroot/css/open-iconic/ICON-LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Waybury 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 13 | all 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 NONINFRINGEMENT. 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 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/wwwroot/css/open-iconic/README.md: -------------------------------------------------------------------------------- 1 | [Open Iconic v1.1.1](http://useiconic.com/open) 2 | =========== 3 | 4 | ### Open Iconic is the open source sibling of [Iconic](http://useiconic.com). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](http://useiconic.com/open#icons) 5 | 6 | 7 | 8 | ## What's in Open Iconic? 9 | 10 | * 223 icons designed to be legible down to 8 pixels 11 | * Super-light SVG files - 61.8 for the entire set 12 | * SVG sprite—the modern replacement for icon fonts 13 | * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats 14 | * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats 15 | * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px. 16 | 17 | 18 | ## Getting Started 19 | 20 | #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](http://useiconic.com/open#icons) and [Reference](http://useiconic.com/open#reference) sections. 21 | 22 | ### General Usage 23 | 24 | #### Using Open Iconic's SVGs 25 | 26 | We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute). 27 | 28 | ``` 29 | icon name 30 | ``` 31 | 32 | #### Using Open Iconic's SVG Sprite 33 | 34 | Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack. 35 | 36 | Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `` *tag and a unique class name for each different icon in the* `` *tag.* 37 | 38 | ``` 39 | 40 | 41 | 42 | ``` 43 | 44 | Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `` tag with equal width and height dimensions. 45 | 46 | ``` 47 | .icon { 48 | width: 16px; 49 | height: 16px; 50 | } 51 | ``` 52 | 53 | Coloring icons is even easier. All you need to do is set the `fill` rule on the `` tag. 54 | 55 | ``` 56 | .icon-account-login { 57 | fill: #f00; 58 | } 59 | ``` 60 | 61 | To learn more about SVG Sprites, read [Chris Coyier's guide](http://css-tricks.com/svg-sprites-use-better-icon-fonts/). 62 | 63 | #### Using Open Iconic's Icon Font... 64 | 65 | 66 | ##### …with Bootstrap 67 | 68 | You can find our Bootstrap stylesheets in `font/css/open-iconic-bootstrap.{css, less, scss, styl}` 69 | 70 | 71 | ``` 72 | 73 | ``` 74 | 75 | 76 | ``` 77 | 78 | ``` 79 | 80 | ##### …with Foundation 81 | 82 | You can find our Foundation stylesheets in `font/css/open-iconic-foundation.{css, less, scss, styl}` 83 | 84 | ``` 85 | 86 | ``` 87 | 88 | 89 | ``` 90 | 91 | ``` 92 | 93 | ##### …on its own 94 | 95 | You can find our default stylesheets in `font/css/open-iconic.{css, less, scss, styl}` 96 | 97 | ``` 98 | 99 | ``` 100 | 101 | ``` 102 | 103 | ``` 104 | 105 | 106 | ## License 107 | 108 | ### Icons 109 | 110 | All code (including SVG markup) is under the [MIT License](http://opensource.org/licenses/MIT). 111 | 112 | ### Fonts 113 | 114 | All fonts are under the [SIL Licensed](http://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web). 115 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css: -------------------------------------------------------------------------------- 1 | @font-face{font-family:Icons;src:url(../fonts/open-iconic.eot);src:url(../fonts/open-iconic.eot?#iconic-sm) format('embedded-opentype'),url(../fonts/open-iconic.woff) format('woff'),url(../fonts/open-iconic.ttf) format('truetype'),url(../fonts/open-iconic.otf) format('opentype'),url(../fonts/open-iconic.svg#iconic-sm) format('svg');font-weight:400;font-style:normal}.oi{position:relative;top:1px;display:inline-block;speak:none;font-family:Icons;font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.oi:empty:before{width:1em;text-align:center;box-sizing:content-box}.oi.oi-align-center:before{text-align:center}.oi.oi-align-left:before{text-align:left}.oi.oi-align-right:before{text-align:right}.oi.oi-flip-horizontal:before{-webkit-transform:scale(-1,1);-ms-transform:scale(-1,1);transform:scale(-1,1)}.oi.oi-flip-vertical:before{-webkit-transform:scale(1,-1);-ms-transform:scale(-1,1);transform:scale(1,-1)}.oi.oi-flip-horizontal-vertical:before{-webkit-transform:scale(-1,-1);-ms-transform:scale(-1,1);transform:scale(-1,-1)}.oi-account-login:before{content:'\e000'}.oi-account-logout:before{content:'\e001'}.oi-action-redo:before{content:'\e002'}.oi-action-undo:before{content:'\e003'}.oi-align-center:before{content:'\e004'}.oi-align-left:before{content:'\e005'}.oi-align-right:before{content:'\e006'}.oi-aperture:before{content:'\e007'}.oi-arrow-bottom:before{content:'\e008'}.oi-arrow-circle-bottom:before{content:'\e009'}.oi-arrow-circle-left:before{content:'\e00a'}.oi-arrow-circle-right:before{content:'\e00b'}.oi-arrow-circle-top:before{content:'\e00c'}.oi-arrow-left:before{content:'\e00d'}.oi-arrow-right:before{content:'\e00e'}.oi-arrow-thick-bottom:before{content:'\e00f'}.oi-arrow-thick-left:before{content:'\e010'}.oi-arrow-thick-right:before{content:'\e011'}.oi-arrow-thick-top:before{content:'\e012'}.oi-arrow-top:before{content:'\e013'}.oi-audio-spectrum:before{content:'\e014'}.oi-audio:before{content:'\e015'}.oi-badge:before{content:'\e016'}.oi-ban:before{content:'\e017'}.oi-bar-chart:before{content:'\e018'}.oi-basket:before{content:'\e019'}.oi-battery-empty:before{content:'\e01a'}.oi-battery-full:before{content:'\e01b'}.oi-beaker:before{content:'\e01c'}.oi-bell:before{content:'\e01d'}.oi-bluetooth:before{content:'\e01e'}.oi-bold:before{content:'\e01f'}.oi-bolt:before{content:'\e020'}.oi-book:before{content:'\e021'}.oi-bookmark:before{content:'\e022'}.oi-box:before{content:'\e023'}.oi-briefcase:before{content:'\e024'}.oi-british-pound:before{content:'\e025'}.oi-browser:before{content:'\e026'}.oi-brush:before{content:'\e027'}.oi-bug:before{content:'\e028'}.oi-bullhorn:before{content:'\e029'}.oi-calculator:before{content:'\e02a'}.oi-calendar:before{content:'\e02b'}.oi-camera-slr:before{content:'\e02c'}.oi-caret-bottom:before{content:'\e02d'}.oi-caret-left:before{content:'\e02e'}.oi-caret-right:before{content:'\e02f'}.oi-caret-top:before{content:'\e030'}.oi-cart:before{content:'\e031'}.oi-chat:before{content:'\e032'}.oi-check:before{content:'\e033'}.oi-chevron-bottom:before{content:'\e034'}.oi-chevron-left:before{content:'\e035'}.oi-chevron-right:before{content:'\e036'}.oi-chevron-top:before{content:'\e037'}.oi-circle-check:before{content:'\e038'}.oi-circle-x:before{content:'\e039'}.oi-clipboard:before{content:'\e03a'}.oi-clock:before{content:'\e03b'}.oi-cloud-download:before{content:'\e03c'}.oi-cloud-upload:before{content:'\e03d'}.oi-cloud:before{content:'\e03e'}.oi-cloudy:before{content:'\e03f'}.oi-code:before{content:'\e040'}.oi-cog:before{content:'\e041'}.oi-collapse-down:before{content:'\e042'}.oi-collapse-left:before{content:'\e043'}.oi-collapse-right:before{content:'\e044'}.oi-collapse-up:before{content:'\e045'}.oi-command:before{content:'\e046'}.oi-comment-square:before{content:'\e047'}.oi-compass:before{content:'\e048'}.oi-contrast:before{content:'\e049'}.oi-copywriting:before{content:'\e04a'}.oi-credit-card:before{content:'\e04b'}.oi-crop:before{content:'\e04c'}.oi-dashboard:before{content:'\e04d'}.oi-data-transfer-download:before{content:'\e04e'}.oi-data-transfer-upload:before{content:'\e04f'}.oi-delete:before{content:'\e050'}.oi-dial:before{content:'\e051'}.oi-document:before{content:'\e052'}.oi-dollar:before{content:'\e053'}.oi-double-quote-sans-left:before{content:'\e054'}.oi-double-quote-sans-right:before{content:'\e055'}.oi-double-quote-serif-left:before{content:'\e056'}.oi-double-quote-serif-right:before{content:'\e057'}.oi-droplet:before{content:'\e058'}.oi-eject:before{content:'\e059'}.oi-elevator:before{content:'\e05a'}.oi-ellipses:before{content:'\e05b'}.oi-envelope-closed:before{content:'\e05c'}.oi-envelope-open:before{content:'\e05d'}.oi-euro:before{content:'\e05e'}.oi-excerpt:before{content:'\e05f'}.oi-expand-down:before{content:'\e060'}.oi-expand-left:before{content:'\e061'}.oi-expand-right:before{content:'\e062'}.oi-expand-up:before{content:'\e063'}.oi-external-link:before{content:'\e064'}.oi-eye:before{content:'\e065'}.oi-eyedropper:before{content:'\e066'}.oi-file:before{content:'\e067'}.oi-fire:before{content:'\e068'}.oi-flag:before{content:'\e069'}.oi-flash:before{content:'\e06a'}.oi-folder:before{content:'\e06b'}.oi-fork:before{content:'\e06c'}.oi-fullscreen-enter:before{content:'\e06d'}.oi-fullscreen-exit:before{content:'\e06e'}.oi-globe:before{content:'\e06f'}.oi-graph:before{content:'\e070'}.oi-grid-four-up:before{content:'\e071'}.oi-grid-three-up:before{content:'\e072'}.oi-grid-two-up:before{content:'\e073'}.oi-hard-drive:before{content:'\e074'}.oi-header:before{content:'\e075'}.oi-headphones:before{content:'\e076'}.oi-heart:before{content:'\e077'}.oi-home:before{content:'\e078'}.oi-image:before{content:'\e079'}.oi-inbox:before{content:'\e07a'}.oi-infinity:before{content:'\e07b'}.oi-info:before{content:'\e07c'}.oi-italic:before{content:'\e07d'}.oi-justify-center:before{content:'\e07e'}.oi-justify-left:before{content:'\e07f'}.oi-justify-right:before{content:'\e080'}.oi-key:before{content:'\e081'}.oi-laptop:before{content:'\e082'}.oi-layers:before{content:'\e083'}.oi-lightbulb:before{content:'\e084'}.oi-link-broken:before{content:'\e085'}.oi-link-intact:before{content:'\e086'}.oi-list-rich:before{content:'\e087'}.oi-list:before{content:'\e088'}.oi-location:before{content:'\e089'}.oi-lock-locked:before{content:'\e08a'}.oi-lock-unlocked:before{content:'\e08b'}.oi-loop-circular:before{content:'\e08c'}.oi-loop-square:before{content:'\e08d'}.oi-loop:before{content:'\e08e'}.oi-magnifying-glass:before{content:'\e08f'}.oi-map-marker:before{content:'\e090'}.oi-map:before{content:'\e091'}.oi-media-pause:before{content:'\e092'}.oi-media-play:before{content:'\e093'}.oi-media-record:before{content:'\e094'}.oi-media-skip-backward:before{content:'\e095'}.oi-media-skip-forward:before{content:'\e096'}.oi-media-step-backward:before{content:'\e097'}.oi-media-step-forward:before{content:'\e098'}.oi-media-stop:before{content:'\e099'}.oi-medical-cross:before{content:'\e09a'}.oi-menu:before{content:'\e09b'}.oi-microphone:before{content:'\e09c'}.oi-minus:before{content:'\e09d'}.oi-monitor:before{content:'\e09e'}.oi-moon:before{content:'\e09f'}.oi-move:before{content:'\e0a0'}.oi-musical-note:before{content:'\e0a1'}.oi-paperclip:before{content:'\e0a2'}.oi-pencil:before{content:'\e0a3'}.oi-people:before{content:'\e0a4'}.oi-person:before{content:'\e0a5'}.oi-phone:before{content:'\e0a6'}.oi-pie-chart:before{content:'\e0a7'}.oi-pin:before{content:'\e0a8'}.oi-play-circle:before{content:'\e0a9'}.oi-plus:before{content:'\e0aa'}.oi-power-standby:before{content:'\e0ab'}.oi-print:before{content:'\e0ac'}.oi-project:before{content:'\e0ad'}.oi-pulse:before{content:'\e0ae'}.oi-puzzle-piece:before{content:'\e0af'}.oi-question-mark:before{content:'\e0b0'}.oi-rain:before{content:'\e0b1'}.oi-random:before{content:'\e0b2'}.oi-reload:before{content:'\e0b3'}.oi-resize-both:before{content:'\e0b4'}.oi-resize-height:before{content:'\e0b5'}.oi-resize-width:before{content:'\e0b6'}.oi-rss-alt:before{content:'\e0b7'}.oi-rss:before{content:'\e0b8'}.oi-script:before{content:'\e0b9'}.oi-share-boxed:before{content:'\e0ba'}.oi-share:before{content:'\e0bb'}.oi-shield:before{content:'\e0bc'}.oi-signal:before{content:'\e0bd'}.oi-signpost:before{content:'\e0be'}.oi-sort-ascending:before{content:'\e0bf'}.oi-sort-descending:before{content:'\e0c0'}.oi-spreadsheet:before{content:'\e0c1'}.oi-star:before{content:'\e0c2'}.oi-sun:before{content:'\e0c3'}.oi-tablet:before{content:'\e0c4'}.oi-tag:before{content:'\e0c5'}.oi-tags:before{content:'\e0c6'}.oi-target:before{content:'\e0c7'}.oi-task:before{content:'\e0c8'}.oi-terminal:before{content:'\e0c9'}.oi-text:before{content:'\e0ca'}.oi-thumb-down:before{content:'\e0cb'}.oi-thumb-up:before{content:'\e0cc'}.oi-timer:before{content:'\e0cd'}.oi-transfer:before{content:'\e0ce'}.oi-trash:before{content:'\e0cf'}.oi-underline:before{content:'\e0d0'}.oi-vertical-align-bottom:before{content:'\e0d1'}.oi-vertical-align-center:before{content:'\e0d2'}.oi-vertical-align-top:before{content:'\e0d3'}.oi-video:before{content:'\e0d4'}.oi-volume-high:before{content:'\e0d5'}.oi-volume-low:before{content:'\e0d6'}.oi-volume-off:before{content:'\e0d7'}.oi-warning:before{content:'\e0d8'}.oi-wifi:before{content:'\e0d9'}.oi-wrench:before{content:'\e0da'}.oi-x:before{content:'\e0db'}.oi-yen:before{content:'\e0dc'}.oi-zoom-in:before{content:'\e0dd'}.oi-zoom-out:before{content:'\e0de'} -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agency8/BlazorAccountsManagerApp/2952c6525e3f6ed40488260ac1db1786342e0c22/BlazorAccountsManager/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.eot -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agency8/BlazorAccountsManagerApp/2952c6525e3f6ed40488260ac1db1786342e0c22/BlazorAccountsManager/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.otf -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | Created by FontForge 20120731 at Tue Jul 1 20:39:22 2014 9 | By P.J. Onori 10 | Created by P.J. Onori with FontForge 2.0 (http://fontforge.sf.net) 11 | 12 | 13 | 14 | 27 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 45 | 47 | 49 | 51 | 53 | 55 | 57 | 59 | 61 | 63 | 65 | 67 | 69 | 71 | 74 | 76 | 79 | 81 | 84 | 86 | 88 | 91 | 93 | 95 | 98 | 100 | 102 | 104 | 106 | 109 | 112 | 115 | 117 | 121 | 123 | 125 | 127 | 130 | 132 | 134 | 136 | 138 | 141 | 143 | 145 | 147 | 149 | 151 | 153 | 155 | 157 | 159 | 162 | 165 | 167 | 169 | 172 | 174 | 177 | 179 | 181 | 183 | 185 | 189 | 191 | 194 | 196 | 198 | 200 | 202 | 205 | 207 | 209 | 211 | 213 | 215 | 218 | 220 | 222 | 224 | 226 | 228 | 230 | 232 | 234 | 236 | 238 | 241 | 243 | 245 | 247 | 249 | 251 | 253 | 256 | 259 | 261 | 263 | 265 | 267 | 269 | 272 | 274 | 276 | 280 | 282 | 285 | 287 | 289 | 292 | 295 | 298 | 300 | 302 | 304 | 306 | 309 | 312 | 314 | 316 | 318 | 320 | 322 | 324 | 326 | 330 | 334 | 338 | 340 | 343 | 345 | 347 | 349 | 351 | 353 | 355 | 358 | 360 | 363 | 365 | 367 | 369 | 371 | 373 | 375 | 377 | 379 | 381 | 383 | 386 | 388 | 390 | 392 | 394 | 396 | 399 | 401 | 404 | 406 | 408 | 410 | 412 | 414 | 416 | 419 | 421 | 423 | 425 | 428 | 431 | 435 | 438 | 440 | 442 | 444 | 446 | 448 | 451 | 453 | 455 | 457 | 460 | 462 | 464 | 466 | 468 | 471 | 473 | 477 | 479 | 481 | 483 | 486 | 488 | 490 | 492 | 494 | 496 | 499 | 501 | 504 | 506 | 509 | 512 | 515 | 517 | 520 | 522 | 524 | 526 | 529 | 532 | 534 | 536 | 539 | 542 | 543 | 544 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agency8/BlazorAccountsManagerApp/2952c6525e3f6ed40488260ac1db1786342e0c22/BlazorAccountsManager/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agency8/BlazorAccountsManagerApp/2952c6525e3f6ed40488260ac1db1786342e0c22/BlazorAccountsManager/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.woff -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agency8/BlazorAccountsManagerApp/2952c6525e3f6ed40488260ac1db1786342e0c22/BlazorAccountsManager/Client/wwwroot/favicon.ico -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/wwwroot/icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agency8/BlazorAccountsManagerApp/2952c6525e3f6ed40488260ac1db1786342e0c22/BlazorAccountsManager/Client/wwwroot/icon-192.png -------------------------------------------------------------------------------- /BlazorAccountsManager/Client/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | BlazorAccountsManager 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
Loading...
16 | 17 |
18 | An unhandled error has occurred. 19 | Reload 20 | 🗙 21 |
22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Areas/Identity/Pages/Shared/_LoginPartial.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Identity 2 | @using BlazorAccountsManager.Shared.Models 3 | @inject SignInManager SignInManager 4 | @inject UserManager UserManager 5 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 6 | 7 | @{ 8 | var returnUrl = "/"; 9 | if (Context.Request.Query.TryGetValue("returnUrl", out var existingUrl)) { 10 | returnUrl = existingUrl; 11 | } 12 | } 13 | 14 | 36 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/BlazorAccountsManager.Server.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | BlazorAccountsManager.Server-45E6DA2D-9D72-4C78-B62D-CBC2927A07FC 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Controllers/AuthController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace BlazorAccountsManager.Server.Controllers 4 | { 5 | [Route("api/[controller]")] 6 | [ApiController] 7 | public class AuthController : ControllerBase 8 | { 9 | private readonly IAuthService _authService; 10 | private readonly UserManager _userManager; 11 | 12 | public AuthController(IAuthService authService, UserManager userManager) 13 | { 14 | _authService = authService; 15 | _userManager = userManager; 16 | } 17 | 18 | [HttpPost("Login")] 19 | public async Task> Login([FromBody] LoginDto request) 20 | { 21 | var result = await _authService.UserLogin(request); 22 | return result; 23 | } //Login 24 | 25 | 26 | 27 | [HttpPost("Register")] 28 | public async Task> Post([FromBody] RegisterDto request) 29 | { 30 | var result = await _authService.UserRegister(request); 31 | return result; 32 | } //Register 33 | 34 | 35 | 36 | 37 | [HttpPost("CreateUserAccount")] 38 | [Authorize(Policy = "IsSuperAdmin")] 39 | public async Task> CreateUserAccount(UserAccountDto request) 40 | { 41 | var result = await _authService.CreateUserAccount(request); 42 | return result; 43 | } //CreateUserAccount 44 | 45 | 46 | [HttpPost("UpdateUserAccount")] 47 | [Authorize(Policy = "IsSuperAdmin")] 48 | public async Task> UpdateUserAccount(UserAccountDto request) 49 | { 50 | var result = await _authService.UpdateUserAccount(request); 51 | return result; 52 | } //UpdateUserAccount 53 | 54 | 55 | 56 | [HttpDelete("DeleteUserAccount/{userId}")] 57 | [Authorize(Policy = "IsSuperAdmin")] 58 | public async Task> DeleteUserAccount(string userId) 59 | { 60 | var result = await _authService.DeleteUserAccount(userId); 61 | return result; 62 | } //DeleteUserAccount 63 | 64 | 65 | 66 | 67 | 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Controllers/UserAccountController.cs: -------------------------------------------------------------------------------- 1 |  2 | using Microsoft.AspNetCore.Http; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace BlazorAccountsManager.Server.Controllers 6 | { 7 | [Route("api/[controller]")] 8 | [ApiController] 9 | public class UserAccountController : ControllerBase 10 | { 11 | private readonly IUserAccountService _userAccountService; 12 | 13 | public UserAccountController(IUserAccountService userAccountService) 14 | { 15 | _userAccountService = userAccountService; 16 | } 17 | 18 | 19 | 20 | 21 | [HttpGet("GetUserAccounts")] 22 | [Authorize(Policy = "IsSuperAdmin")] 23 | public async Task>>> GetUserAccounts() 24 | { 25 | var result = await _userAccountService.GetUserAccounts(); 26 | return result; 27 | } //GetUserAccounts 28 | 29 | 30 | [HttpGet("GetUserDetails/{userId}")] 31 | public async Task>> GetUserDetails(string userId) 32 | { 33 | var result = await _userAccountService.GetUserDetails(userId); 34 | return result; 35 | } //GetUserAccount 36 | 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using BlazorAccountsManager.Shared; 2 | using Microsoft.AspNetCore.Authorization; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace BlazorAccountsManager.Server.Controllers 6 | { 7 | [Authorize] 8 | [ApiController] 9 | [Route("[controller]")] 10 | public class WeatherForecastController : ControllerBase 11 | { 12 | private static readonly string[] Summaries = new[] 13 | { 14 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 15 | }; 16 | 17 | private readonly ILogger _logger; 18 | 19 | public WeatherForecastController(ILogger logger) 20 | { 21 | _logger = logger; 22 | } 23 | 24 | [HttpGet] 25 | public IEnumerable Get() 26 | { 27 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 28 | { 29 | Date = DateTime.Now.AddDays(index), 30 | TemperatureC = Random.Shared.Next(-20, 55), 31 | Summary = Summaries[Random.Shared.Next(Summaries.Length)] 32 | }) 33 | .ToArray(); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Data/DataContext.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorAccountsManager.Server.Data 2 | { 3 | public class DataContext : IdentityDbContext 4 | { 5 | public DataContext(DbContextOptions options) : base(options) 6 | { 7 | 8 | } 9 | 10 | 11 | protected override void OnModelCreating(ModelBuilder modelBuilder) 12 | { 13 | base.OnModelCreating(modelBuilder); 14 | 15 | modelBuilder.Entity(b => { b.ToTable("Users"); }); 16 | modelBuilder.Entity>(b => { b.ToTable("UserClaims"); }); 17 | modelBuilder.Entity>(b => { b.ToTable("UserLogins"); }); 18 | modelBuilder.Entity>(b => { b.ToTable("UserTokens"); }); 19 | modelBuilder.Entity(b => { b.ToTable("Roles"); }); 20 | modelBuilder.Entity>(b => { b.ToTable("RoleClaims"); }); 21 | modelBuilder.Entity>(b => { b.ToTable("UserRoles"); }); 22 | 23 | foreach (string role in Enum.GetNames(typeof(Roles))) 24 | { 25 | var guid = Guid.NewGuid().ToString(); 26 | modelBuilder.Entity().HasData( 27 | new IdentityRole 28 | { 29 | Name = role, 30 | NormalizedName = role.ToUpper(), 31 | Id = guid, 32 | ConcurrencyStamp = Guid.NewGuid().ToString() 33 | }); 34 | 35 | if (role == "SuperAdmin") 36 | SeedSuperUser(modelBuilder, guid); 37 | 38 | } 39 | } 40 | 41 | 42 | 43 | 44 | private void SeedSuperUser(ModelBuilder builder, string roleGuid) 45 | { 46 | var userGuid = Guid.NewGuid().ToString(); 47 | ApplicationUser user = new ApplicationUser() 48 | { 49 | Id = userGuid, 50 | UserName = "superadmin", 51 | NormalizedUserName = "SUPERADMIN", 52 | Email = "admin@admin.com", 53 | NormalizedEmail = "ADMIN@ADMIN.COM", 54 | FirstName = "Super", 55 | LastName = "Admin", 56 | DisplayName = "SuperAdmin" 57 | }; 58 | 59 | user.PasswordHash = GeneratePasswordHash(user, "Admin*123"); 60 | builder.Entity().HasData(user); 61 | 62 | builder.Entity>().HasData(new IdentityUserRole() 63 | { 64 | RoleId = roleGuid, 65 | UserId = userGuid 66 | }); 67 | } 68 | 69 | public string GeneratePasswordHash(ApplicationUser user, string password) 70 | { 71 | var passHash = new PasswordHasher(); 72 | return passHash.HashPassword(user, password); 73 | } 74 | 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Pages/Error.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model BlazorAccountsManager.Server.Pages.ErrorModel 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Error 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 |

Error.

19 |

An error occurred while processing your request.

20 | 21 | @if (Model.ShowRequestId) 22 | { 23 |

24 | Request ID: @Model.RequestId 25 |

26 | } 27 | 28 |

Development Mode

29 |

30 | Swapping to the Development environment displays detailed information about the error that occurred. 31 |

32 |

33 | The Development environment shouldn't be enabled for deployed applications. 34 | It can result in displaying sensitive information from exceptions to end users. 35 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 36 | and restarting the app. 37 |

38 |
39 |
40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Pages/Error.cshtml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.AspNetCore.Mvc.RazorPages; 3 | using System.Diagnostics; 4 | 5 | namespace BlazorAccountsManager.Server.Pages 6 | { 7 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 8 | [IgnoreAntiforgeryToken] 9 | public class ErrorModel : PageModel 10 | { 11 | public string? RequestId { get; set; } 12 | 13 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 14 | 15 | private readonly ILogger _logger; 16 | 17 | public ErrorModel(ILogger logger) 18 | { 19 | _logger = logger; 20 | } 21 | 22 | public void OnGet() 23 | { 24 | RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Program.cs: -------------------------------------------------------------------------------- 1 | global using BlazorAccountsManager.Shared.Models; 2 | global using BlazorAccountsManager.Shared.Dtos; 3 | global using BlazorAccountsManager.Shared.Enums; 4 | global using Microsoft.EntityFrameworkCore; 5 | global using BlazorAccountsManager.Server.Data; 6 | global using BlazorAccountsManager.Shared.Helpers; 7 | global using Microsoft.AspNetCore.Identity; 8 | global using Microsoft.AspNetCore.Authorization; 9 | global using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 10 | global using BlazorAccountsManager.Server.Services.AuthService; 11 | global using BlazorAccountsManager.Server.Services.UserAccountService; 12 | 13 | 14 | using Microsoft.AspNetCore.Authentication; 15 | using Microsoft.AspNetCore.Authentication.JwtBearer; 16 | using Microsoft.AspNetCore.ResponseCompression; 17 | using Microsoft.IdentityModel.Tokens; 18 | using System.Text; 19 | 20 | 21 | var builder = WebApplication.CreateBuilder(args); 22 | 23 | // Add services to the container. 24 | var connectionString = builder.Configuration.GetConnectionString("SqlConnection"); 25 | string jwtIssuer = builder.Configuration["JwtIssuer"]; 26 | string jwtAudience = builder.Configuration["JwtAudience"]; 27 | string jwtSecurityKey = builder.Configuration["JwtSecurityKey"]; 28 | 29 | 30 | 31 | builder.Services.AddDbContext(options => 32 | options.UseSqlServer(connectionString)); 33 | 34 | builder.Services.AddDefaultIdentity() 35 | .AddRoles() 36 | .AddEntityFrameworkStores(); 37 | 38 | builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) 39 | .AddJwtBearer(options => 40 | { 41 | options.TokenValidationParameters = new TokenValidationParameters 42 | { 43 | ValidateIssuer = true, 44 | ValidateAudience = true, 45 | ValidateLifetime = true, 46 | ValidateIssuerSigningKey = true, 47 | ValidIssuer = jwtIssuer, 48 | ValidAudience = jwtAudience, 49 | IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSecurityKey)), 50 | ClockSkew = TimeSpan.FromSeconds(0) 51 | }; 52 | }); 53 | 54 | builder.Services.AddAuthorization(config => 55 | { 56 | config.AddPolicy(Policies.IsSuperAdmin, Policies.IsSuperAdminPolicy()); 57 | config.AddPolicy(Policies.IsAdmin, Policies.IsAdminPolicy()); 58 | config.AddPolicy(Policies.IsUser, Policies.IsUserPolicy()); 59 | }); 60 | 61 | 62 | 63 | builder.Services.AddScoped(); 64 | builder.Services.AddScoped(); 65 | 66 | builder.Services.AddControllers(); 67 | builder.Services.AddRazorPages(); 68 | 69 | var app = builder.Build(); 70 | 71 | // Configure the HTTP request pipeline. 72 | if (app.Environment.IsDevelopment()) 73 | { 74 | app.UseMigrationsEndPoint(); 75 | app.UseWebAssemblyDebugging(); 76 | } 77 | else 78 | { 79 | app.UseExceptionHandler("/Error"); 80 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. 81 | app.UseHsts(); 82 | } 83 | 84 | app.UseHttpsRedirection(); 85 | 86 | app.UseBlazorFrameworkFiles(); 87 | app.UseStaticFiles(); 88 | 89 | app.UseRouting(); 90 | app.UseAuthentication(); 91 | app.UseAuthorization(); 92 | 93 | app.MapRazorPages(); 94 | app.MapControllers(); 95 | app.MapFallbackToFile("index.html"); 96 | 97 | app.Run(); 98 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:13686", 7 | "sslPort": 44319 8 | } 9 | }, 10 | "profiles": { 11 | "BlazorAccountsManager.Server": { 12 | "commandName": "Project", 13 | "dotnetRunMessages": true, 14 | "launchBrowser": true, 15 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 16 | "applicationUrl": "https://localhost:7058;http://localhost:5058", 17 | "environmentVariables": { 18 | "ASPNETCORE_ENVIRONMENT": "Development" 19 | } 20 | }, 21 | "IIS Express": { 22 | "commandName": "IISExpress", 23 | "launchBrowser": true, 24 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Properties/serviceDependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mssql1": { 4 | "type": "mssql", 5 | "connectionId": "ConnectionStrings:DefaultConnection" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Properties/serviceDependencies.local.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mssql1": { 4 | "type": "mssql.local", 5 | "connectionId": "ConnectionStrings:DefaultConnection" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Services/AuthService/AuthService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | using System.IdentityModel.Tokens.Jwt; 3 | using System.Security.Claims; 4 | using System.Text; 5 | 6 | namespace BlazorAccountsManager.Server.Services.AuthService 7 | { 8 | public class AuthService : IAuthService 9 | { 10 | private readonly DataContext _context; 11 | private readonly IConfiguration _configuration; 12 | private readonly IHttpContextAccessor _httpContextAccessor; 13 | private readonly UserManager _userManager; 14 | private readonly SignInManager _signInManager; 15 | 16 | public AuthService(DataContext context, 17 | IConfiguration configuration, 18 | IHttpContextAccessor httpContextAccessor, 19 | UserManager userManager, 20 | SignInManager signInManager) 21 | { 22 | _context = context; 23 | _configuration = configuration; 24 | _httpContextAccessor = httpContextAccessor; 25 | _userManager = userManager; 26 | _signInManager = signInManager; 27 | } 28 | 29 | 30 | 31 | public string GetUserId() => _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); 32 | 33 | 34 | public async Task> UserLogin(LoginDto user) 35 | { 36 | var result = await _signInManager.PasswordSignInAsync(user.Email, user.Password, false, false); 37 | if (!result.Succeeded) 38 | { 39 | return new ServiceResponse 40 | { 41 | Success = false, 42 | Message = "Username and password are invalid." 43 | }; 44 | } 45 | 46 | List claims = await CreateClaims(user); 47 | 48 | var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JwtSecurityKey"])); 49 | var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); 50 | var expiry = DateTime.Now.AddDays(Convert.ToInt32(_configuration["JwtExpiryInDays"])); 51 | 52 | var token = new JwtSecurityToken( 53 | _configuration["JwtIssuer"], 54 | _configuration["JwtAudience"], 55 | claims, 56 | expires: expiry, 57 | signingCredentials: creds 58 | ); 59 | var response = new ServiceResponse 60 | { 61 | Success = true, 62 | Data = new JwtSecurityTokenHandler().WriteToken(token), 63 | Message = "Registration successful!" 64 | }; 65 | 66 | return response; 67 | } //UserLogin 68 | 69 | 70 | public async Task> UserRegister(RegisterDto user) 71 | { 72 | if (await UserExists(user.Email)) 73 | { 74 | return new ServiceResponse 75 | { 76 | Success = false, 77 | Message = "User already exists." 78 | }; 79 | } 80 | 81 | var displayName = user.FirstName; 82 | if (!string.IsNullOrEmpty(user.DisplayName)) 83 | displayName = user.DisplayName; 84 | 85 | var newUser = new ApplicationUser { 86 | UserName = user.Email, 87 | Email = user.Email, 88 | FirstName = user.FirstName, 89 | LastName = user.LastName, 90 | DisplayName = displayName 91 | }; 92 | var result = await _userManager.CreateAsync(newUser, user.Password); 93 | await _userManager.AddToRoleAsync(newUser, "Registered"); 94 | 95 | if (!result.Succeeded) 96 | { 97 | return new ServiceResponse 98 | { 99 | Success = false, 100 | Message = "Oops, something went wrong :/" 101 | }; 102 | } 103 | 104 | return new ServiceResponse { 105 | Success = true, 106 | Message = "Registration successful!" 107 | }; 108 | } //UserRegister 109 | 110 | 111 | public async Task> CreateUserAccount(UserAccountDto user) 112 | { 113 | if (await UserExists(user.Email)) 114 | { 115 | return new ServiceResponse 116 | { 117 | Success = false, 118 | Message = "User already exists." 119 | }; 120 | } 121 | 122 | var displayName = user.FirstName; 123 | if (!string.IsNullOrEmpty(user.DisplayName)) 124 | displayName = user.DisplayName; 125 | 126 | var newCreateUser = new ApplicationUser { 127 | UserName = user.UserName, 128 | Email = user.Email, 129 | FirstName = user.FirstName, 130 | LastName = user.LastName, 131 | DisplayName = displayName, 132 | Notes = user.Notes, 133 | }; 134 | 135 | var result = await _userManager.CreateAsync(newCreateUser, user.Password); 136 | await _userManager.AddToRoleAsync(newCreateUser, user.UserRole); 137 | 138 | if (!result.Succeeded) 139 | { 140 | return new ServiceResponse 141 | { 142 | Success = false, 143 | Message = "Oops, something went wrong :/" 144 | }; 145 | } 146 | 147 | return new ServiceResponse { 148 | Success = true, 149 | Message = "New account creation successful!" 150 | }; 151 | } //CreateUserAccount 152 | 153 | 154 | public async Task> UpdateUserAccount(UserAccountDto user) 155 | { 156 | var currentUser = await _userManager.FindByIdAsync(user.UserId); 157 | currentUser.UserName = user.UserName; 158 | currentUser.NormalizedUserName = user.UserName.ToUpper(); 159 | currentUser.FirstName = user.FirstName; 160 | currentUser.LastName = user.LastName; 161 | currentUser.DisplayName = user.DisplayName; 162 | currentUser.Notes = user.Notes; 163 | 164 | var result = await _userManager.UpdateAsync(currentUser); 165 | 166 | foreach (var role in Enum.GetValues(typeof(Roles))) 167 | await _userManager.RemoveFromRoleAsync(currentUser, role.ToString()); 168 | 169 | await _userManager.AddToRoleAsync(currentUser, user.UserRole); 170 | 171 | if (!result.Succeeded) 172 | { 173 | return new ServiceResponse 174 | { 175 | Success = false, 176 | Message = "Oops, something went wrong :/" 177 | }; 178 | } 179 | 180 | return new ServiceResponse 181 | { 182 | Success = true, 183 | Message = "Account updated successful!" 184 | }; 185 | } //UpdateUserAccount 186 | 187 | 188 | 189 | public async Task> DeleteUserAccount(string userId) 190 | { 191 | var currentUser = await _userManager.FindByIdAsync(userId); 192 | if (currentUser == null) 193 | { 194 | return new ServiceResponse 195 | { 196 | Success = false, 197 | Message = "User account not found" 198 | }; 199 | } 200 | var result = await _userManager.DeleteAsync(currentUser); 201 | 202 | if (!result.Succeeded) 203 | { 204 | return new ServiceResponse 205 | { 206 | Success = false, 207 | Message = "Oops, something went wrong :/" 208 | }; 209 | } 210 | 211 | return new ServiceResponse 212 | { 213 | Success = true, 214 | Message = "User account deleted successfully!" 215 | }; 216 | } //DeleteUserAccount 217 | 218 | 219 | 220 | 221 | 222 | 223 | private async Task UserExists(string email) 224 | { 225 | if (await _context.Users.AnyAsync(user => user.Email.ToLower() 226 | .Equals(email.ToLower()))) 227 | { 228 | return true; 229 | } 230 | return false; 231 | } //UserExists 232 | 233 | 234 | private async Task> CreateClaims(LoginDto login) 235 | { 236 | var user = await _userManager.FindByEmailAsync(login.Email) ?? await _userManager.FindByNameAsync(login.Email); 237 | var roles = await _userManager.GetRolesAsync(user); 238 | 239 | List claims = new List 240 | { 241 | new Claim(ClaimTypes.NameIdentifier, user.Id), 242 | new Claim(ClaimTypes.Name, login.Email), 243 | new Claim(ClaimTypes.Email, login.Email) 244 | }; 245 | 246 | foreach (var role in roles) 247 | claims.Add(new Claim(ClaimTypes.Role, role)); 248 | 249 | return claims; 250 | } //CreateClaims 251 | 252 | 253 | } 254 | } 255 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Services/AuthService/IAuthService.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorAccountsManager.Server.Services.AuthService 2 | { 3 | public interface IAuthService 4 | { 5 | Task> UserLogin(LoginDto user); 6 | Task> UserRegister(RegisterDto user); 7 | Task> CreateUserAccount(UserAccountDto user); 8 | Task> UpdateUserAccount(UserAccountDto user); 9 | Task> DeleteUserAccount(string userId); 10 | string GetUserId(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Services/UserAccountService/IUserAccountService.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorAccountsManager.Server.Services.UserAccountService 2 | { 3 | public interface IUserAccountService 4 | { 5 | Task>> GetUserAccounts(); 6 | Task> GetUserDetails(string userId); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/Services/UserAccountService/UserAccountService.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorAccountsManager.Server.Services.UserAccountService 2 | { 3 | public class UserAccountService : IUserAccountService 4 | { 5 | private readonly DataContext _context; 6 | private readonly UserManager _userManager; 7 | public UserAccountService(DataContext context, UserManager userManager) 8 | { 9 | _context = context; 10 | _userManager = userManager; 11 | } 12 | 13 | 14 | 15 | public async Task>> GetUserAccounts() 16 | { 17 | var response = new ServiceResponse>(); 18 | List userList = new List(); 19 | var users = await _userManager.Users.Select(x => new ApplicationUser 20 | { 21 | Id = x.Id, 22 | UserName = x.UserName, 23 | Email = x.Email, 24 | FirstName = x.FirstName, 25 | LastName = x.LastName, 26 | DisplayName = x.DisplayName, 27 | PasswordHash = "*****" 28 | }).ToListAsync(); 29 | 30 | if (users.Count() <= 0) 31 | { 32 | response.Success = false; 33 | response.Message = "Sorry, No user accounts found"; 34 | } 35 | else 36 | { 37 | foreach (var user in users) 38 | { 39 | var isSuperUser = await _userManager.IsInRoleAsync(user, "SuperAdmin"); 40 | 41 | var roles = await _userManager.GetRolesAsync(user); 42 | var userRole = roles.FirstOrDefault(); 43 | 44 | 45 | userList.Add(new UserAccountDto 46 | { 47 | UserId = user.Id, 48 | UserName = user.UserName, 49 | Email = user.Email, 50 | FirstName = user.FirstName, 51 | LastName = user.LastName, 52 | DisplayName = user.DisplayName, 53 | UserRole = userRole, 54 | IsSuperUser = isSuperUser 55 | }); 56 | } 57 | response.Success = true; 58 | response.Data = userList.ToList(); 59 | } 60 | return response; 61 | } //GetUserAccounts 62 | 63 | 64 | 65 | public async Task> GetUserDetails(string userId) 66 | { 67 | var response = new ServiceResponse(); 68 | var foundUser = await _userManager.FindByIdAsync(userId); 69 | var user = new UserAccountDto(); 70 | 71 | if (foundUser == null) 72 | { 73 | response.Success = true; 74 | response.Message = "Sorry, The user account is not found"; 75 | } 76 | else 77 | { 78 | var roles = await _userManager.GetRolesAsync(foundUser); 79 | var userRole = roles.FirstOrDefault(); 80 | 81 | 82 | user.UserId = foundUser.Id; 83 | user.UserName = foundUser.UserName; 84 | user.Email = foundUser.Email; 85 | user.FirstName = foundUser.FirstName; 86 | user.LastName = foundUser.LastName; 87 | user.DisplayName = foundUser.DisplayName; 88 | user.UserRole = userRole; 89 | user.Notes = foundUser.Notes; 90 | 91 | response.Success = true; 92 | response.Data = user; 93 | } 94 | 95 | return response; 96 | } //GetUserDetails 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "IdentityServer": { 9 | "Key": { 10 | "Type": "Development" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Server/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "SqlConnection": "Server=localhost\\sqlexpress;Database=BlazorAccountsManager;Trusted_Connection=True;MultipleActiveResultSets=true" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Information", 8 | "Microsoft.AspNetCore": "Warning" 9 | } 10 | }, 11 | "IdentityServer": { 12 | "Clients": { 13 | "BlazorAccountsManager.Client": { 14 | "Profile": "IdentityServerSPA" 15 | } 16 | } 17 | }, 18 | "JwtSecurityKey": "ADD_A_NEW_SECURITY_KEY_HERE", 19 | "JwtIssuer": "https://localhost", 20 | "JwtAudience": "localhost", 21 | "JwtExpiryInDays": 1, 22 | "AllowedHosts": "*" 23 | } 24 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Shared/BlazorAccountsManager.Shared.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Shared/Dtos/LoginDto.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace BlazorAccountsManager.Shared.Dtos 4 | { 5 | public class LoginDto 6 | { 7 | [Required] 8 | public string Email { get; set; } = string.Empty; 9 | [Required] 10 | public string Password { get; set; } = string.Empty; 11 | public bool RememberMe { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Shared/Dtos/RegisterDto.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace BlazorAccountsManager.Shared.Dtos 4 | { 5 | public class RegisterDto 6 | { 7 | [Required] 8 | [StringLength(128, ErrorMessage = "FirstName is required")] 9 | [Display(Name = "FirstName")] 10 | public string FirstName { get; set; } = string.Empty; 11 | 12 | [Required] 13 | [StringLength(128, ErrorMessage = "SurName is required")] 14 | [Display(Name = "Surname")] 15 | public string LastName { get; set; } = string.Empty; 16 | 17 | public string DisplayName { get; set; } = string.Empty; 18 | 19 | 20 | [Required] 21 | [EmailAddress] 22 | [Display(Name = "Email")] 23 | public string Email { get; set; } = string.Empty; 24 | 25 | [Required] 26 | [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 27 | [DataType(DataType.Password)] 28 | [Display(Name = "Password")] 29 | public string Password { get; set; } = string.Empty; 30 | 31 | [DataType(DataType.Password)] 32 | [Display(Name = "Confirm password")] 33 | [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] 34 | public string ConfirmPassword { get; set; } = string.Empty; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Shared/Dtos/UserAccountDto.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace BlazorAccountsManager.Shared.Dtos 4 | { 5 | public class UserAccountDto 6 | { 7 | public string UserId { get; set; } = string.Empty; 8 | 9 | [Required] 10 | [StringLength(256, MinimumLength = 8, ErrorMessage = "Username must be larger than 7 charactors!")] 11 | [Display(Name = "UserName")] 12 | public string UserName { get; set; } = string.Empty; 13 | 14 | [Required] 15 | [EmailAddress] 16 | [StringLength(256, ErrorMessage = "A valid is required")] 17 | [Display(Name = "Email")] 18 | public string Email { get; set; } = string.Empty; 19 | 20 | [Required] 21 | [StringLength(128, ErrorMessage = "FirstName is required")] 22 | [Display(Name = "FirstName")] 23 | public string FirstName { get; set; } = string.Empty; 24 | 25 | [Required] 26 | [StringLength(128, ErrorMessage = "Surname is required")] 27 | [Display(Name = "Surname")] 28 | public string LastName { get; set; } = string.Empty; 29 | public string DisplayName { get; set; } = string.Empty; 30 | public string Notes { get; set; } = string.Empty; 31 | public string Password { get; set; } = string.Empty; 32 | public string ConfirmPassword { get; set; } = string.Empty; 33 | public string UserRole { get; set; } = "Registered"; 34 | public bool IsSuperUser { get; set; } = false; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Shared/Enums/Roles.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorAccountsManager.Shared.Enums 2 | { 3 | public enum Roles 4 | { 5 | Registered, 6 | User, 7 | Editor, 8 | Administrator, 9 | SuperAdmin 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Shared/Helpers/Policies.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | 3 | namespace BlazorAccountsManager.Shared.Helpers 4 | { 5 | public static class Policies 6 | { 7 | public const string IsSuperAdmin = "IsSuperAdmin"; 8 | public const string IsAdmin = "IsAdmin"; 9 | public const string IsUser = "IsUser"; 10 | 11 | 12 | public static AuthorizationPolicy IsSuperAdminPolicy() 13 | { 14 | return new AuthorizationPolicyBuilder() 15 | .RequireAuthenticatedUser() 16 | .RequireRole("SuperAdmin") 17 | .Build(); 18 | } 19 | 20 | public static AuthorizationPolicy IsAdminPolicy() 21 | { 22 | return new AuthorizationPolicyBuilder() 23 | .RequireAuthenticatedUser() 24 | .RequireRole("Administrator") 25 | .Build(); 26 | } 27 | 28 | public static AuthorizationPolicy IsUserPolicy() 29 | { 30 | return new AuthorizationPolicyBuilder() 31 | .RequireAuthenticatedUser() 32 | .RequireRole("User", "Registered") 33 | .Build(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Shared/Models/ApplicationUser.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace BlazorAccountsManager.Shared.Models 5 | { 6 | public class ApplicationUser : IdentityUser 7 | { 8 | [Column(TypeName = "varchar(128)")] 9 | public string FirstName { get; set; } = string.Empty; 10 | [Column(TypeName = "varchar(128)")] 11 | public string LastName { get; set; } = string.Empty; 12 | [Column(TypeName = "varchar(128)")] 13 | public string DisplayName { get; set; } = string.Empty; 14 | public string CustomClaim { get; set; } = string.Empty; 15 | public string Notes { get; set; } = string.Empty; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Shared/Models/ServiceResponse.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorAccountsManager.Shared.Models 2 | { 3 | public class ServiceResponse 4 | { 5 | public T? Data { get; set; } 6 | public bool Success { get; set; } = true; 7 | public string Message { get; set; } = string.Empty; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /BlazorAccountsManager/Shared/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorAccountsManager.Shared 2 | { 3 | public class WeatherForecast 4 | { 5 | public DateTime Date { get; set; } 6 | 7 | public int TemperatureC { get; set; } 8 | 9 | public string? Summary { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | } 13 | } -------------------------------------------------------------------------------- /BlazorAccountsManagerApp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32421.90 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorAccountsManager.Server", "BlazorAccountsManager\Server\BlazorAccountsManager.Server.csproj", "{2D5B83FC-35EF-4A7A-AB06-91C70D779259}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorAccountsManager.Client", "BlazorAccountsManager\Client\BlazorAccountsManager.Client.csproj", "{24288B72-986C-4962-ABB4-52C9F13528D0}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorAccountsManager.Shared", "BlazorAccountsManager\Shared\BlazorAccountsManager.Shared.csproj", "{0B604C48-B61A-4F9C-882C-03EFB74DE0EA}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {2D5B83FC-35EF-4A7A-AB06-91C70D779259}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {2D5B83FC-35EF-4A7A-AB06-91C70D779259}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {2D5B83FC-35EF-4A7A-AB06-91C70D779259}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {2D5B83FC-35EF-4A7A-AB06-91C70D779259}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {24288B72-986C-4962-ABB4-52C9F13528D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {24288B72-986C-4962-ABB4-52C9F13528D0}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {24288B72-986C-4962-ABB4-52C9F13528D0}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {24288B72-986C-4962-ABB4-52C9F13528D0}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {0B604C48-B61A-4F9C-882C-03EFB74DE0EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {0B604C48-B61A-4F9C-882C-03EFB74DE0EA}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {0B604C48-B61A-4F9C-882C-03EFB74DE0EA}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {0B604C48-B61A-4F9C-882C-03EFB74DE0EA}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {1964FA4A-5C88-4A86-A93D-129944BD7425} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Blazor 6 client User Manager Demo 2 | This is a demo to show how to setup and manager users and their roles on the client side. 3 | 4 | ### Features: 5 | - **Client side User Manager** 6 | - Uses **Microsoft Identity** (NOT IdentityServer) 7 | - A complete UI to manager user accounts 8 | - Uses **JWT** for authentication 9 | - **Policy based** roles and authentication 10 | - You can Add, edit, delete and change the user’s role. 11 | - **Custom Database table names** (Users, Roles etc., instead of the standard AspNetUsers, AspNetRoles) 12 | - **Custom fields** added to the ‘ApplicationUser’ table (FirstName, LastName, DisplayName, Notes) 13 | - Registration, Login and logout pages (client side) 14 | - Can be **easily expanded** with extra user account fields etc. 15 | - Added a simple **ToolTips Component** for ease of use 16 | --- 17 | 18 | ![Blazor 6 client User Manager Demo](screenshot1.jpg) 19 | 20 | ![Blazor 6 client User Manager Demo](screenshot2.jpg) 21 | 22 | ### Setup Instructions 23 | 24 | The access role to use the ‘User Account’ page is ‘SuperAdmin’, this is needed. 25 | Change your database connection in the ‘appsettings.json’ file (sqlConnection)) 26 | Create a secret key for JwtSecurityKey, this can be a Guid or anything you like 27 | 28 | `"JwtSecurityKey": "ADD_A_NEW_SECURITY_KEY_HERE"` 29 | 30 | Change the ‘JwtIssuer’ and ‘JwtAudience’ to match your site. 31 | Using the ‘Package Manager Console’ or preferred way, create a migration: 32 | Make sure you are in the right directory: 33 | 34 | - `cd blazoraccountsmanager` 35 | - `cd server` 36 | 37 | Create a migration 38 | 39 | - `dotnet ef migrations add InitialCreate` 40 | 41 | Update the database 42 | 43 | - `dotnet ef database update` 44 | 45 | Once you have created the database via EntityFramework, you should be able to run the app and login with the pre-filled user account below: 46 | 47 | **Username** : superadmin 48 | **Password**: Admin*123 49 | 50 | 51 | -------------------------------------------------------------------------------- /screenshot1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agency8/BlazorAccountsManagerApp/2952c6525e3f6ed40488260ac1db1786342e0c22/screenshot1.jpg -------------------------------------------------------------------------------- /screenshot2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agency8/BlazorAccountsManagerApp/2952c6525e3f6ed40488260ac1db1786342e0c22/screenshot2.jpg --------------------------------------------------------------------------------