├── .github └── workflows │ └── dotnet.yml ├── .gitignore ├── BlazorWasmWithAADAuth ├── BlazorWasmWithAADAuth.sln ├── Client │ ├── App.razor │ ├── BlazorWasmWithAADAuth.Client.csproj │ ├── Pages │ │ ├── Authentication.razor │ │ ├── Counter.razor │ │ ├── FetchData.razor │ │ └── Index.razor │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Services │ │ ├── CustomAccountFactory.cs │ │ ├── CustomUserAccount.cs │ │ ├── DirectoryObjects.cs │ │ ├── GraphCustomAuthorizationMessageHandler.cs │ │ ├── GraphHTTPClientService.cs │ │ └── HTTPClientBackendService.cs │ ├── Shared │ │ ├── LoginDisplay.razor │ │ ├── MainLayout.razor │ │ ├── NavMenu.razor │ │ ├── RedirectToLogin.razor │ │ └── SurveyPrompt.razor │ ├── _Imports.razor │ └── wwwroot │ │ ├── appsettings.json │ │ ├── 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 │ │ ├── getcookie.js │ │ └── index.html ├── Server │ ├── BlazorWasmWithAADAuth.Server.csproj │ ├── Controllers │ │ └── WeatherForecastController.cs │ ├── Pages │ │ ├── Error.cshtml │ │ ├── Error.cshtml.cs │ │ └── Shared │ │ │ └── _Layout.cshtml │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Startup.cs │ ├── appsettings.Development.json │ └── appsettings.json └── Shared │ ├── BlazorWasmWithAADAuth.Shared.csproj │ ├── WeatherForecast.cs │ └── models │ ├── AADObjectModel.cs │ ├── GroupGraphModel.cs │ └── UserGraphModel.cs ├── LICENSE └── README.md /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | name: .NET 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | workflow_dispatch: 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Setup .NET 17 | uses: actions/setup-dotnet@v1 18 | with: 19 | dotnet-version: 6.0.x 20 | - name: Change Files 21 | uses: microsoft/variable-substitution@v1 22 | with: 23 | files: 'BlazorWasmWithAADAuth/Server/appsettings.json' 24 | env: 25 | CorsEndpoints: "https://sshmantest.azurewebsites.net" 26 | ContentPolicy: "Content-Security-Policy" 27 | 28 | - name: Build 29 | run: dotnet build ./BlazorWasmWithAADAuth/BlazorWasmWithAADAuth.sln --configuration Release 30 | - name: dotnet publish 31 | run: dotnet publish ./BlazorWasmWithAADAuth/BlazorWasmWithAADAuth.sln --runtime linux-x64 -c Release -o ${{env.DOTNET_ROOT}}/myapp 32 | 33 | - name: Deploy to Azure Web App 34 | uses: azure/webapps-deploy@v2 35 | with: 36 | app-name: 'sshmantest' 37 | slot-name: 'production' 38 | publish-profile: ${{ secrets.AzureAppService_PublishProfile }} 39 | package: ${{env.DOTNET_ROOT}}/myapp 40 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/BlazorWasmWithAADAuth.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Version 16 3 | VisualStudioVersion = 16.0.0.0 4 | MinimumVisualStudioVersion = 16.0.0.0 5 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorWasmWithAADAuth.Server", "Server\BlazorWasmWithAADAuth.Server.csproj", "{05EC3215-D2F9-44C7-843F-E13491C8D0E1}" 6 | EndProject 7 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorWasmWithAADAuth.Client", "Client\BlazorWasmWithAADAuth.Client.csproj", "{4FB92260-9DD9-4688-92F7-252F3C6F91E5}" 8 | EndProject 9 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorWasmWithAADAuth.Shared", "Shared\BlazorWasmWithAADAuth.Shared.csproj", "{2D92B1BC-C931-4679-BCF7-10D9F681D201}" 10 | EndProject 11 | Global 12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 13 | Debug|Any CPU = Debug|Any CPU 14 | Debug|x64 = Debug|x64 15 | Debug|x86 = Debug|x86 16 | Release|Any CPU = Release|Any CPU 17 | Release|x64 = Release|x64 18 | Release|x86 = Release|x86 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {05EC3215-D2F9-44C7-843F-E13491C8D0E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {05EC3215-D2F9-44C7-843F-E13491C8D0E1}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {05EC3215-D2F9-44C7-843F-E13491C8D0E1}.Debug|x64.ActiveCfg = Debug|Any CPU 24 | {05EC3215-D2F9-44C7-843F-E13491C8D0E1}.Debug|x64.Build.0 = Debug|Any CPU 25 | {05EC3215-D2F9-44C7-843F-E13491C8D0E1}.Debug|x86.ActiveCfg = Debug|Any CPU 26 | {05EC3215-D2F9-44C7-843F-E13491C8D0E1}.Debug|x86.Build.0 = Debug|Any CPU 27 | {05EC3215-D2F9-44C7-843F-E13491C8D0E1}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {05EC3215-D2F9-44C7-843F-E13491C8D0E1}.Release|Any CPU.Build.0 = Release|Any CPU 29 | {05EC3215-D2F9-44C7-843F-E13491C8D0E1}.Release|x64.ActiveCfg = Release|Any CPU 30 | {05EC3215-D2F9-44C7-843F-E13491C8D0E1}.Release|x64.Build.0 = Release|Any CPU 31 | {05EC3215-D2F9-44C7-843F-E13491C8D0E1}.Release|x86.ActiveCfg = Release|Any CPU 32 | {05EC3215-D2F9-44C7-843F-E13491C8D0E1}.Release|x86.Build.0 = Release|Any CPU 33 | {4FB92260-9DD9-4688-92F7-252F3C6F91E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 34 | {4FB92260-9DD9-4688-92F7-252F3C6F91E5}.Debug|Any CPU.Build.0 = Debug|Any CPU 35 | {4FB92260-9DD9-4688-92F7-252F3C6F91E5}.Debug|x64.ActiveCfg = Debug|Any CPU 36 | {4FB92260-9DD9-4688-92F7-252F3C6F91E5}.Debug|x64.Build.0 = Debug|Any CPU 37 | {4FB92260-9DD9-4688-92F7-252F3C6F91E5}.Debug|x86.ActiveCfg = Debug|Any CPU 38 | {4FB92260-9DD9-4688-92F7-252F3C6F91E5}.Debug|x86.Build.0 = Debug|Any CPU 39 | {4FB92260-9DD9-4688-92F7-252F3C6F91E5}.Release|Any CPU.ActiveCfg = Release|Any CPU 40 | {4FB92260-9DD9-4688-92F7-252F3C6F91E5}.Release|Any CPU.Build.0 = Release|Any CPU 41 | {4FB92260-9DD9-4688-92F7-252F3C6F91E5}.Release|x64.ActiveCfg = Release|Any CPU 42 | {4FB92260-9DD9-4688-92F7-252F3C6F91E5}.Release|x64.Build.0 = Release|Any CPU 43 | {4FB92260-9DD9-4688-92F7-252F3C6F91E5}.Release|x86.ActiveCfg = Release|Any CPU 44 | {4FB92260-9DD9-4688-92F7-252F3C6F91E5}.Release|x86.Build.0 = Release|Any CPU 45 | {2D92B1BC-C931-4679-BCF7-10D9F681D201}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 46 | {2D92B1BC-C931-4679-BCF7-10D9F681D201}.Debug|Any CPU.Build.0 = Debug|Any CPU 47 | {2D92B1BC-C931-4679-BCF7-10D9F681D201}.Debug|x64.ActiveCfg = Debug|Any CPU 48 | {2D92B1BC-C931-4679-BCF7-10D9F681D201}.Debug|x64.Build.0 = Debug|Any CPU 49 | {2D92B1BC-C931-4679-BCF7-10D9F681D201}.Debug|x86.ActiveCfg = Debug|Any CPU 50 | {2D92B1BC-C931-4679-BCF7-10D9F681D201}.Debug|x86.Build.0 = Debug|Any CPU 51 | {2D92B1BC-C931-4679-BCF7-10D9F681D201}.Release|Any CPU.ActiveCfg = Release|Any CPU 52 | {2D92B1BC-C931-4679-BCF7-10D9F681D201}.Release|Any CPU.Build.0 = Release|Any CPU 53 | {2D92B1BC-C931-4679-BCF7-10D9F681D201}.Release|x64.ActiveCfg = Release|Any CPU 54 | {2D92B1BC-C931-4679-BCF7-10D9F681D201}.Release|x64.Build.0 = Release|Any CPU 55 | {2D92B1BC-C931-4679-BCF7-10D9F681D201}.Release|x86.ActiveCfg = Release|Any CPU 56 | {2D92B1BC-C931-4679-BCF7-10D9F681D201}.Release|x86.Build.0 = Release|Any CPU 57 | EndGlobalSection 58 | GlobalSection(SolutionProperties) = preSolution 59 | HideSolutionNode = FALSE 60 | EndGlobalSection 61 | GlobalSection(ExtensibilityGlobals) = postSolution 62 | SolutionGuid = {FBF5A135-B135-4B9B-8C7F-3072FC265D2F} 63 | EndGlobalSection 64 | EndGlobal 65 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/App.razor: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @if (!context.User.Identity.IsAuthenticated) 7 | { 8 | 9 | } 10 | else 11 | { 12 |

You are not authorized to access this resource.

13 | } 14 |
15 |
16 |
17 | 18 | 19 |

Sorry, there's nothing at this address.

20 |
21 |
22 |
23 |
24 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/BlazorWasmWithAADAuth.Client.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | 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 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Pages/Authentication.razor: -------------------------------------------------------------------------------- 1 | @page "/authentication/{action}" 2 | @using Microsoft.AspNetCore.Components.WebAssembly.Authentication 3 | @using Microsoft.AspNetCore.WebUtilities 4 | 5 | 6 |

There was an error login you in: @_errorMessage

7 |
8 |
9 | 10 | @code{ 11 | [Parameter] public string Action { get; set; } 12 | [Inject] NavigationManager _navigationManager { get; set; } 13 | string _errorMessage; 14 | protected override void OnParametersSet() 15 | { 16 | Uri uri = _navigationManager.ToAbsoluteUri(_navigationManager.Uri); 17 | if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("message", out var errorMessage)) 18 | { 19 | _errorMessage = errorMessage; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Pages/Counter.razor: -------------------------------------------------------------------------------- 1 | @page "/counter" 2 | 3 |

Counter

4 | 5 |

Current count: @currentCount

6 | 7 | 8 | 9 | @code { 10 | private int currentCount = 0; 11 | 12 | private void IncrementCount() 13 | { 14 | currentCount++; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Pages/FetchData.razor: -------------------------------------------------------------------------------- 1 | @page "/fetchdata" 2 | @using Microsoft.AspNetCore.Authorization 3 | @using Microsoft.AspNetCore.Components.WebAssembly.Authentication 4 | @using BlazorWasmWithAADAuth.Shared 5 | @using BlazorWasmWithAADAuth.Client.Services 6 | @using BlazorWasmWithAADAuth.Shared.models 7 | @using Newtonsoft.Json 8 | 9 | @attribute [Authorize] 10 | @inject HTTPClientBackendService _httpBackend 11 | @inject GraphHTTPClientService _httpGraphService 12 | @inject NavigationManager _navigationManager 13 | 14 |

Weather forecast

15 | 16 |

This component demonstrates fetching data from the server.

17 | 18 | @if (forecasts == null) 19 | { 20 |

Loading...

21 | } 22 | else 23 | { 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | @foreach (var forecast in forecasts) 35 | { 36 | 37 | 38 | 39 | 40 | 41 | 42 | } 43 | 44 |
DateTemp. (C)Temp. (F)Summary
@forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
45 | } 46 | 47 | 48 |
49 | 50 | 51 | 52 |
53 | 54 |
55 | 56 | 57 |
58 | @if (_requestersList == null || _requestersList.Count <= 0) 59 | { 60 |

No Allowed AAD Objects were found for this example, please add AAD Principals

61 | } 62 | else 63 | { 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | @foreach (var aADObject in _requestersList) 76 | { 77 | 78 | 79 | 80 | 81 | 82 | 83 | } 84 | 85 |
Friendly NameObject IDObject TypeDelete
@aADObject.FriendlyName@aADObject.ObjectId@aADObject.ObjectType
86 | } 87 | 88 | 89 | @code { 90 | private WeatherForecast[] forecasts; 91 | private List _requestersList { get; set; } 92 | private string _tempAutoAADObject; 93 | [Inject] IJSRuntime _jSRuntime { get; set; } 94 | 95 | protected override async Task OnInitializedAsync() 96 | { 97 | _requestersList = new List(); 98 | try 99 | { 100 | string csrfCookieValue = await _jSRuntime.InvokeAsync("getCookie", "XSRF-TOKEN"); 101 | //forecasts = await _httpBackend.CallPostAPIAsync(_navigationManager.BaseUri + "WeatherForecast", 102 | // csrfCookieValue); 103 | forecasts = await _httpBackend.CallGetApiAsync(_navigationManager.BaseUri + "WeatherForecast"); 104 | } 105 | catch (AccessTokenNotAvailableException exception) 106 | { 107 | exception.Redirect(); 108 | } 109 | } 110 | 111 | private async Task AddAutoAADObjectAsync() 112 | { 113 | if (string.IsNullOrWhiteSpace(_tempAutoAADObject)) 114 | { 115 | //TODO toast error 116 | return; 117 | } 118 | AADObjectModel newAADObj = (await _httpGraphService.VaidateAADUserGroupObjectAsync(_tempAutoAADObject)).FirstOrDefault(); 119 | var existingObject = _requestersList.FirstOrDefault(i => i.ObjectId.ToLower().Trim() == newAADObj.ObjectId.ToLower().Trim()); 120 | if (existingObject == null) 121 | { 122 | _requestersList.Add(newAADObj); 123 | } 124 | else 125 | { 126 | //Todo toast error 127 | } 128 | } 129 | 130 | private void DeleteObject(AADObjectModel aADObject) 131 | { 132 | _requestersList.Remove(aADObject); 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Pages/Index.razor: -------------------------------------------------------------------------------- 1 | @page "/" 2 | 3 |

Hello, world!

4 | 5 | Welcome to your new app. 6 | 7 | 8 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using System.Collections.Generic; 4 | using System.Threading.Tasks; 5 | using System.Text; 6 | using Microsoft.AspNetCore.Components.WebAssembly.Authentication; 7 | using Microsoft.AspNetCore.Components.WebAssembly.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.DependencyInjection; 10 | using Microsoft.Extensions.Logging; 11 | using BlazorWasmWithAADAuth.Client.Services; 12 | 13 | namespace BlazorWasmWithAADAuth.Client 14 | { 15 | public class Program 16 | { 17 | public static async Task Main(string[] args) 18 | { 19 | var builder = WebAssemblyHostBuilder.CreateDefault(args); 20 | builder.RootComponents.Add("app"); 21 | 22 | //builder.Services.AddHttpClient("BlazorWasmWithAADAuth.ServerAPI", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) 23 | // .AddHttpMessageHandler(); 24 | builder.Services.AddHttpClient("BlazorWasmWithAADAuth.ServerAPI", 25 | client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)) 26 | .AddHttpMessageHandler(); 27 | 28 | builder.Services.AddTransient(); 29 | builder.Services.AddHttpClient("BlazorWasmWithAADAuth.GraphAPI", 30 | client => client.BaseAddress = new Uri("https://graph.microsoft.com/")) 31 | .AddHttpMessageHandler(); 32 | 33 | 34 | 35 | // Supply HttpClient instances that include access tokens when making requests to the server project 36 | builder.Services.AddTransient(sp => sp.GetRequiredService().CreateClient("BlazorWasmWithAADAuth.ServerAPI")); 37 | builder.Services.AddTransient(sp => sp.GetRequiredService().CreateClient("BlazorWasmWithAADAuth.GraphAPI")); 38 | 39 | builder.Services.AddMsalAuthentication(options => 41 | { 42 | builder.Configuration.Bind("AzureAd", options.ProviderOptions.Authentication); 43 | options.ProviderOptions.DefaultAccessTokenScopes.Add("8a3cc5ba-76dc-419a-ade8-fa3534c71ae2/API.Access"); 44 | options.UserOptions.RoleClaim = "role"; 45 | }).AddAccountClaimsPrincipalFactory(); 47 | 48 | await builder.Build().RunAsync(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:40718", 7 | "sslPort": 44305 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "BlazorWasmWithAADAuth": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 23 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 24 | "environmentVariables": { 25 | "ASPNETCORE_ENVIRONMENT": "Development" 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Services/CustomAccountFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Net.Http; 3 | using System.Net.Http.Json; 4 | using System.Security.Claims; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Components.WebAssembly.Authentication; 7 | using Microsoft.AspNetCore.Components.WebAssembly.Authentication.Internal; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace BlazorWasmWithAADAuth.Client.Services 11 | { 12 | public class CustomUserFactory 13 | : AccountClaimsPrincipalFactory 14 | { 15 | private readonly ILogger logger; 16 | private readonly IHttpClientFactory clientFactory; 17 | 18 | public CustomUserFactory(IAccessTokenProviderAccessor accessor, 19 | IHttpClientFactory clientFactory, 20 | ILogger logger) 21 | : base(accessor) 22 | { 23 | this.clientFactory = clientFactory; 24 | this.logger = logger; 25 | } 26 | 27 | public async override ValueTask CreateUserAsync( 28 | CustomUserAccount account, 29 | RemoteAuthenticationUserOptions options) 30 | { 31 | var initialUser = await base.CreateUserAsync(account, options); 32 | 33 | if (initialUser.Identity.IsAuthenticated) 34 | { 35 | var userIdentity = (ClaimsIdentity)initialUser.Identity; 36 | 37 | foreach (var role in account.Roles) 38 | { 39 | userIdentity.AddClaim(new Claim("role", role)); 40 | } 41 | 42 | if (userIdentity.HasClaim(c => c.Type == "hasgroups")) 43 | { 44 | try 45 | { 46 | var client = clientFactory.CreateClient("BlazorWasmWithAADAuth.GraphAPI"); 47 | 48 | var response = await client.GetAsync("v1.0/me/memberOf"); 49 | 50 | if (response.IsSuccessStatusCode) 51 | { 52 | var userObjects = await response.Content 53 | .ReadFromJsonAsync(); 54 | 55 | foreach (var obj in userObjects?.Values) 56 | { 57 | userIdentity.AddClaim(new Claim("group", obj.Id)); 58 | } 59 | 60 | var claim = userIdentity.Claims.FirstOrDefault( 61 | c => c.Type == "hasgroups"); 62 | 63 | userIdentity.RemoveClaim(claim); 64 | } 65 | else 66 | { 67 | logger.LogError("Graph API request failure: {REASON}", 68 | response.ReasonPhrase); 69 | } 70 | } 71 | catch (AccessTokenNotAvailableException exception) 72 | { 73 | logger.LogError("Graph API access token failure: {MESSAGE}", 74 | exception.Message); 75 | } 76 | } 77 | else 78 | { 79 | foreach (var group in account.Groups) 80 | { 81 | userIdentity.AddClaim(new Claim("group", group)); 82 | } 83 | } 84 | } 85 | 86 | return initialUser; 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Services/CustomUserAccount.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | using Microsoft.AspNetCore.Components.WebAssembly.Authentication; 3 | 4 | namespace BlazorWasmWithAADAuth.Client.Services 5 | { 6 | public class CustomUserAccount : RemoteUserAccount 7 | { 8 | [JsonPropertyName("groups")] 9 | public string[] Groups { get; set; } = new string[] { }; 10 | 11 | [JsonPropertyName("roles")] 12 | public string[] Roles { get; set; } = new string[] { }; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Services/DirectoryObjects.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace BlazorWasmWithAADAuth.Client.Services 5 | { 6 | public class DirectoryObjects 7 | { 8 | [JsonPropertyName("@odata.context")] 9 | public string Context { get; set; } 10 | 11 | [JsonPropertyName("value")] 12 | public List Values { get; set; } 13 | } 14 | 15 | public class Value 16 | { 17 | [JsonPropertyName("@odata.type")] 18 | public string Type { get; set; } 19 | 20 | [JsonPropertyName("id")] 21 | public string Id { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Services/GraphCustomAuthorizationMessageHandler.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | using Microsoft.AspNetCore.Components.WebAssembly.Authentication; 3 | 4 | namespace BlazorWasmWithAADAuth.Client.Services 5 | { 6 | public class GraphCustomAuthorizationMessageHandler : AuthorizationMessageHandler 7 | { 8 | public GraphCustomAuthorizationMessageHandler(IAccessTokenProvider provider, 9 | NavigationManager navigationManager) 10 | : base(provider, navigationManager) 11 | { 12 | ConfigureHandler( 13 | authorizedUrls: new[] { "https://graph.microsoft.com/" }, 14 | scopes: new[] { "Application.Read.All", "Group.Read.All", "User.Read.All" }); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Services/GraphHTTPClientService.cs: -------------------------------------------------------------------------------- 1 | using BlazorWasmWithAADAuth.Shared.models; 2 | using Microsoft.Extensions.Logging; 3 | using Newtonsoft.Json; 4 | using Polly; 5 | using Polly.Retry; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Net; 10 | using System.Net.Http; 11 | using System.Threading.Tasks; 12 | 13 | namespace BlazorWasmWithAADAuth.Client.Services 14 | { 15 | public class GraphHTTPClientService 16 | { 17 | private readonly HttpClient _httpClient; 18 | private readonly AsyncRetryPolicy _retryPolicy; 19 | private readonly ILogger _logger; 20 | public GraphHTTPClientService(HttpClient httpClient, ILogger logger) 21 | { 22 | _logger = logger; 23 | _httpClient = httpClient; 24 | HttpStatusCode[] httpStatusCodesWorthRetrying = { 25 | HttpStatusCode.RequestTimeout, // 408 26 | HttpStatusCode.InternalServerError, // 500 27 | HttpStatusCode.BadGateway, // 502 28 | HttpStatusCode.ServiceUnavailable, // 503 29 | HttpStatusCode.GatewayTimeout // 504 30 | }; 31 | _retryPolicy = Policy 32 | .Handle() 33 | .OrInner() 34 | .OrResult(r => httpStatusCodesWorthRetrying.Contains(r.StatusCode)) 35 | .WaitAndRetryAsync(new[] 36 | { 37 | TimeSpan.FromSeconds(2), 38 | TimeSpan.FromSeconds(4), 39 | TimeSpan.FromSeconds(8) 40 | }); 41 | } 42 | 43 | public async Task> VaidateAADUserGroupObjectAsync(string aadObjectString) 44 | { 45 | List aADObjects = new List(); 46 | if (string.IsNullOrWhiteSpace(aadObjectString)) 47 | { 48 | return aADObjects; 49 | } 50 | Task> groupEqResults = ValidateGroupAsync(aadObjectString); 51 | AADObjectModel userResult = await ValidateUserAsync(aadObjectString); 52 | if (userResult.isValid) 53 | { 54 | aADObjects.Add(userResult); 55 | } 56 | aADObjects.AddRange(await groupEqResults); 57 | if (aADObjects.Count == 0) 58 | { 59 | Task> userResults = ValidateUser2ChanceAsync(aadObjectString); 60 | Task> groupResults = ValidateGroup2ChanceAsync(aadObjectString); 61 | aADObjects.AddRange(await userResults); 62 | aADObjects.AddRange(await groupResults); 63 | } 64 | return aADObjects; 65 | } 66 | 67 | private async Task ValidateUserAsync(string aadObjectString) 68 | { 69 | AADObjectModel aADObject = new AADObjectModel(); 70 | UserGraphModel userResult; 71 | if (string.IsNullOrWhiteSpace(aadObjectString)) 72 | { 73 | return new AADObjectModel() { isValid = false }; 74 | } 75 | try 76 | { 77 | string response = await CallGetApiAsync("https://graph.microsoft.com/v1.0/users/" + aadObjectString + "?$select=userPrincipalName,id"); 78 | if (response.Equals("NotFound")) 79 | { 80 | return new AADObjectModel() { isValid = false }; 81 | } 82 | else 83 | { 84 | userResult = JsonConvert.DeserializeObject(response); 85 | } 86 | aADObject.FriendlyName = userResult.UserPrincipalName; 87 | aADObject.ObjectId = userResult.Id; 88 | aADObject.ObjectType = "USER"; 89 | aADObject.isValid = true; 90 | } 91 | catch (Exception ex) 92 | { 93 | //swallow exception since it can only be that it is not the right format 94 | aADObject.isValid = false; 95 | } 96 | return aADObject; 97 | } 98 | 99 | private async Task> ValidateUser2ChanceAsync(string aadObjectString) 100 | { 101 | List aADObjects = new List(); 102 | List userResults = new List(); 103 | if (string.IsNullOrWhiteSpace(aadObjectString)) 104 | { 105 | return aADObjects; 106 | } 107 | try 108 | { 109 | 110 | string response = await CallGetApiAsync("https://graph.microsoft.com/v1.0/users?$filter=startswith(userPrincipalName,'" + aadObjectString + "')&$select=userPrincipalName,id"); 111 | if (response.Equals("NotFound")) 112 | { 113 | return aADObjects; 114 | } 115 | else 116 | { 117 | userResults = JsonConvert.DeserializeObject(response).value; 118 | } 119 | foreach (UserGraphModel userResult in userResults) 120 | { 121 | aADObjects.Add(new AADObjectModel(userResult)); 122 | } 123 | } 124 | catch (Exception ex) 125 | { 126 | //swallow exception since it can only be that it is not the right format 127 | 128 | } 129 | return aADObjects; 130 | } 131 | 132 | private async Task> ValidateGroupAsync(string aadObjectString) 133 | { 134 | List aADObjects = new List(); 135 | List groupResults; 136 | if (string.IsNullOrWhiteSpace(aadObjectString)) 137 | { 138 | return aADObjects; 139 | } 140 | try 141 | { 142 | if (Guid.TryParse(aadObjectString, out Guid x)) 143 | { 144 | string response = await CallGetApiAsync("https://graph.microsoft.com/v1.0/groups/" + aadObjectString + "'?$select=displayName,id"); 145 | if (response.Equals("NotFound")) 146 | { 147 | return aADObjects; 148 | } 149 | GroupGraphModel groupResult = JsonConvert.DeserializeObject(response); 150 | aADObjects.Add(new AADObjectModel(groupResult)); 151 | } 152 | else 153 | { 154 | string response = await CallGetApiAsync("https://graph.microsoft.com/v1.0/groups?$filter=displayName eq '" + aadObjectString + "'&$select=displayName,id"); 155 | if (response.Equals("NotFound")) 156 | { 157 | return aADObjects; 158 | } 159 | groupResults = JsonConvert.DeserializeObject(response).value; 160 | foreach (GroupGraphModel groupResult in groupResults) 161 | { 162 | aADObjects.Add(new AADObjectModel(groupResult)); 163 | } 164 | } 165 | 166 | } 167 | catch (Exception ex) 168 | { 169 | //swallow exception since it can only be that it is not the right format 170 | } 171 | return aADObjects; 172 | } 173 | 174 | private async Task> ValidateGroup2ChanceAsync(string aadObjectString) 175 | { 176 | List aADObjects = new List(); 177 | List groupResults; 178 | if (string.IsNullOrWhiteSpace(aadObjectString)) 179 | { 180 | return aADObjects; 181 | } 182 | try 183 | { 184 | string response = await CallGetApiAsync("https://graph.microsoft.com/v1.0/groups?$filter=startswith(displayName,'" + aadObjectString + "')&$select=displayName,id"); 185 | if (response.Equals("NotFound")) 186 | { 187 | return aADObjects; 188 | } 189 | else 190 | { 191 | groupResults = JsonConvert.DeserializeObject(response).value; 192 | } 193 | foreach (GroupGraphModel groupResult in groupResults) 194 | { 195 | aADObjects.Add(new AADObjectModel(groupResult)); 196 | } 197 | } 198 | catch (Exception ex) 199 | { 200 | //swallow exception since it can only be that it is not the right format 201 | } 202 | return aADObjects; 203 | } 204 | 205 | private async Task CallGetApiAsync(string url) 206 | { 207 | if (string.IsNullOrWhiteSpace(url)) 208 | { 209 | throw new ArgumentNullException("url is empty or null", nameof(url)); 210 | } 211 | ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; 212 | string responseString; 213 | try 214 | { 215 | HttpResponseMessage response; 216 | response = await _retryPolicy.ExecuteAsync(async () => 217 | await CreateAndSendGetMessageAsync(url) 218 | ); 219 | if (response.IsSuccessStatusCode) 220 | { 221 | responseString = await response.Content.ReadAsStringAsync(); 222 | 223 | } 224 | else 225 | { 226 | responseString = "NotFound"; 227 | } 228 | return responseString; 229 | } 230 | catch (Exception ex) 231 | { 232 | _logger.LogError("Error contacting Graph", ex); 233 | return ex.Message; 234 | } 235 | } 236 | 237 | private async Task CreateAndSendGetMessageAsync(string url) 238 | { 239 | HttpResponseMessage response; 240 | HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url); 241 | response = await _httpClient.SendAsync(requestMessage); 242 | return response; 243 | } 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Services/HTTPClientBackendService.cs: -------------------------------------------------------------------------------- 1 | using BlazorWasmWithAADAuth.Shared; 2 | using Newtonsoft.Json; 3 | using Polly; 4 | using Polly.Retry; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Net; 9 | using System.Net.Http; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | 13 | namespace BlazorWasmWithAADAuth.Client.Services 14 | { 15 | public class HTTPClientBackendService 16 | { 17 | private readonly HttpClient _httpClient; 18 | private readonly AsyncRetryPolicy _retryPolicy; 19 | public HTTPClientBackendService(HttpClient httpClient) 20 | { 21 | _httpClient = httpClient; 22 | HttpStatusCode[] httpStatusCodesWorthRetrying = { 23 | HttpStatusCode.RequestTimeout, // 408 24 | HttpStatusCode.InternalServerError, // 500 25 | HttpStatusCode.BadGateway, // 502 26 | HttpStatusCode.ServiceUnavailable, // 503 27 | HttpStatusCode.GatewayTimeout // 504 28 | }; 29 | _retryPolicy = Policy 30 | .Handle() 31 | .OrInner() 32 | .OrResult(r => httpStatusCodesWorthRetrying.Contains(r.StatusCode)) 33 | .WaitAndRetryAsync(new[] 34 | { 35 | TimeSpan.FromSeconds(2), 36 | TimeSpan.FromSeconds(4), 37 | TimeSpan.FromSeconds(8) 38 | }); 39 | } 40 | 41 | public async Task CallGetApiAsync(string url) 42 | { 43 | if (string.IsNullOrWhiteSpace(url)) 44 | { 45 | throw new ArgumentNullException("url is empty or null", nameof(url)); 46 | } 47 | WeatherForecast[] weatherForecasts = new WeatherForecast[0]; 48 | ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; 49 | try 50 | { 51 | HttpResponseMessage response; 52 | response = await _retryPolicy.ExecuteAsync(async () => 53 | await CreateAndSendGetMessageAsync(url) 54 | ); 55 | weatherForecasts = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); 56 | } 57 | catch (Exception ex) 58 | { 59 | //TODO handle error 60 | } 61 | return weatherForecasts; 62 | } 63 | 64 | public async Task CallPostAPIAsync(string url, string csrfCookieValue, string jsonPayload = null) 65 | { 66 | if (string.IsNullOrWhiteSpace(url)) 67 | { 68 | throw new ArgumentNullException("url is empty or null", nameof(url)); 69 | } 70 | WeatherForecast[] weatherForecasts = new WeatherForecast[0]; 71 | ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; 72 | try 73 | { 74 | HttpResponseMessage response; 75 | HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, url); 76 | if (!string.IsNullOrWhiteSpace(csrfCookieValue)) 77 | { 78 | requestMessage.Headers.Add("X-CSRF-TOKEN", csrfCookieValue); 79 | } 80 | if(!string.IsNullOrWhiteSpace(jsonPayload)) 81 | { 82 | requestMessage.Content = new StringContent(jsonPayload, 83 | Encoding.UTF8, "application/json"); 84 | } 85 | response = await _retryPolicy.ExecuteAsync(async () => 86 | await SendMessageAsync(requestMessage) 87 | ); 88 | weatherForecasts = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); 89 | } 90 | catch (Exception ex) 91 | { 92 | //TODO handle error 93 | } 94 | return weatherForecasts; 95 | } 96 | 97 | private async Task SendMessageAsync(HttpRequestMessage requestMessage) 98 | { 99 | HttpResponseMessage response; 100 | response = await _httpClient.SendAsync(requestMessage); 101 | return response; 102 | } 103 | 104 | private async Task CreateAndSendGetMessageAsync(string url) 105 | { 106 | HttpResponseMessage response; 107 | HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url); 108 | response = await _httpClient.SendAsync(requestMessage); 109 | return response; 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Shared/LoginDisplay.razor: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Components.Authorization 2 | @using Microsoft.AspNetCore.Components.WebAssembly.Authentication 3 | 4 | @inject NavigationManager Navigation 5 | @inject SignOutSessionStateManager SignOutManager 6 | 7 | 8 | 9 | Hello, @context.User.Identity.Name! 10 | 11 | 12 | 13 | Log in 14 | 15 | 16 | 17 | @code{ 18 | private async Task BeginLogout(MouseEventArgs args) 19 | { 20 | await SignOutManager.SetSignOutState(); 21 | Navigation.NavigateTo("authentication/logout"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | 3 | 6 | 7 |
8 |
9 | 10 | About 11 |
12 | 13 |
14 | @Body 15 |
16 |
17 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Shared/NavMenu.razor: -------------------------------------------------------------------------------- 1 |  7 | 8 |
9 | 29 |
30 | 31 | @code { 32 | private bool collapseNavMenu = true; 33 | 34 | private string NavMenuCssClass => collapseNavMenu ? "collapse" : null; 35 | 36 | private void ToggleNavMenu() 37 | { 38 | collapseNavMenu = !collapseNavMenu; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Shared/RedirectToLogin.razor: -------------------------------------------------------------------------------- 1 | @inject NavigationManager Navigation 2 | @using Microsoft.AspNetCore.Components.WebAssembly.Authentication 3 | @code { 4 | protected override void OnInitialized() 5 | { 6 | Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/Shared/SurveyPrompt.razor: -------------------------------------------------------------------------------- 1 |  11 | 12 | @code { 13 | // Demonstrates how a parent component can supply parameters 14 | [Parameter] 15 | public string Title { get; set; } 16 | } 17 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/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.WebAssembly.Http 8 | @using Microsoft.JSInterop 9 | @using BlazorWasmWithAADAuth.Client 10 | @using BlazorWasmWithAADAuth.Client.Shared 11 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/wwwroot/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AzureAd": { 3 | "Authority": "https://login.microsoftonline.com/common", 4 | "ClientId": "eac6e5e0-04a5-4ecf-8f8e-38477e3d6b7a", 5 | "ValidateAuthority": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/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 | a, .btn-link { 8 | color: #0366d6; 9 | } 10 | 11 | .btn-primary { 12 | color: #fff; 13 | background-color: #1b6ec2; 14 | border-color: #1861ac; 15 | } 16 | 17 | app { 18 | position: relative; 19 | display: flex; 20 | flex-direction: column; 21 | } 22 | 23 | .top-row { 24 | height: 3.5rem; 25 | display: flex; 26 | align-items: center; 27 | } 28 | 29 | .main { 30 | flex: 1; 31 | } 32 | 33 | .main .top-row { 34 | background-color: #f7f7f7; 35 | border-bottom: 1px solid #d6d5d5; 36 | justify-content: flex-end; 37 | } 38 | 39 | .main .top-row > a, .main .top-row .btn-link { 40 | white-space: nowrap; 41 | margin-left: 1.5rem; 42 | } 43 | 44 | .main .top-row a:first-child { 45 | overflow: hidden; 46 | text-overflow: ellipsis; 47 | } 48 | 49 | .sidebar { 50 | background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); 51 | } 52 | 53 | .sidebar .top-row { 54 | background-color: rgba(0,0,0,0.4); 55 | } 56 | 57 | .sidebar .navbar-brand { 58 | font-size: 1.1rem; 59 | } 60 | 61 | .sidebar .oi { 62 | width: 2rem; 63 | font-size: 1.1rem; 64 | vertical-align: text-top; 65 | top: -2px; 66 | } 67 | 68 | .sidebar .nav-item { 69 | font-size: 0.9rem; 70 | padding-bottom: 0.5rem; 71 | } 72 | 73 | .sidebar .nav-item:first-of-type { 74 | padding-top: 1rem; 75 | } 76 | 77 | .sidebar .nav-item:last-of-type { 78 | padding-bottom: 1rem; 79 | } 80 | 81 | .sidebar .nav-item a { 82 | color: #d7d7d7; 83 | border-radius: 4px; 84 | height: 3rem; 85 | display: flex; 86 | align-items: center; 87 | line-height: 3rem; 88 | } 89 | 90 | .sidebar .nav-item a.active { 91 | background-color: rgba(255,255,255,0.25); 92 | color: white; 93 | } 94 | 95 | .sidebar .nav-item a:hover { 96 | background-color: rgba(255,255,255,0.1); 97 | color: white; 98 | } 99 | 100 | .content { 101 | padding-top: 1.1rem; 102 | } 103 | 104 | .navbar-toggler { 105 | background-color: rgba(255, 255, 255, 0.1); 106 | } 107 | 108 | .valid.modified:not([type=checkbox]) { 109 | outline: 1px solid #26b050; 110 | } 111 | 112 | .invalid { 113 | outline: 1px solid red; 114 | } 115 | 116 | .validation-message { 117 | color: red; 118 | } 119 | 120 | #blazor-error-ui { 121 | background: lightyellow; 122 | bottom: 0; 123 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); 124 | display: none; 125 | left: 0; 126 | padding: 0.6rem 1.25rem 0.7rem 1.25rem; 127 | position: fixed; 128 | width: 100%; 129 | z-index: 1000; 130 | } 131 | 132 | #blazor-error-ui .dismiss { 133 | cursor: pointer; 134 | position: absolute; 135 | right: 0.75rem; 136 | top: 0.5rem; 137 | } 138 | 139 | @media (max-width: 767.98px) { 140 | .main .top-row:not(.auth) { 141 | display: none; 142 | } 143 | 144 | .main .top-row.auth { 145 | justify-content: space-between; 146 | } 147 | 148 | .main .top-row a, .main .top-row .btn-link { 149 | margin-left: 0; 150 | } 151 | } 152 | 153 | @media (min-width: 768px) { 154 | app { 155 | flex-direction: row; 156 | } 157 | 158 | .sidebar { 159 | width: 250px; 160 | height: 100vh; 161 | position: sticky; 162 | top: 0; 163 | } 164 | 165 | .main .top-row { 166 | position: sticky; 167 | top: 0; 168 | } 169 | 170 | .main > div { 171 | padding-left: 2rem !important; 172 | padding-right: 1.5rem !important; 173 | } 174 | 175 | .navbar-toggler { 176 | display: none; 177 | } 178 | 179 | .sidebar .collapse { 180 | /* Never collapse the sidebar for wide screens */ 181 | display: block; 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/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 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/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. -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/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 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/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'} -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-flamingo/BlazorWasmWithAADAuth/c0ec2a35b9ed8a496efb4612f9d5162a7422d4a3/BlazorWasmWithAADAuth/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.eot -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-flamingo/BlazorWasmWithAADAuth/c0ec2a35b9ed8a496efb4612f9d5162a7422d4a3/BlazorWasmWithAADAuth/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.otf -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/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 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-flamingo/BlazorWasmWithAADAuth/c0ec2a35b9ed8a496efb4612f9d5162a7422d4a3/BlazorWasmWithAADAuth/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-flamingo/BlazorWasmWithAADAuth/c0ec2a35b9ed8a496efb4612f9d5162a7422d4a3/BlazorWasmWithAADAuth/Client/wwwroot/css/open-iconic/font/fonts/open-iconic.woff -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-flamingo/BlazorWasmWithAADAuth/c0ec2a35b9ed8a496efb4612f9d5162a7422d4a3/BlazorWasmWithAADAuth/Client/wwwroot/favicon.ico -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/wwwroot/getcookie.js: -------------------------------------------------------------------------------- 1 | function getCookie(cname) { 2 | var decodedCookie = decodeURIComponent(document.cookie); 3 | var ca = decodedCookie.split(';'); 4 | for (var i = 0; i < ca.length; i++) { 5 | var arr = ca[i].split('='); 6 | if (arr[0] == cname) 7 | return arr[1] 8 | } 9 | return ""; 10 | } -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Client/wwwroot/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | BlazorWasmWithAADAuth 8 | 9 | 10 | 11 | 12 | 13 | 14 | Loading... 15 | 16 |
17 | An unhandled error has occurred. 18 | Reload 19 | 🗙 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Server/BlazorWasmWithAADAuth.Server.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | BlazorWasmWithAADAuth.Server-94FFA1CF-62F9-4AD1-B379-0F47F24D0B8A 6 | 0 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Server/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using BlazorWasmWithAADAuth.Shared; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Authorization; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace BlazorWasmWithAADAuth.Server.Controllers 11 | { 12 | [Authorize] 13 | [ApiController] 14 | [Route("[controller]")] 15 | public class WeatherForecastController : ControllerBase 16 | { 17 | private static readonly string[] Summaries = new[] 18 | { 19 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 20 | }; 21 | 22 | private readonly ILogger logger; 23 | 24 | public WeatherForecastController(ILogger logger) 25 | { 26 | this.logger = logger; 27 | } 28 | 29 | [HttpGet] 30 | public IEnumerable Get() 31 | { 32 | var rng = new Random(); 33 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 34 | { 35 | Date = DateTime.Now.AddDays(index), 36 | TemperatureC = rng.Next(-20, 55), 37 | Summary = Summaries[rng.Next(Summaries.Length)] 38 | }) 39 | .ToArray(); 40 | } 41 | [ValidateAntiForgeryToken] 42 | [HttpPost] 43 | public IEnumerable Post() 44 | { 45 | var rng = new Random(); 46 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 47 | { 48 | Date = DateTime.Now.AddDays(index), 49 | TemperatureC = rng.Next(-20, 55), 50 | Summary = Summaries[rng.Next(Summaries.Length)] 51 | }) 52 | .ToArray(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Server/Pages/Error.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model BlazorWasmWithAADAuth.Server.Pages.ErrorModel 3 | @{ 4 | Layout = "_Layout"; 5 | ViewData["Title"] = "Error"; 6 | } 7 | 8 |

Error.

9 |

An error occurred while processing your request.

10 | 11 | @if (Model.ShowRequestId) 12 | { 13 |

14 | Request ID: @Model.RequestId 15 |

16 | } 17 | 18 |

Development Mode

19 |

20 | Swapping to the Development environment displays detailed information about the error that occurred. 21 |

22 |

23 | The Development environment shouldn't be enabled for deployed applications. 24 | It can result in displaying sensitive information from exceptions to end users. 25 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 26 | and restarting the app. 27 |

28 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Server/Pages/Error.cshtml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.AspNetCore.Mvc.RazorPages; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace BlazorWasmWithAADAuth.Server.Pages 11 | { 12 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 13 | public class ErrorModel : PageModel 14 | { 15 | public string RequestId { get; set; } 16 | 17 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 18 | 19 | private readonly ILogger _logger; 20 | 21 | public ErrorModel(ILogger logger) 22 | { 23 | _logger = logger; 24 | } 25 | 26 | public void OnGet() 27 | { 28 | RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Server/Pages/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | @ViewBag.Title 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | @RenderBody() 16 |
17 |
18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Server/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace BlazorWasmWithAADAuth.Server 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Server/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:40718", 7 | "sslPort": 44305 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "BlazorWasmWithAADAuth.Server": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 23 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 24 | "environmentVariables": { 25 | "ASPNETCORE_ENVIRONMENT": "Development" 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Server/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authentication; 2 | using Microsoft.AspNetCore.Authentication.AzureAD.UI; 3 | using Microsoft.AspNetCore.Builder; 4 | using Microsoft.AspNetCore.HttpsPolicy; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.AspNetCore.ResponseCompression; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | using System.Linq; 11 | using System.Collections.Generic; 12 | using Microsoft.AspNetCore.Authentication.JwtBearer; 13 | using Microsoft.IdentityModel.Tokens; 14 | using Microsoft.AspNetCore.Antiforgery; 15 | using Microsoft.AspNetCore.Http; 16 | 17 | namespace BlazorWasmWithAADAuth.Server 18 | { 19 | public class Startup 20 | { 21 | public Startup(IConfiguration configuration) 22 | { 23 | Configuration = configuration; 24 | } 25 | 26 | public IConfiguration Configuration { get; } 27 | 28 | // This method gets called by the runtime. Use this method to add services to the container. 29 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 30 | public void ConfigureServices(IServiceCollection services) 31 | { 32 | List validIssuers = new List(); 33 | validIssuers.AddRange(Configuration["AzureAd:ValidIssuers"].Split(',').ToList()); 34 | services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) 35 | .AddJwtBearer(options => 36 | { 37 | options.Authority = "https://login.microsoftonline.com/common"; 38 | options.Audience = Configuration["AzureAd:ClientId"]; 39 | options.RequireHttpsMetadata = true; 40 | options.TokenValidationParameters = new TokenValidationParameters() 41 | { 42 | ValidateIssuer = true, 43 | ValidateAudience = true, 44 | ValidateLifetime = true, 45 | ValidateIssuerSigningKey = true, 46 | ValidIssuers = validIssuers 47 | 48 | }; 49 | }); 50 | 51 | services.AddControllersWithViews(); 52 | services.AddRazorPages(); 53 | } 54 | 55 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 56 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IAntiforgery antiforgery) 57 | { 58 | if (env.IsDevelopment()) 59 | { 60 | app.UseDeveloperExceptionPage(); 61 | app.UseWebAssemblyDebugging(); 62 | } 63 | else 64 | { 65 | app.UseExceptionHandler("/Error"); 66 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. 67 | app.UseHsts(); 68 | } 69 | 70 | app.UseHttpsRedirection(); 71 | app.UseBlazorFrameworkFiles(); 72 | app.UseStaticFiles(); 73 | app.Use(async (context, next) => 74 | { 75 | context.Response.Headers.Add("X-Frame-Options", "SAMEORIGIN"); 76 | context.Response.Headers.Add("X-Content-Type-Options", "nosniff"); 77 | context.Response.Headers.Add("Referrer-Policy", "same-origin"); 78 | context.Response.Headers.Add("Permissions-Policy", "geolocation=(), camera=()"); 79 | context.Response.Headers.Add(Configuration["ContentPolicy"], "default-src " + 80 | "self " + 81 | "https://maxcdn.bootstrapcdn.com " + 82 | "https://login.microsoftonline.com " + 83 | "https://sshmantest.azurewebsites.net " + 84 | "https://code.jquery.com https://dc.services.visualstudio.com " + 85 | " 'unsafe-inline' 'unsafe-eval'"); 86 | context.Response.Headers.Add("SameSite", "Strict"); 87 | context.Response.Headers.Add("X-XSS-Protection", "1; mode=block"); 88 | await next(); 89 | }); 90 | app.UseRouting(); 91 | 92 | app.UseAuthentication(); 93 | app.UseAuthorization(); 94 | app.UseEndpoints(endpoints => 95 | { 96 | endpoints.MapRazorPages(); 97 | endpoints.MapControllers(); 98 | endpoints.MapFallbackToFile("index.html"); 99 | }); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Server/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Server/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AzureAd": { 3 | "Instance": "https://login.microsoftonline.com/", 4 | "Domain": "codingflamingogmail.onmicrosoft.com", 5 | "TenantId": "common", 6 | "ClientId": "8a3cc5ba-76dc-419a-ade8-fa3534c71ae2", 7 | "ValidIssuers": "https://sts.windows.net/1c3c6cea-fcbd-4681-85e1-74fb74b6863e/,https://sts.windows.net/fb544f4b-a0cf-413e-bd78-b61db28fe081/" 8 | }, 9 | "Logging": { 10 | "LogLevel": { 11 | "Default": "Information", 12 | "Microsoft": "Warning", 13 | "Microsoft.Hosting.Lifetime": "Information" 14 | } 15 | }, 16 | "ContentPolicy": "Content-Security-Policy-Report-Only", 17 | "AllowedHosts": "*" 18 | } 19 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Shared/BlazorWasmWithAADAuth.Shared.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Shared/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BlazorWasmWithAADAuth.Shared 6 | { 7 | public class WeatherForecast 8 | { 9 | public DateTime Date { get; set; } 10 | 11 | public int TemperatureC { get; set; } 12 | 13 | public string Summary { get; set; } 14 | 15 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Shared/models/AADObjectModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BlazorWasmWithAADAuth.Shared.models 6 | { 7 | public class AADObjectModel 8 | { 9 | public AADObjectModel() 10 | { 11 | } 12 | 13 | public AADObjectModel(UserGraphModel userGraph) 14 | { 15 | ObjectId = userGraph.Id; 16 | FriendlyName = userGraph.UserPrincipalName; 17 | isValid = true; 18 | ObjectType = "USER"; 19 | } 20 | 21 | public AADObjectModel(GroupGraphModel groupGraph) 22 | { 23 | ObjectId = groupGraph.Id; 24 | FriendlyName = groupGraph.DisplayName; 25 | isValid = true; 26 | ObjectType = "GROUP"; 27 | } 28 | public string ObjectId { get; set; } 29 | public string FriendlyName { get; set; } 30 | public string ObjectType { get; set; } 31 | public bool isValid { get; set; } = false;// group, user, SP 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Shared/models/GroupGraphModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BlazorWasmWithAADAuth.Shared.models 6 | { 7 | public class GroupGraphModel 8 | { 9 | public string DisplayName { get; set; } 10 | public string Id { get; set; } 11 | } 12 | 13 | public class GroupListGraphModel 14 | { 15 | public List value { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BlazorWasmWithAADAuth/Shared/models/UserGraphModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BlazorWasmWithAADAuth.Shared.models 6 | { 7 | public class UserGraphModel 8 | { 9 | public string UserPrincipalName { get; set; } 10 | public string Id { get; set; } 11 | } 12 | 13 | public class UserListGraphModel 14 | { 15 | public List value { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Coding Flamingo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Quick Overview 2 | All the repos under coding flamingo are the code used in my Youtube channel: https://www.youtube.com/channel/UCjGgqULI1EX0VEoizrD6PYA 3 | # BlazorWasmWithAADAuth 4 | 1. This tutorial we look at creating a Blazor Wasm Application with AAD authentication 5 | --------------------------------------------------------------------------------