├── Angular
├── angular-app
│ ├── src
│ │ ├── assets
│ │ │ └── .gitkeep
│ │ ├── app
│ │ │ ├── app.component.css
│ │ │ ├── app.component.html
│ │ │ ├── app-routing.module.ts
│ │ │ ├── app.component.ts
│ │ │ ├── app.component.spec.ts
│ │ │ └── app.module.ts
│ │ ├── styles.css
│ │ ├── environments
│ │ │ ├── environment.prod.ts
│ │ │ └── environment.ts
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ ├── main.ts
│ │ ├── test.ts
│ │ └── polyfills.ts
│ ├── e2e
│ │ ├── tsconfig.json
│ │ ├── src
│ │ │ ├── app.po.ts
│ │ │ └── app.e2e-spec.ts
│ │ └── protractor.conf.js
│ ├── tsconfig.app.json
│ ├── .editorconfig
│ ├── tsconfig.spec.json
│ ├── browserslist
│ ├── tsconfig.json
│ ├── .gitignore
│ ├── README.md
│ ├── karma.conf.js
│ ├── package.json
│ └── tslint.json
├── Angular.csproj
└── package-lock.json
├── Basics
├── Views
│ └── Home
│ │ ├── Secret.cshtml
│ │ └── Index.cshtml
├── Pages
│ ├── RazorSecured
│ │ ├── Anon.cshtml
│ │ ├── Index.cshtml
│ │ ├── Anon.cshtml.cs
│ │ └── Index.cshtml.cs
│ └── Razor
│ │ ├── Policy.cshtml
│ │ ├── Secured.cshtml
│ │ ├── Index.cshtml
│ │ ├── Index.cshtml.cs
│ │ ├── Policy.cshtml.cs
│ │ └── Secured.cshtml.cs
├── Basics.csproj
├── appsettings.Development.json
├── appsettings.json
├── Transformer
│ └── ClaimsTransformation.cs
├── Properties
│ └── launchSettings.json
├── Program.cs
├── AuthorizationRequirements
│ └── CustomRequireClaim.cs
├── Controllers
│ ├── OperationsController.cs
│ └── HomeController.cs
└── CustomPolicyProvider
│ └── CustomAuthorizationPolicyProvider.cs
├── MvcClient
├── Views
│ └── Home
│ │ ├── Index.cshtml
│ │ └── Secret.cshtml
├── appsettings.Development.json
├── appsettings.json
├── MvcClient.csproj
├── Properties
│ └── launchSettings.json
├── Program.cs
├── Startup.cs
└── Controllers
│ └── HomeController.cs
├── Client
├── Views
│ └── Home
│ │ ├── Secret.cshtml
│ │ └── Index.cshtml
├── appsettings.Development.json
├── appsettings.json
├── Client.csproj
├── Properties
│ └── launchSettings.json
├── Program.cs
└── Startup.cs
├── IdentityExample
├── Views
│ └── Home
│ │ ├── Index.cshtml
│ │ ├── Secret.cshtml
│ │ ├── EmailVerification.cshtml
│ │ ├── VerifyEmail.cshtml
│ │ ├── Login.cshtml
│ │ └── Register.cshtml
├── appsettings.Development.json
├── appsettings.json
├── Data
│ └── AppDbContext.cs
├── IdentityExample.csproj
├── Properties
│ └── launchSettings.json
├── Program.cs
├── Startup.cs
└── Controllers
│ └── HomeController.cs
├── Server
├── Views
│ ├── Home
│ │ ├── Secret.cshtml
│ │ └── Index.cshtml
│ └── OAuth
│ │ └── Authorize.cshtml
├── appsettings.Development.json
├── appsettings.json
├── Constants.cs
├── Controllers
│ ├── SecretController.cs
│ ├── HomeController.cs
│ └── OAuthController.cs
├── Server.csproj
├── Properties
│ └── launchSettings.json
├── Program.cs
└── Startup.cs
├── flutter_app
├── ios
│ ├── Flutter
│ │ ├── Debug.xcconfig
│ │ ├── Release.xcconfig
│ │ └── AppFrameworkInfo.plist
│ ├── Runner
│ │ ├── Runner-Bridging-Header.h
│ │ ├── Assets.xcassets
│ │ │ ├── LaunchImage.imageset
│ │ │ │ ├── LaunchImage.png
│ │ │ │ ├── LaunchImage@2x.png
│ │ │ │ ├── LaunchImage@3x.png
│ │ │ │ ├── README.md
│ │ │ │ └── Contents.json
│ │ │ └── AppIcon.appiconset
│ │ │ │ ├── Icon-App-20x20@1x.png
│ │ │ │ ├── Icon-App-20x20@2x.png
│ │ │ │ ├── Icon-App-20x20@3x.png
│ │ │ │ ├── Icon-App-29x29@1x.png
│ │ │ │ ├── Icon-App-29x29@2x.png
│ │ │ │ ├── Icon-App-29x29@3x.png
│ │ │ │ ├── Icon-App-40x40@1x.png
│ │ │ │ ├── Icon-App-40x40@2x.png
│ │ │ │ ├── Icon-App-40x40@3x.png
│ │ │ │ ├── Icon-App-60x60@2x.png
│ │ │ │ ├── Icon-App-60x60@3x.png
│ │ │ │ ├── Icon-App-76x76@1x.png
│ │ │ │ ├── Icon-App-76x76@2x.png
│ │ │ │ ├── Icon-App-1024x1024@1x.png
│ │ │ │ ├── Icon-App-83.5x83.5@2x.png
│ │ │ │ └── Contents.json
│ │ ├── AppDelegate.swift
│ │ ├── Base.lproj
│ │ │ ├── Main.storyboard
│ │ │ └── LaunchScreen.storyboard
│ │ └── Info.plist
│ ├── Runner.xcworkspace
│ │ └── contents.xcworkspacedata
│ ├── Runner.xcodeproj
│ │ ├── project.xcworkspace
│ │ │ └── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ └── Runner.xcscheme
│ └── .gitignore
├── android
│ ├── gradle.properties
│ ├── .gitignore
│ ├── app
│ │ ├── src
│ │ │ ├── main
│ │ │ │ ├── res
│ │ │ │ │ ├── mipmap-hdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── values
│ │ │ │ │ │ └── styles.xml
│ │ │ │ │ └── drawable
│ │ │ │ │ │ └── launch_background.xml
│ │ │ │ ├── kotlin
│ │ │ │ │ └── com
│ │ │ │ │ │ └── example
│ │ │ │ │ │ └── flutter_app
│ │ │ │ │ │ └── MainActivity.kt
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── profile
│ │ │ │ └── AndroidManifest.xml
│ │ └── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ └── gradle-wrapper.properties
│ ├── settings.gradle
│ └── build.gradle
├── .metadata
├── README.md
├── .gitignore
├── test
│ └── widget_test.dart
├── pubspec.yaml
└── lib
│ └── main.dart
├── IdentityServer
├── Views
│ ├── _ViewImports.cshtml
│ └── Auth
│ │ ├── ExternalRegister.cshtml
│ │ ├── Register.cshtml
│ │ └── Login.cshtml
├── appsettings.Development.json
├── Controllers
│ ├── ExternalRegisterViewModel.cs
│ ├── LoginViewModel.cs
│ └── RegisterViewModel.cs
├── Data
│ ├── AppDbContext.cs
│ └── Migrations
│ │ └── IdentityServer
│ │ └── PersistedGrantDb
│ │ └── 20191201205312_InitialIdentityServerPersistedGrantDbMigration.cs
├── appsettings.json
├── db-scripts.txt
├── Properties
│ └── launchSettings.json
├── IdentityServer.csproj
├── tempkey.rsa
└── Program.cs
├── XamarinApp
├── XamarinApp
│ ├── AssemblyInfo.cs
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── MainPage.xaml
│ ├── XamarinApp.csproj
│ └── MainPage.xaml.cs
└── XamarinApp.Android
│ ├── Resources
│ ├── mipmap-hdpi
│ │ ├── icon.png
│ │ └── launcher_foreground.png
│ ├── mipmap-mdpi
│ │ ├── icon.png
│ │ └── launcher_foreground.png
│ ├── mipmap-xhdpi
│ │ ├── icon.png
│ │ └── launcher_foreground.png
│ ├── mipmap-xxhdpi
│ │ ├── icon.png
│ │ └── launcher_foreground.png
│ ├── mipmap-xxxhdpi
│ │ ├── icon.png
│ │ └── launcher_foreground.png
│ ├── xml
│ │ └── network_security_config.xml
│ ├── mipmap-anydpi-v26
│ │ ├── icon.xml
│ │ └── icon_round.xml
│ ├── values
│ │ ├── colors.xml
│ │ └── styles.xml
│ ├── layout
│ │ ├── Toolbar.xml
│ │ └── Tabbar.xml
│ └── AboutResources.txt
│ ├── Properties
│ ├── AndroidManifest.xml
│ └── AssemblyInfo.cs
│ ├── Assets
│ └── AboutAssets.txt
│ ├── OidcCallbackActivity.cs
│ ├── MainActivity.cs
│ └── ChromeCustomTabsBrowser.cs
├── Api
├── Api.csproj
├── appsettings.Development.json
├── appsettings.json
├── Controllers
│ └── SecretController.cs
├── Properties
│ └── launchSettings.json
├── Program.cs
├── CustomeAuthenticationHandler.cs
├── AuthRequirement
│ └── JwtRequirement.cs
└── Startup.cs
├── README.md
├── ApiOne
├── appsettings.Development.json
├── appsettings.json
├── ApiOne.csproj
├── Controllers
│ └── SecretController.cs
├── Properties
│ └── launchSettings.json
├── Program.cs
└── Startup.cs
├── ApiTwo
├── appsettings.Development.json
├── appsettings.json
├── ApiTwo.csproj
├── Properties
│ └── launchSettings.json
├── Program.cs
├── Startup.cs
└── Controllers
│ └── HomeController.cs
├── JavascriptClient
├── appsettings.Development.json
├── appsettings.json
├── JavascriptClient.csproj
├── Controllers
│ └── HomeController.cs
├── wwwroot
│ ├── js-old
│ │ ├── sign-in-callback.js
│ │ └── sign-in.js
│ └── main.js
├── Views
│ └── Home
│ │ ├── Index.cshtml
│ │ └── SignIn.cshtml
├── Properties
│ └── launchSettings.json
├── Program.cs
└── Startup.cs
├── WpfApp
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ ├── AssemblyInfo.cs
│ └── Resources.Designer.cs
├── App.xaml
├── App.xaml.cs
├── App.config
├── MainWindow.xaml
├── packages.config
├── MainWindow.xaml.cs
└── WpfEmbeddedBrowser.cs
└── .gitattributes
/Angular/angular-app/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Angular/angular-app/src/app/app.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Basics/Views/Home/Secret.cshtml:
--------------------------------------------------------------------------------
1 |
Secret Page
--------------------------------------------------------------------------------
/MvcClient/Views/Home/Index.cshtml:
--------------------------------------------------------------------------------
1 | Home Page
--------------------------------------------------------------------------------
/Client/Views/Home/Secret.cshtml:
--------------------------------------------------------------------------------
1 | Client Secret Page
--------------------------------------------------------------------------------
/IdentityExample/Views/Home/Index.cshtml:
--------------------------------------------------------------------------------
1 | Home Page
--------------------------------------------------------------------------------
/MvcClient/Views/Home/Secret.cshtml:
--------------------------------------------------------------------------------
1 | Secret Page
--------------------------------------------------------------------------------
/Server/Views/Home/Secret.cshtml:
--------------------------------------------------------------------------------
1 | Server Secret Page
--------------------------------------------------------------------------------
/Client/Views/Home/Index.cshtml:
--------------------------------------------------------------------------------
1 | Client Home Page
2 |
--------------------------------------------------------------------------------
/IdentityExample/Views/Home/Secret.cshtml:
--------------------------------------------------------------------------------
1 | Secret Page
--------------------------------------------------------------------------------
/Server/Views/Home/Index.cshtml:
--------------------------------------------------------------------------------
1 | Server Home Page
2 |
--------------------------------------------------------------------------------
/flutter_app/ios/Flutter/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/flutter_app/ios/Flutter/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Runner-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | #import "GeneratedPluginRegistrant.h"
--------------------------------------------------------------------------------
/Basics/Pages/RazorSecured/Anon.cshtml:
--------------------------------------------------------------------------------
1 | @page
2 | @model Basics.Pages.RazorSecured.AnonModel
3 | @{
4 | }
5 |
--------------------------------------------------------------------------------
/Basics/Pages/RazorSecured/Index.cshtml:
--------------------------------------------------------------------------------
1 | @page
2 | @model Basics.Pages.RazorSecured.IndexModel
3 | @{
4 | }
5 |
--------------------------------------------------------------------------------
/Angular/angular-app/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
--------------------------------------------------------------------------------
/Angular/angular-app/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/IdentityExample/Views/Home/EmailVerification.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Email has been sent
4 | Please verify it.
--------------------------------------------------------------------------------
/IdentityServer/Views/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 | @using IdentityServer.Controllers
2 | @addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers"
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using Xamarin.Forms.Xaml;
2 |
3 | [assembly: XamlCompilation(XamlCompilationOptions.Compile)]
--------------------------------------------------------------------------------
/Angular/angular-app/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/Angular/angular-app/src/favicon.ico
--------------------------------------------------------------------------------
/Basics/Pages/Razor/Policy.cshtml:
--------------------------------------------------------------------------------
1 | @page
2 | @model Basics.Pages.Razor.PolicyModel
3 | @{
4 | }
5 |
6 | Secured by a policy Admin
--------------------------------------------------------------------------------
/Basics/Pages/Razor/Secured.cshtml:
--------------------------------------------------------------------------------
1 | @page
2 | @model Basics.Pages.Razor.SecuredModel
3 | @{
4 | }
5 |
6 | This is a secured page.
--------------------------------------------------------------------------------
/flutter_app/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 | android.enableR8=true
3 | android.useAndroidX=true
4 | android.enableJetifier=true
5 |
--------------------------------------------------------------------------------
/Angular/angular-app/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Basics/Pages/Razor/Index.cshtml:
--------------------------------------------------------------------------------
1 | @page
2 | @model Basics.Pages.Razor.IndexModel
3 | @{
4 | }
5 |
6 | Index page, anone can visit this inside public folder.
--------------------------------------------------------------------------------
/IdentityExample/Views/Home/VerifyEmail.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Thank you for verifying your email please login here
4 | Go to Login
--------------------------------------------------------------------------------
/flutter_app/android/.gitignore:
--------------------------------------------------------------------------------
1 | gradle-wrapper.jar
2 | /.gradle
3 | /captures/
4 | /gradlew
5 | /gradlew.bat
6 | /local.properties
7 | GeneratedPluginRegistrant.java
8 |
--------------------------------------------------------------------------------
/Api/Api.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Basics/Basics.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/mipmap-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/XamarinApp/XamarinApp.Android/Resources/mipmap-hdpi/icon.png
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/mipmap-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/XamarinApp/XamarinApp.Android/Resources/mipmap-mdpi/icon.png
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/mipmap-xhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/XamarinApp/XamarinApp.Android/Resources/mipmap-xhdpi/icon.png
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/mipmap-xxhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/XamarinApp/XamarinApp.Android/Resources/mipmap-xxhdpi/icon.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # aspnetcore3 Authentication Tutorial
2 |
3 | This repo is for my Youtube tutorial that can be found here: https://www.youtube.com/playlist?list=PLOeFnOV9YBa7dnrjpOG6lMpcyd7Wn7E8V
4 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/mipmap-xxxhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/XamarinApp/XamarinApp.Android/Resources/mipmap-xxxhdpi/icon.png
--------------------------------------------------------------------------------
/flutter_app/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/flutter_app/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/flutter_app/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/flutter_app/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/flutter_app/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Api/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ApiOne/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ApiTwo/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Basics/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Client/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Server/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/MvcClient/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/mipmap-hdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/XamarinApp/XamarinApp.Android/Resources/mipmap-hdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/mipmap-mdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/XamarinApp/XamarinApp.Android/Resources/mipmap-mdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/mipmap-xhdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/XamarinApp/XamarinApp.Android/Resources/mipmap-xhdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/mipmap-xxhdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/XamarinApp/XamarinApp.Android/Resources/mipmap-xxhdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
--------------------------------------------------------------------------------
/Angular/Angular.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/IdentityExample/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/IdentityServer/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/JavascriptClient/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/mipmap-xxxhdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/XamarinApp/XamarinApp.Android/Resources/mipmap-xxxhdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T0shik/aspnetcore3-authentication/HEAD/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/flutter_app/ios/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Api/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/WpfApp/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/ApiOne/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/ApiTwo/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/Basics/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/Client/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/Server/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/flutter_app/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/MvcClient/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/JavascriptClient/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/IdentityServer/Controllers/ExternalRegisterViewModel.cs:
--------------------------------------------------------------------------------
1 | namespace IdentityServer.Controllers
2 | {
3 | public class ExternalRegisterViewModel
4 | {
5 | public string Username { get; set; }
6 | public string ReturnUrl { get; set; }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/IdentityExample/Views/Home/Login.cshtml:
--------------------------------------------------------------------------------
1 | Login Page
2 |
3 |
8 |
--------------------------------------------------------------------------------
/IdentityExample/Views/Home/Register.cshtml:
--------------------------------------------------------------------------------
1 | Register Page
2 |
3 |
8 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/xml/network_security_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 192.168.1.107
5 |
6 |
--------------------------------------------------------------------------------
/Angular/angular-app/e2e/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/e2e",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "jasminewd2",
10 | "node"
11 | ]
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Angular/angular-app/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "./out-tsc/app",
5 | "types": []
6 | },
7 | "files": [
8 | "src/main.ts",
9 | "src/polyfills.ts"
10 | ],
11 | "include": [
12 | "src/**/*.d.ts"
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/flutter_app/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jun 23 08:50:38 CEST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
7 |
--------------------------------------------------------------------------------
/Server/Views/OAuth/Authorize.cshtml:
--------------------------------------------------------------------------------
1 | @model string
2 |
3 | @{
4 | var url = $"/OAuth/Authorize{Model}";
5 | }
6 |
7 |
8 | @Model
9 |
10 |
--------------------------------------------------------------------------------
/Server/Constants.cs:
--------------------------------------------------------------------------------
1 | namespace Server
2 | {
3 | public static class Constants
4 | {
5 | public const string Issuer = Audiance;
6 | public const string Audiance = "https://localhost:44382/";
7 | public const string Secret = "not_too_short_secret_otherwise_it_might_error";
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/mipmap-anydpi-v26/icon.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/ApiOne/ApiOne.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFF
4 | #3F51B5
5 | #303F9F
6 | #FF4081
7 |
8 |
--------------------------------------------------------------------------------
/Angular/angular-app/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 |
4 |
5 | const routes: Routes = [];
6 |
7 | @NgModule({
8 | imports: [RouterModule.forRoot(routes)],
9 | exports: [RouterModule]
10 | })
11 | export class AppRoutingModule { }
12 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/mipmap-anydpi-v26/icon_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Api/Controllers/SecretController.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authorization;
2 | using Microsoft.AspNetCore.Mvc;
3 |
4 | namespace Api.Controllers
5 | {
6 | public class SecretController : Controller
7 | {
8 | [Authorize]
9 | public string Index()
10 | {
11 | return "secret message";
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/JavascriptClient/JavascriptClient.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/flutter_app/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: f139b11009aeb8ed2a3a3aa8b0066e482709dde3
8 | channel: stable
9 |
10 | project_type: app
11 |
--------------------------------------------------------------------------------
/Server/Controllers/SecretController.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authorization;
2 | using Microsoft.AspNetCore.Mvc;
3 |
4 | namespace Server.Controllers
5 | {
6 | public class SecretController : Controller
7 | {
8 | [Authorize]
9 | public string Index()
10 | {
11 | return "secret message";
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Angular/angular-app/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see https://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.ts]
12 | quote_type = single
13 |
14 | [*.md]
15 | max_line_length = off
16 | trim_trailing_whitespace = false
17 |
--------------------------------------------------------------------------------
/Angular/angular-app/e2e/src/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo(): Promise {
5 | return browser.get(browser.baseUrl) as Promise;
6 | }
7 |
8 | getTitleText(): Promise {
9 | return element(by.css('app-root .content span')).getText() as Promise;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Angular/angular-app/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | AngularApp
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Angular/angular-app/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "./out-tsc/spec",
5 | "types": [
6 | "jasmine",
7 | "node"
8 | ]
9 | },
10 | "files": [
11 | "src/test.ts",
12 | "src/polyfills.ts"
13 | ],
14 | "include": [
15 | "src/**/*.spec.ts",
16 | "src/**/*.d.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/ApiTwo/ApiTwo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/WpfApp/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/flutter_app/android/app/src/profile/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Basics/Pages/Razor/Index.cshtml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Mvc;
6 | using Microsoft.AspNetCore.Mvc.RazorPages;
7 |
8 | namespace Basics.Pages.Razor
9 | {
10 | public class IndexModel : PageModel
11 | {
12 | public void OnGet()
13 | {
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Basics/Pages/Razor/Policy.cshtml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Mvc;
6 | using Microsoft.AspNetCore.Mvc.RazorPages;
7 |
8 | namespace Basics.Pages.Razor
9 | {
10 | public class PolicyModel : PageModel
11 | {
12 | public void OnGet()
13 | {
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Client/Client.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/IdentityExample/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Email": {
3 | "Server": "127.0.0.1",
4 | "Port": 25,
5 | "SenderName": "Anton",
6 | "SenderEmail": "Testo@testo.com"
7 | },
8 | "Logging": {
9 | "LogLevel": {
10 | "Default": "Information",
11 | "Microsoft": "Warning",
12 | "Microsoft.Hosting.Lifetime": "Information"
13 | }
14 | },
15 | "AllowedHosts": "*"
16 | }
17 |
--------------------------------------------------------------------------------
/WpfApp/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace WpfApp
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md:
--------------------------------------------------------------------------------
1 | # Launch Screen Assets
2 |
3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory.
4 |
5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
--------------------------------------------------------------------------------
/Basics/Pages/Razor/Secured.cshtml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Mvc;
6 | using Microsoft.AspNetCore.Mvc.RazorPages;
7 |
8 | namespace Basics.Pages.Razor
9 | {
10 | public class SecuredModel : PageModel
11 | {
12 | public void OnGet()
13 | {
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/MvcClient/MvcClient.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Basics/Pages/RazorSecured/Anon.cshtml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Mvc;
6 | using Microsoft.AspNetCore.Mvc.RazorPages;
7 |
8 | namespace Basics.Pages.RazorSecured
9 | {
10 | public class AnonModel : PageModel
11 | {
12 | public void OnGet()
13 | {
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Basics/Pages/RazorSecured/Index.cshtml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Mvc;
6 | using Microsoft.AspNetCore.Mvc.RazorPages;
7 |
8 | namespace Basics.Pages.RazorSecured
9 | {
10 | public class IndexModel : PageModel
11 | {
12 | public void OnGet()
13 | {
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/JavascriptClient/Controllers/HomeController.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Mvc;
2 |
3 | namespace JavascriptClient.Controllers
4 | {
5 | public class HomeController : Controller
6 | {
7 | public IActionResult Index()
8 | {
9 | return View();
10 | }
11 |
12 | public IActionResult SignIn()
13 | {
14 | return View();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/flutter_app/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
--------------------------------------------------------------------------------
/Server/Server.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Angular/angular-app/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .catch(err => console.error(err));
13 |
--------------------------------------------------------------------------------
/IdentityServer/Data/AppDbContext.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
2 | using Microsoft.EntityFrameworkCore;
3 |
4 | namespace IdentityServer.Data
5 | {
6 | // IdentityDbContext contains all the user tables
7 | public class AppDbContext : IdentityDbContext
8 | {
9 | public AppDbContext(DbContextOptions options)
10 | : base(options)
11 | {
12 |
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/IdentityExample/Data/AppDbContext.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
2 | using Microsoft.EntityFrameworkCore;
3 |
4 | namespace IdentityExample.Data
5 | {
6 | // IdentityDbContext contains all the user tables
7 | public class AppDbContext : IdentityDbContext
8 | {
9 | public AppDbContext(DbContextOptions options)
10 | : base(options)
11 | {
12 |
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/IdentityServer/Views/Auth/ExternalRegister.cshtml:
--------------------------------------------------------------------------------
1 | @model ExternalRegisterViewModel
2 |
3 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/layout/Toolbar.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
--------------------------------------------------------------------------------
/IdentityServer/Controllers/LoginViewModel.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authentication;
2 | using System.Collections.Generic;
3 |
4 | namespace IdentityServer.Controllers
5 | {
6 | public class LoginViewModel
7 | {
8 | public string Username { get; set; }
9 | public string Password { get; set; }
10 | public string ReturnUrl { get; set; }
11 |
12 | public IEnumerable ExternalProviders { get; set; }
13 | }
14 | }
--------------------------------------------------------------------------------
/ApiOne/Controllers/SecretController.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authorization;
2 | using Microsoft.AspNetCore.Mvc;
3 | using System.Linq;
4 |
5 | namespace ApiOne.Controllers
6 | {
7 | public class SecretController : Controller
8 | {
9 | [Route("/secret")]
10 | [Authorize]
11 | public string Index()
12 | {
13 | var claims = User.Claims.ToList();
14 | return "secret message from ApiOne";
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/JavascriptClient/wwwroot/js-old/sign-in-callback.js:
--------------------------------------------------------------------------------
1 | var extractTokens = function (address) {
2 | var returnValue = address.split('#')[1];
3 | var values = returnValue.split('&');
4 |
5 | for (var i = 0; i < values.length; i++) {
6 | var v = values[i];
7 | var kvPair = v.split('=');
8 | localStorage.setItem(kvPair[0], kvPair[1]);
9 | }
10 |
11 | window.location.href = '/home/index';
12 | }
13 |
14 |
15 | extractTokens(window.location.href);
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import Flutter
3 |
4 | @UIApplicationMain
5 | @objc class AppDelegate: FlutterAppDelegate {
6 | override func application(
7 | _ application: UIApplication,
8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9 | ) -> Bool {
10 | GeneratedPluginRegistrant.register(with: self)
11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Angular/angular-app/browserslist:
--------------------------------------------------------------------------------
1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 |
5 | # You can see what browsers were selected by your queries by running:
6 | # npx browserslist
7 |
8 | > 0.5%
9 | last 2 versions
10 | Firefox ESR
11 | not dead
12 | not IE 9-11 # For IE 9-11 support, remove 'not'.
--------------------------------------------------------------------------------
/JavascriptClient/Views/Home/Index.cshtml:
--------------------------------------------------------------------------------
1 |
2 | Home Page
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/JavascriptClient/Views/Home/SignIn.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp/App.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Basics/Views/Home/Index.cshtml:
--------------------------------------------------------------------------------
1 | Home Page
2 |
3 | @* Simple access quick checks *@
4 | @if (User.Identity.IsAuthenticated)
5 | {
6 | User is authenticated
7 | }
8 | else
9 | {
10 | User is NOT authenticated
11 | }
12 |
13 |
14 | @* Big guns reusable functions *@
15 | @using Microsoft.AspNetCore.Authorization
16 | @inject IAuthorizationService authorizationService
17 |
18 | @if ((await authorizationService.AuthorizeAsync(User, "Claim.DoB")).Succeeded)
19 | {
20 | User has DoB Claim
21 | }
--------------------------------------------------------------------------------
/IdentityServer/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "ConnectionStrings": {
3 | "DefaultConnection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=IdentityServer4Tutorial;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
4 | },
5 | "Logging": {
6 | "LogLevel": {
7 | "Default": "Information",
8 | "Microsoft": "Warning",
9 | "Microsoft.Hosting.Lifetime": "Information"
10 | }
11 | },
12 | "AllowedHosts": "*"
13 | }
14 |
--------------------------------------------------------------------------------
/flutter_app/android/app/src/main/kotlin/com/example/flutter_app/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.flutter_app
2 |
3 | import androidx.annotation.NonNull;
4 | import io.flutter.embedding.android.FlutterActivity
5 | import io.flutter.embedding.engine.FlutterEngine
6 | import io.flutter.plugins.GeneratedPluginRegistrant
7 |
8 | class MainActivity: FlutterActivity() {
9 | override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
10 | GeneratedPluginRegistrant.registerWith(flutterEngine);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/flutter_app/android/app/src/main/res/drawable/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/IdentityServer/db-scripts.txt:
--------------------------------------------------------------------------------
1 | dotnet ef migrations add InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb
2 | dotnet ef migrations add InitialIdentityServerConfigurationDbMigration -c ConfigurationDbContext -o Data/Migrations/IdentityServer/ConfigurationDb
3 |
4 | dotnet ef migrations add -c AppDbContext -o Data/Migrations/AppMigrations
5 | dotnet ef database update -c AppDbContext
6 |
7 | dotnet ef database update -c PersistedGrantDbContext
8 | dotnet ef database update -c ConfigurationDbContext
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchImage.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchImage@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "LaunchImage@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Properties/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/flutter_app/android/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
3 | def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
4 |
5 | def plugins = new Properties()
6 | def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
7 | if (pluginsFile.exists()) {
8 | pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
9 | }
10 |
11 | plugins.each { name, path ->
12 | def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
13 | include ":$name"
14 | project(":$name").projectDir = pluginDirectory
15 | }
16 |
--------------------------------------------------------------------------------
/WpfApp/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/IdentityServer/Controllers/RegisterViewModel.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations;
2 |
3 | namespace IdentityServer.Controllers
4 | {
5 | public class RegisterViewModel
6 | {
7 | [Required]
8 | public string Username { get; set; }
9 | [Required]
10 | [DataType(DataType.Password)]
11 | public string Password { get; set; }
12 | [Required]
13 | [DataType(DataType.Password)]
14 | [Compare("Password")]
15 | public string ConfirmPassword { get; set; }
16 | public string ReturnUrl { get; set; }
17 | }
18 | }
--------------------------------------------------------------------------------
/IdentityExample/IdentityExample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xamarin.Forms;
3 | using Xamarin.Forms.Xaml;
4 |
5 | namespace XamarinApp
6 | {
7 | public partial class App : Application
8 | {
9 | public App()
10 | {
11 | InitializeComponent();
12 |
13 | MainPage = new MainPage();
14 | }
15 |
16 | protected override void OnStart()
17 | {
18 | }
19 |
20 | protected override void OnSleep()
21 | {
22 | }
23 |
24 | protected override void OnResume()
25 | {
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Angular/angular-app/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "baseUrl": "./",
5 | "outDir": "./dist/out-tsc",
6 | "sourceMap": true,
7 | "declaration": false,
8 | "downlevelIteration": true,
9 | "experimentalDecorators": true,
10 | "module": "esnext",
11 | "moduleResolution": "node",
12 | "importHelpers": true,
13 | "target": "es2015",
14 | "lib": [
15 | "es2018",
16 | "dom"
17 | ]
18 | },
19 | "angularCompilerOptions": {
20 | "fullTemplateTypeCheck": true,
21 | "strictInjectionParameters": true
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/layout/Tabbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
--------------------------------------------------------------------------------
/flutter_app/README.md:
--------------------------------------------------------------------------------
1 | # flutter_app
2 |
3 | A new Flutter project.
4 |
5 | ## Getting Started
6 |
7 | This project is a starting point for a Flutter application.
8 |
9 | A few resources to get you started if this is your first Flutter project:
10 |
11 | - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
12 | - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
13 |
14 | For help getting started with Flutter, view our
15 | [online documentation](https://flutter.dev/docs), which offers tutorials,
16 | samples, guidance on mobile development, and a full API reference.
17 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp/MainPage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/WpfApp/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/flutter_app/ios/.gitignore:
--------------------------------------------------------------------------------
1 | *.mode1v3
2 | *.mode2v3
3 | *.moved-aside
4 | *.pbxuser
5 | *.perspectivev3
6 | **/*sync/
7 | .sconsign.dblite
8 | .tags*
9 | **/.vagrant/
10 | **/DerivedData/
11 | Icon?
12 | **/Pods/
13 | **/.symlinks/
14 | profile
15 | xcuserdata
16 | **/.generated/
17 | Flutter/App.framework
18 | Flutter/Flutter.framework
19 | Flutter/Flutter.podspec
20 | Flutter/Generated.xcconfig
21 | Flutter/app.flx
22 | Flutter/app.zip
23 | Flutter/flutter_assets/
24 | Flutter/flutter_export_environment.sh
25 | ServiceDefinitions.json
26 | Runner/GeneratedPluginRegistrant.*
27 |
28 | # Exceptions to above rules.
29 | !default.mode1v3
30 | !default.mode2v3
31 | !default.pbxuser
32 | !default.perspectivev3
33 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp/XamarinApp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | true
6 |
7 |
8 |
9 | portable
10 | true
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Basics/Transformer/ClaimsTransformation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authentication;
2 | using System.Linq;
3 | using System.Security.Claims;
4 | using System.Threading.Tasks;
5 |
6 | namespace Basics.Transformer
7 | {
8 | public class ClaimsTransformation : IClaimsTransformation
9 | {
10 | public Task TransformAsync(ClaimsPrincipal principal)
11 | {
12 | var hasFriendClaim = principal.Claims.Any(x => x.Type == "Friend");
13 |
14 | if (!hasFriendClaim)
15 | {
16 | ((ClaimsIdentity)principal.Identity).AddClaim(new Claim("Friend", "Bad"));
17 | }
18 |
19 | return Task.FromResult(principal);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Assets/AboutAssets.txt:
--------------------------------------------------------------------------------
1 | Any raw assets you want to be deployed with your application can be placed in
2 | this directory (and child directories) and given a Build Action of "AndroidAsset".
3 |
4 | These files will be deployed with your package and will be accessible using Android's
5 | AssetManager, like this:
6 |
7 | public class ReadAsset : Activity
8 | {
9 | protected override void OnCreate (Bundle bundle)
10 | {
11 | base.OnCreate (bundle);
12 |
13 | InputStream input = Assets.Open ("my_asset.txt");
14 | }
15 | }
16 |
17 | Additionally, some Android functions will automatically load asset files:
18 |
19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
20 |
--------------------------------------------------------------------------------
/flutter_app/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.3.50'
3 | repositories {
4 | google()
5 | jcenter()
6 | }
7 |
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.5.0'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | jcenter()
18 | }
19 | }
20 |
21 | rootProject.buildDir = '../build'
22 | subprojects {
23 | project.buildDir = "${rootProject.buildDir}/${project.name}"
24 | }
25 | subprojects {
26 | project.evaluationDependsOn(':app')
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/Angular/angular-app/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // This file can be replaced during build by using the `fileReplacements` array.
2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
3 | // The list of file replacements can be found in `angular.json`.
4 |
5 | export const environment = {
6 | production: false
7 | };
8 |
9 | /*
10 | * For easier debugging in development mode, you can import the following file
11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
12 | *
13 | * This import should be commented out in production mode because it will have a negative impact
14 | * on performance if an error is thrown.
15 | */
16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
17 |
--------------------------------------------------------------------------------
/Angular/angular-app/e2e/src/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 | import { browser, logging } from 'protractor';
3 |
4 | describe('workspace-project App', () => {
5 | let page: AppPage;
6 |
7 | beforeEach(() => {
8 | page = new AppPage();
9 | });
10 |
11 | it('should display welcome message', () => {
12 | page.navigateTo();
13 | expect(page.getTitleText()).toEqual('angular-app app is running!');
14 | });
15 |
16 | afterEach(async () => {
17 | // Assert that there are no errors emitted from the browser
18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER);
19 | expect(logs).not.toContain(jasmine.objectContaining({
20 | level: logging.Level.SEVERE,
21 | } as logging.Entry));
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/Api/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:54609",
7 | "sslPort": 44332
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "Api": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/IdentityExample/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:58375",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "IdentityExample": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "http://localhost:5000",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/ApiOne/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:59871",
7 | "sslPort": 44337
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "ApiOne": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "https://localhost:5003;http://localhost:5002",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/ApiTwo/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:59902",
7 | "sslPort": 44316
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "ApiTwo": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Basics/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:50690",
7 | "sslPort": 44315
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "Basics": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Client/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:49459",
7 | "sslPort": 44342
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "Client": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Server/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:55580",
7 | "sslPort": 44382
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "Server": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/flutter_app/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 |
12 | # IntelliJ related
13 | *.iml
14 | *.ipr
15 | *.iws
16 | .idea/
17 |
18 | # The .vscode folder contains launch configuration and tasks you configure in
19 | # VS Code which you may wish to be included in version control, so this line
20 | # is commented out by default.
21 | #.vscode/
22 |
23 | # Flutter/Dart/Pub related
24 | **/doc/api/
25 | .dart_tool/
26 | .flutter-plugins
27 | .flutter-plugins-dependencies
28 | .packages
29 | .pub-cache/
30 | .pub/
31 | /build/
32 |
33 | # Web related
34 | lib/generated_plugin_registrant.dart
35 |
36 | # Exceptions to above rules.
37 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
38 |
--------------------------------------------------------------------------------
/MvcClient/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:49386",
7 | "sslPort": 44322
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "MvcClient": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Api/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 Api
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 |
--------------------------------------------------------------------------------
/ApiOne/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 ApiOne
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 |
--------------------------------------------------------------------------------
/ApiTwo/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 ApiTwo
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 |
--------------------------------------------------------------------------------
/Basics/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 Basics
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 |
--------------------------------------------------------------------------------
/Client/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 Client
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 |
--------------------------------------------------------------------------------
/IdentityServer/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:59781",
7 | "sslPort": 44305
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "IdentityServer": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/JavascriptClient/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:65505",
7 | "sslPort": 44345
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "JavascriptClient": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/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 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 |
--------------------------------------------------------------------------------
/MvcClient/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 MvcClient
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 |
--------------------------------------------------------------------------------
/IdentityExample/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 IdentityExample
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 |
--------------------------------------------------------------------------------
/JavascriptClient/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 JavascriptClient
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 |
--------------------------------------------------------------------------------
/Angular/angular-app/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 | # Only exists if Bazel was run
8 | /bazel-out
9 |
10 | # dependencies
11 | /node_modules
12 |
13 | # profiling files
14 | chrome-profiler-events*.json
15 | speed-measure-plugin*.json
16 |
17 | # IDEs and editors
18 | /.idea
19 | .project
20 | .classpath
21 | .c9/
22 | *.launch
23 | .settings/
24 | *.sublime-workspace
25 |
26 | # IDE - VSCode
27 | .vscode/*
28 | !.vscode/settings.json
29 | !.vscode/tasks.json
30 | !.vscode/launch.json
31 | !.vscode/extensions.json
32 | .history/*
33 |
34 | # misc
35 | /.sass-cache
36 | /connect.lock
37 | /coverage
38 | /libpeerconnection.log
39 | npm-debug.log
40 | yarn-error.log
41 | testem.log
42 | /typings
43 |
44 | # System Files
45 | .DS_Store
46 | Thumbs.db
47 |
--------------------------------------------------------------------------------
/Api/CustomeAuthenticationHandler.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authentication;
2 | using Microsoft.Extensions.Logging;
3 | using Microsoft.Extensions.Options;
4 | using System.Text.Encodings.Web;
5 | using System.Threading.Tasks;
6 |
7 | namespace Api
8 | {
9 | public class CustomeAuthenticationHandler : AuthenticationHandler
10 | {
11 | public CustomeAuthenticationHandler(
12 | IOptionsMonitor options,
13 | ILoggerFactory logger,
14 | UrlEncoder encoder,
15 | ISystemClock clock) : base(options, logger, encoder, clock) { }
16 |
17 | protected override Task HandleAuthenticateAsync()
18 | {
19 | return Task.FromResult(AuthenticateResult.Fail("Failed Authentication"));
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Angular/angular-app/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/zone-testing';
4 | import { getTestBed } from '@angular/core/testing';
5 | import {
6 | BrowserDynamicTestingModule,
7 | platformBrowserDynamicTesting
8 | } from '@angular/platform-browser-dynamic/testing';
9 |
10 | declare const require: {
11 | context(path: string, deep?: boolean, filter?: RegExp): {
12 | keys(): string[];
13 | (id: string): T;
14 | };
15 | };
16 |
17 | // First, initialize the Angular testing environment.
18 | getTestBed().initTestEnvironment(
19 | BrowserDynamicTestingModule,
20 | platformBrowserDynamicTesting()
21 | );
22 | // Then we find all the tests.
23 | const context = require.context('./', true, /\.spec\.ts$/);
24 | // And load the modules.
25 | context.keys().map(context);
26 |
--------------------------------------------------------------------------------
/IdentityServer/Views/Auth/Register.cshtml:
--------------------------------------------------------------------------------
1 | @model RegisterViewModel
2 |
3 |
24 |
25 | Back to Login
--------------------------------------------------------------------------------
/flutter_app/ios/Flutter/AppFrameworkInfo.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | App
9 | CFBundleIdentifier
10 | io.flutter.flutter.app
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | App
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | MinimumOSVersion
24 | 8.0
25 |
26 |
27 |
--------------------------------------------------------------------------------
/JavascriptClient/wwwroot/js-old/sign-in.js:
--------------------------------------------------------------------------------
1 | var createState = function () {
2 | return "SessionValueMakeItABitLongerasdfhjsadoighasdifjdsalkhrfakwelyrosdpiufghasidkgewr";
3 | };
4 |
5 | var createNonce = function () {
6 | return "NonceValuedsafliudsayatroiewewryie123";
7 | };
8 |
9 | var signIn = function () {
10 | var redirectUri = "https://localhost:44345/Home/SignIn";
11 | var responseType = "id_token token";
12 | var scope = "openid ApiOne";
13 | var authUrl =
14 | "/connect/authorize/callback" +
15 | "?client_id=client_id_js" +
16 | "&redirect_uri=" + encodeURIComponent(redirectUri) +
17 | "&response_type=" + encodeURIComponent(responseType) +
18 | "&scope=" + encodeURIComponent(scope) +
19 | "&nonce="+ createNonce() +
20 | "&state="+ createState();
21 |
22 | var returnUrl = encodeURIComponent(authUrl);
23 |
24 | window.location.href = "https://localhost:44305/Auth/Login?ReturnUrl=" + returnUrl;
25 | }
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Angular/angular-app/e2e/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // @ts-check
2 | // Protractor configuration file, see link for more information
3 | // https://github.com/angular/protractor/blob/master/lib/config.ts
4 |
5 | const { SpecReporter } = require('jasmine-spec-reporter');
6 |
7 | /**
8 | * @type { import("protractor").Config }
9 | */
10 | exports.config = {
11 | allScriptsTimeout: 11000,
12 | specs: [
13 | './src/**/*.e2e-spec.ts'
14 | ],
15 | capabilities: {
16 | browserName: 'chrome'
17 | },
18 | directConnect: true,
19 | baseUrl: 'http://localhost:4200/',
20 | framework: 'jasmine',
21 | jasmineNodeOpts: {
22 | showColors: true,
23 | defaultTimeoutInterval: 30000,
24 | print: function() {}
25 | },
26 | onPrepare() {
27 | require('ts-node').register({
28 | project: require('path').join(__dirname, './tsconfig.json')
29 | });
30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
31 | }
32 | };
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/OidcCallbackActivity.cs:
--------------------------------------------------------------------------------
1 | using Android.App;
2 | using Android.Content;
3 | using Android.OS;
4 | using Android.Util;
5 | using System;
6 |
7 | namespace XamarinApp.Droid
8 | {
9 | [Activity(Label = "OidcCallbackActivity")]
10 | [IntentFilter(new[] { Intent.ActionView },
11 | Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
12 | DataScheme = "xamarinformsclients")]
13 | // DataHost = "callback")]
14 | public class OidcCallbackActivity : Activity
15 | {
16 | public static event Action Callbacks;
17 |
18 | public OidcCallbackActivity()
19 | {
20 | Log.Debug("OidcCallbackActivity", "constructing OidcCallbackActivity");
21 | }
22 |
23 | protected override void OnCreate(Bundle savedInstanceState)
24 | {
25 | base.OnCreate(savedInstanceState);
26 |
27 | Callbacks?.Invoke(Intent.DataString);
28 |
29 | Finish();
30 |
31 | StartActivity(typeof(MainActivity));
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/Angular/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "requires": true,
3 | "lockfileVersion": 1,
4 | "dependencies": {
5 | "angular-auth-oidc-client": {
6 | "version": "11.1.1",
7 | "resolved": "https://registry.npmjs.org/angular-auth-oidc-client/-/angular-auth-oidc-client-11.1.1.tgz",
8 | "integrity": "sha512-CXKIyjdDCmP/w9p9tSMdyrZ+8sxRQcnwRsqi544GWVQKEoWZqaRNjsdVoOVrqjcHOMYDkHzwt+gROLHg8qnWgw==",
9 | "requires": {
10 | "common-tags": "^1.8.0",
11 | "jsrsasign-reduced": "^8.0.15"
12 | }
13 | },
14 | "common-tags": {
15 | "version": "1.8.0",
16 | "resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.8.0.tgz",
17 | "integrity": "sha512-6P6g0uetGpW/sdyUy/iQQCbFF0kWVMSIVSyYz7Zgjcgh8mgw8PQzDNZeyZ5DQ2gM7LBoZPHmnjz8rUthkBG5tw=="
18 | },
19 | "jsrsasign-reduced": {
20 | "version": "8.0.15",
21 | "resolved": "https://registry.npmjs.org/jsrsasign-reduced/-/jsrsasign-reduced-8.0.15.tgz",
22 | "integrity": "sha512-Ig4W69nXCIUedzOSk3nqJWUr2DmSDENYfsmCqVK33GPETtPcjwREGQc92hV5jcJ6zavMvGD4tjhZ+T7JIiaSLA=="
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/JavascriptClient/Startup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Builder;
6 | using Microsoft.AspNetCore.Hosting;
7 | using Microsoft.AspNetCore.Http;
8 | using Microsoft.Extensions.DependencyInjection;
9 | using Microsoft.Extensions.Hosting;
10 |
11 | namespace JavascriptClient
12 | {
13 | public class Startup
14 | {
15 | public void ConfigureServices(IServiceCollection services)
16 | {
17 | services.AddControllersWithViews()
18 | .AddRazorRuntimeCompilation();
19 | }
20 |
21 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
22 | {
23 | if (env.IsDevelopment())
24 | {
25 | app.UseDeveloperExceptionPage();
26 | }
27 |
28 | app.UseStaticFiles();
29 |
30 | app.UseRouting();
31 |
32 | app.UseEndpoints(endpoints =>
33 | {
34 | endpoints.MapDefaultControllerRoute();
35 | });
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Angular/angular-app/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { OidcSecurityService } from 'angular-auth-oidc-client';
3 | import { HttpClient, HttpHeaders } from '@angular/common/http';
4 |
5 | @Component({
6 | selector: 'app-root',
7 | templateUrl: './app.component.html',
8 | styleUrls: ['./app.component.css']
9 | })
10 | export class AppComponent {
11 |
12 | constructor(
13 | public oidcSecurityService: OidcSecurityService,
14 | public http: HttpClient) { }
15 |
16 | ngOnInit() {
17 | this.oidcSecurityService
18 | .checkAuth()
19 | .subscribe((auth) => console.log('is authenticated', auth));
20 | }
21 |
22 | login() {
23 | this.oidcSecurityService.authorize();
24 | }
25 |
26 | callApi() {
27 | const token = this.oidcSecurityService.getToken();
28 |
29 | this.http.get("http://localhost:5002/secret", {
30 | headers: new HttpHeaders({
31 | Authorization: 'Bearer ' + token,
32 | }),
33 | responseType: 'text'
34 | })
35 | .subscribe((data: any) => {
36 | console.log("api result:", data);
37 | });
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/IdentityServer/IdentityServer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | all
15 | runtime; build; native; contentfiles; analyzers; buildtransitive
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Angular/angular-app/README.md:
--------------------------------------------------------------------------------
1 | # AngularApp
2 |
3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.7.
4 |
5 | ## Development server
6 |
7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
8 |
9 | ## Code scaffolding
10 |
11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
12 |
13 | ## Build
14 |
15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
16 |
17 | ## Running unit tests
18 |
19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
20 |
21 | ## Running end-to-end tests
22 |
23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
24 |
25 | ## Further help
26 |
27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
28 |
--------------------------------------------------------------------------------
/IdentityServer/Views/Auth/Login.cshtml:
--------------------------------------------------------------------------------
1 | @model LoginViewModel
2 |
3 | Sign In With
4 |
15 |
16 |
30 |
--------------------------------------------------------------------------------
/Angular/angular-app/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | dir: require('path').join(__dirname, './coverage/angular-app'),
20 | reports: ['html', 'lcovonly', 'text-summary'],
21 | fixWebpackSourcePaths: true
22 | },
23 | reporters: ['progress', 'kjhtml'],
24 | port: 9876,
25 | colors: true,
26 | logLevel: config.LOG_INFO,
27 | autoWatch: true,
28 | browsers: ['Chrome'],
29 | singleRun: false,
30 | restartOnFileChange: true
31 | });
32 | };
33 |
--------------------------------------------------------------------------------
/flutter_app/test/widget_test.dart:
--------------------------------------------------------------------------------
1 | // This is a basic Flutter widget test.
2 | //
3 | // To perform an interaction with a widget in your test, use the WidgetTester
4 | // utility that Flutter provides. For example, you can send tap and scroll
5 | // gestures. You can also use WidgetTester to find child widgets in the widget
6 | // tree, read text, and verify that the values of widget properties are correct.
7 |
8 | import 'package:flutter/material.dart';
9 | import 'package:flutter_test/flutter_test.dart';
10 |
11 | import 'package:flutter_app/main.dart';
12 |
13 | void main() {
14 | testWidgets('Counter increments smoke test', (WidgetTester tester) async {
15 | // Build our app and trigger a frame.
16 | await tester.pumpWidget(MyApp());
17 |
18 | // Verify that our counter starts at 0.
19 | expect(find.text('0'), findsOneWidget);
20 | expect(find.text('1'), findsNothing);
21 |
22 | // Tap the '+' icon and trigger a frame.
23 | await tester.tap(find.byIcon(Icons.add));
24 | await tester.pump();
25 |
26 | // Verify that our counter has incremented.
27 | expect(find.text('0'), findsNothing);
28 | expect(find.text('1'), findsOneWidget);
29 | });
30 | }
31 |
--------------------------------------------------------------------------------
/WpfApp/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WpfApp.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Angular/angular-app/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 | import { RouterTestingModule } from '@angular/router/testing';
3 | import { AppComponent } from './app.component';
4 |
5 | describe('AppComponent', () => {
6 | beforeEach(async(() => {
7 | TestBed.configureTestingModule({
8 | imports: [
9 | RouterTestingModule
10 | ],
11 | declarations: [
12 | AppComponent
13 | ],
14 | }).compileComponents();
15 | }));
16 |
17 | it('should create the app', () => {
18 | const fixture = TestBed.createComponent(AppComponent);
19 | const app = fixture.componentInstance;
20 | expect(app).toBeTruthy();
21 | });
22 |
23 | it(`should have as title 'angular-app'`, () => {
24 | const fixture = TestBed.createComponent(AppComponent);
25 | const app = fixture.componentInstance;
26 | expect(app.title).toEqual('angular-app');
27 | });
28 |
29 | it('should render title', () => {
30 | const fixture = TestBed.createComponent(AppComponent);
31 | fixture.detectChanges();
32 | const compiled = fixture.nativeElement;
33 | expect(compiled.querySelector('.content span').textContent).toContain('angular-app app is running!');
34 | });
35 | });
36 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 | using Android.App;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("XamarinApp.Android")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("XamarinApp.Android")]
14 | [assembly: AssemblyCopyright("Copyright © 2014")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 | [assembly: ComVisible(false)]
18 |
19 | // Version information for an assembly consists of the following four values:
20 | //
21 | // Major Version
22 | // Minor Version
23 | // Build Number
24 | // Revision
25 | [assembly: AssemblyVersion("1.0.0.0")]
26 | [assembly: AssemblyFileVersion("1.0.0.0")]
27 |
28 | // Add some common permissions, these can be removed if not needed
29 | [assembly: UsesPermission(Android.Manifest.Permission.Internet)]
30 | [assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
31 |
--------------------------------------------------------------------------------
/Angular/angular-app/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { BrowserModule } from '@angular/platform-browser';
2 | import { APP_INITIALIZER, NgModule } from '@angular/core';
3 |
4 | import { AppRoutingModule } from './app-routing.module';
5 | import { AppComponent } from './app.component';
6 | import { AuthModule, LogLevel, OidcConfigService } from 'angular-auth-oidc-client';
7 | import { HttpClientModule } from '@angular/common/http';
8 |
9 | export function configureAuth(oidcConfigService: OidcConfigService) {
10 | return () =>
11 | oidcConfigService.withConfig({
12 | clientId: 'angular',
13 | stsServer: 'http://localhost:5000',
14 | responseType: 'code',
15 | redirectUrl: window.location.origin,
16 | postLogoutRedirectUri: window.location.origin,
17 | scope: 'openid ApiOne',
18 | logLevel: LogLevel.Debug,
19 | });
20 | }
21 |
22 | @NgModule({
23 | declarations: [
24 | AppComponent
25 | ],
26 | imports: [
27 | BrowserModule,
28 | AppRoutingModule,
29 | AuthModule.forRoot(),
30 | HttpClientModule
31 | ],
32 | providers: [
33 | OidcConfigService,
34 | {
35 | provide: APP_INITIALIZER,
36 | useFactory: configureAuth,
37 | deps: [OidcConfigService],
38 | multi: true,
39 | },
40 | ],
41 | bootstrap: [AppComponent]
42 | })
43 | export class AppModule { }
44 |
--------------------------------------------------------------------------------
/ApiTwo/Startup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Builder;
6 | using Microsoft.AspNetCore.Hosting;
7 | using Microsoft.AspNetCore.Http;
8 | using Microsoft.Extensions.DependencyInjection;
9 | using Microsoft.Extensions.Hosting;
10 |
11 | namespace ApiTwo
12 | {
13 | public class Startup
14 | {
15 | public void ConfigureServices(IServiceCollection services)
16 | {
17 | services.AddAuthentication("Bearer")
18 | .AddJwtBearer("Bearer", config => {
19 | config.Authority = "https://localhost:44305/";
20 |
21 | config.Audience = "ApiTwo";
22 | });
23 |
24 | services.AddHttpClient();
25 |
26 | services.AddControllers();
27 | }
28 |
29 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
30 | {
31 | if (env.IsDevelopment())
32 | {
33 | app.UseDeveloperExceptionPage();
34 | }
35 |
36 | app.UseRouting();
37 |
38 | app.UseAuthentication();
39 |
40 | app.UseAuthorization();
41 |
42 | app.UseEndpoints(endpoints =>
43 | {
44 | endpoints.MapControllers();
45 | });
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Basics/AuthorizationRequirements/CustomRequireClaim.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authorization;
2 | using System.Linq;
3 | using System.Threading.Tasks;
4 |
5 | namespace Basics.AuthorizationRequirements
6 | {
7 | public class CustomRequireClaim : IAuthorizationRequirement
8 | {
9 | public CustomRequireClaim(string claimType)
10 | {
11 | ClaimType = claimType;
12 | }
13 |
14 | public string ClaimType { get; }
15 | }
16 |
17 | public class CustomRequireClaimHandler : AuthorizationHandler
18 | {
19 | protected override Task HandleRequirementAsync(
20 | AuthorizationHandlerContext context,
21 | CustomRequireClaim requirement)
22 | {
23 | var hasClaim = context.User.Claims.Any(x => x.Type == requirement.ClaimType);
24 | if (hasClaim)
25 | {
26 | context.Succeed(requirement);
27 | }
28 |
29 | return Task.CompletedTask;
30 | }
31 | }
32 |
33 | public static class AuthorizationPolicyBuilderExtensions
34 | {
35 | public static AuthorizationPolicyBuilder RequireCustomClaim(
36 | this AuthorizationPolicyBuilder builder,
37 | string claimType)
38 | {
39 | builder.AddRequirements(new CustomRequireClaim(claimType));
40 | return builder;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Angular/angular-app/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "angular-app",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng serve",
7 | "build": "ng build",
8 | "test": "ng test",
9 | "lint": "ng lint",
10 | "e2e": "ng e2e"
11 | },
12 | "private": true,
13 | "dependencies": {
14 | "@angular/animations": "~9.1.9",
15 | "@angular/common": "~9.1.9",
16 | "@angular/compiler": "~9.1.9",
17 | "@angular/core": "~9.1.9",
18 | "@angular/forms": "~9.1.9",
19 | "@angular/platform-browser": "~9.1.9",
20 | "@angular/platform-browser-dynamic": "~9.1.9",
21 | "@angular/router": "~9.1.9",
22 | "angular-auth-oidc-client": "^11.1.1",
23 | "rxjs": "~6.5.4",
24 | "tslib": "^1.10.0",
25 | "zone.js": "~0.10.2"
26 | },
27 | "devDependencies": {
28 | "@angular-devkit/build-angular": "~0.901.7",
29 | "@angular/cli": "~9.1.7",
30 | "@angular/compiler-cli": "~9.1.9",
31 | "@types/node": "^12.11.1",
32 | "@types/jasmine": "~3.5.0",
33 | "@types/jasminewd2": "~2.0.3",
34 | "codelyzer": "^5.1.2",
35 | "jasmine-core": "~3.5.0",
36 | "jasmine-spec-reporter": "~4.2.1",
37 | "karma": "~5.0.0",
38 | "karma-chrome-launcher": "~3.1.0",
39 | "karma-coverage-istanbul-reporter": "~2.1.0",
40 | "karma-jasmine": "~3.0.1",
41 | "karma-jasmine-html-reporter": "^1.4.2",
42 | "protractor": "~7.0.0",
43 | "ts-node": "~8.3.0",
44 | "tslint": "~6.1.0",
45 | "typescript": "~3.8.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
26 |
27 |
30 |
31 |
--------------------------------------------------------------------------------
/Api/AuthRequirement/JwtRequirement.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authorization;
2 | using Microsoft.AspNetCore.Http;
3 | using System.Net.Http;
4 | using System.Threading.Tasks;
5 |
6 | namespace Api.AuthRequirement
7 | {
8 | public class JwtRequirement : IAuthorizationRequirement { }
9 |
10 | public class JwtRequirementHandler : AuthorizationHandler
11 | {
12 | private readonly HttpClient _client;
13 | private readonly HttpContext _httpContext;
14 |
15 | public JwtRequirementHandler(
16 | IHttpClientFactory httpClientFactory,
17 | IHttpContextAccessor httpContextAccessor)
18 | {
19 | _client = httpClientFactory.CreateClient();
20 | _httpContext = httpContextAccessor.HttpContext;
21 | }
22 |
23 | protected override async Task HandleRequirementAsync(
24 | AuthorizationHandlerContext context,
25 | JwtRequirement requirement)
26 | {
27 | if (_httpContext.Request.Headers.TryGetValue("Authorization", out var authHeader))
28 | {
29 | var accessToken = authHeader.ToString().Split(' ')[1];
30 |
31 | var response = await _client
32 | .GetAsync($"https://localhost:44382/oauth/validate?access_token={accessToken}");
33 |
34 | if(response.StatusCode == System.Net.HttpStatusCode.OK)
35 | {
36 | context.Succeed(requirement);
37 | }
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/ApiOne/Startup.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Builder;
2 | using Microsoft.AspNetCore.Hosting;
3 | using Microsoft.Extensions.DependencyInjection;
4 | using Microsoft.Extensions.Hosting;
5 |
6 | namespace ApiOne
7 | {
8 | public class Startup
9 | {
10 | public void ConfigureServices(IServiceCollection services)
11 | {
12 | services.AddAuthentication("Bearer")
13 | .AddJwtBearer("Bearer", config =>
14 | {
15 | config.Authority = "http://localhost:5000/";
16 |
17 | config.Audience = "ApiOne";
18 |
19 | config.RequireHttpsMetadata = false;
20 | });
21 |
22 | services.AddCors(confg =>
23 | confg.AddPolicy("AllowAll",
24 | p => p.AllowAnyOrigin()
25 | .AllowAnyMethod()
26 | .AllowAnyHeader()));
27 |
28 | services.AddControllers();
29 | }
30 |
31 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
32 | {
33 | if (env.IsDevelopment())
34 | {
35 | app.UseDeveloperExceptionPage();
36 | }
37 |
38 | app.UseCors("AllowAll");
39 |
40 | app.UseRouting();
41 |
42 | app.UseAuthentication();
43 |
44 | app.UseAuthorization();
45 |
46 | app.UseEndpoints(endpoints =>
47 | {
48 | endpoints.MapControllers();
49 | });
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/IdentityServer/tempkey.rsa:
--------------------------------------------------------------------------------
1 | {"KeyId":"MKYnjQ_a1EfAdUkVD7ToVA","Parameters":{"D":"u/GbkcvjWsPNtMymodf6SMuhzGM/f7vEf3pOaZlNmivSoXH6kxiNVPA5bLcsN+ni5Ybq1V0GJsKTwgd9IE+xHkIAoR8EMY7etxADr/azgLTGzuB8nRXL5LrcSeA43j0VHxqSKwYqO3TguVihUmIGC2l+7SOGd5BsZNXRZtbz4NbNOkVE3OXcplK1Rm7nANmBkpE7jScQzA8Vm3RqjA7tobvax11QFcIqk2wfisEiI15liJbKmBKioGLesT/djrVq28qKZWnIWCsBkWdwoSGlYn8pwPMU9UO7FHo4PSh9q+sdfk4CewrYAGl6op4Yj94zxXhqY+67K1PX1bSWLGYIIQ==","DP":"O2vWpsL68mSdSfeK+EeczqhyMVeNgmNwetsdiO7TqBs8uY/rKpeOnuKKxclBYcmleqT3zdajHlCjo02C6aXKMjzBo5UNJcJ/llIrHY7En4pADkTYQSPor8jEASDW0ptmF3r8TA0LR+Wv7u2Xe7yFLu2Paf4KbkS3myyK5WaEYsk=","DQ":"QmXWpltIURiagLtMGoNjpTRFSh+kJsqVp9nnioHShta9+MHC4ICmYngx6DzgIRVMcW7xEcJZYimIFAogNg9GTuVJH/E0/f+ml9a6gQ5W/t0w4MmlRX66dZbLhblvAxBbr2WN2cPR8EWZ9iQiyIEePZEINATNhmFP7xwPfF1BTks=","Exponent":"AQAB","InverseQ":"fsl3OoFlL7k25As4qO0tUx881qyoog2h5KMRlfrMyLrwVlygQSnlmN/dUHDSILu2Y93EBMSS3B76paxh2VNhpw2TZykM+TtrZL+laiU6SE/thtUGUS/Ylgx9y6tsDHIV8EzKxgUYkWTlFOrEElVnu86EEYK3Bu5eSAs+w5JykEs=","Modulus":"01ixZ7ujifVsulyKYKF9Wat/fZRzjkOPG3CL4Iw+Ntxjb6mJUSdTBsV7yYjXjI3yFOqr0loCwfHZb40EE1A7hPNzK3etbAA2SIZa365ZJjv7qJobeCgZjvJnr5UvL+xEBAEzS3vS4u9KmI0+AF243SxtmQxrpkfqTl+cL4wDMmkffGBFlAigufR80NXR5sTejEHAQzjCTPR1518ssNX9OM8t1QHGxGwtp5OUZDSx0DZuCGuvHfEk5eYIEqNfhNEtZnvPmEEqrv6Adweaf4XI2kSrFlBfVjE2DXzeTvy8Kd9wSw6jE8gj+mfo9CcYKpLSqZrxUSetz0RfAnK2sLF1OQ==","P":"4q0Akz8lc69pD6Dx/Yj8k6iDg3QIQRoW+1hHldmu7CKkdbpVY/8vASZZpkvN285HeEIT8xouNRqNjyB1K1e8K7ve3Xg7huEGoNaYs6zTNkhafKVR7P0bS00+bw4gHk/hSYINk01L8yPR0OA1EUkHYfh3FR8epCMigltI7MTW878=","Q":"7rAEcKTkDDOOgMpioOLko/QSO2kqHjqPvX2nSc9YSpvn5Zjl+91w5kTlOlsGh2nFmHIOar0/CrLmDvGN5a2UGoFwiTH16BwJQrQ/hecItXtMoIHyFholRZ+3KEWaQi9qlum0apMECAaL/sszceS2eLkZP43jXvMn7WiF6R819Qc="}}
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/MainActivity.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Android.App;
4 | using Android.Content.PM;
5 | using Android.Runtime;
6 | using Android.Views;
7 | using Android.Widget;
8 | using Android.OS;
9 | using Xamarin.Forms;
10 | using Plugin.CurrentActivity;
11 |
12 | namespace XamarinApp.Droid
13 | {
14 | [Activity(Label = "XamarinApp", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
15 | LaunchMode = LaunchMode.SingleTask)]
16 | public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
17 | {
18 | protected override void OnCreate(Bundle savedInstanceState)
19 | {
20 | DependencyService.Register();
21 |
22 | TabLayoutResource = Resource.Layout.Tabbar;
23 | ToolbarResource = Resource.Layout.Toolbar;
24 |
25 | base.OnCreate(savedInstanceState);
26 |
27 | Xamarin.Essentials.Platform.Init(this, savedInstanceState);
28 | global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
29 | CrossCurrentActivity.Current.Init(this, savedInstanceState);
30 | LoadApplication(new App());
31 | }
32 | public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
33 | {
34 | Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
35 |
36 | base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/flutter_app/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
8 |
12 |
19 |
20 |
21 |
22 |
23 |
24 |
26 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | flutter_app
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | $(FLUTTER_BUILD_NAME)
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(FLUTTER_BUILD_NUMBER)
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UISupportedInterfaceOrientations
30 |
31 | UIInterfaceOrientationPortrait
32 | UIInterfaceOrientationLandscapeLeft
33 | UIInterfaceOrientationLandscapeRight
34 |
35 | UISupportedInterfaceOrientations~ipad
36 |
37 | UIInterfaceOrientationPortrait
38 | UIInterfaceOrientationPortraitUpsideDown
39 | UIInterfaceOrientationLandscapeLeft
40 | UIInterfaceOrientationLandscapeRight
41 |
42 | UIViewControllerBasedStatusBarAppearance
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/ApiTwo/Controllers/HomeController.cs:
--------------------------------------------------------------------------------
1 | using IdentityModel.Client;
2 | using Microsoft.AspNetCore.Mvc;
3 | using System.Net.Http;
4 | using System.Threading.Tasks;
5 |
6 | namespace ApiTwo.Controllers
7 | {
8 | public class HomeController : Controller
9 | {
10 | private readonly IHttpClientFactory _httpClientFactory;
11 |
12 | public HomeController(IHttpClientFactory httpClientFactory)
13 | {
14 | _httpClientFactory = httpClientFactory;
15 | }
16 |
17 | [Route("/home")]
18 | public async Task Index()
19 | {
20 | //retrieve access token
21 | var serverClient = _httpClientFactory.CreateClient();
22 |
23 | var discoveryDocument = await serverClient.GetDiscoveryDocumentAsync("https://localhost:44305/");
24 |
25 | var tokenResponse = await serverClient.RequestClientCredentialsTokenAsync(
26 | new ClientCredentialsTokenRequest
27 | {
28 | Address = discoveryDocument.TokenEndpoint,
29 |
30 | ClientId = "client_id",
31 | ClientSecret = "client_secret",
32 |
33 | Scope = "ApiOne",
34 | });
35 |
36 | //retrieve secret data
37 | var apiClient = _httpClientFactory.CreateClient();
38 |
39 | apiClient.SetBearerToken(tokenResponse.AccessToken);
40 |
41 | var response = await apiClient.GetAsync("https://localhost:44337/secret");
42 |
43 | var content = await response.Content.ReadAsStringAsync();
44 |
45 | return Ok(new
46 | {
47 | access_token = tokenResponse.AccessToken,
48 | message = content,
49 | });
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Api/Startup.cs:
--------------------------------------------------------------------------------
1 | using Api.AuthRequirement;
2 | using Microsoft.AspNetCore.Authentication;
3 | using Microsoft.AspNetCore.Authorization;
4 | using Microsoft.AspNetCore.Builder;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.Extensions.DependencyInjection;
7 | using Microsoft.Extensions.Hosting;
8 |
9 | namespace Api
10 | {
11 | public class Startup
12 | {
13 | public void ConfigureServices(IServiceCollection services)
14 | {
15 | services.AddAuthentication("DefaultAuth")
16 | .AddScheme("DefaultAuth", null);
17 |
18 | services.AddAuthorization(config =>
19 | {
20 | var defaultAuthBuilder = new AuthorizationPolicyBuilder();
21 | var defaultAuthPolicy = defaultAuthBuilder
22 | .AddRequirements(new JwtRequirement())
23 | .Build();
24 |
25 | config.DefaultPolicy = defaultAuthPolicy;
26 | });
27 |
28 | services.AddScoped();
29 |
30 | services.AddHttpClient()
31 | .AddHttpContextAccessor();
32 |
33 | services.AddControllers();
34 | }
35 |
36 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
37 | {
38 | if (env.IsDevelopment())
39 | {
40 | app.UseDeveloperExceptionPage();
41 | }
42 |
43 | app.UseRouting();
44 |
45 | app.UseAuthentication();
46 |
47 | app.UseAuthorization();
48 |
49 | app.UseEndpoints(endpoints =>
50 | {
51 | endpoints.MapDefaultControllerRoute();
52 | });
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Server/Controllers/HomeController.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authorization;
2 | using Microsoft.AspNetCore.Mvc;
3 | using Microsoft.IdentityModel.Tokens;
4 | using System;
5 | using System.IdentityModel.Tokens.Jwt;
6 | using System.Security.Claims;
7 | using System.Text;
8 |
9 | namespace Server.Controllers
10 | {
11 | public class HomeController : Controller
12 | {
13 | public IActionResult Index()
14 | {
15 | return View();
16 | }
17 |
18 | [Authorize]
19 | public IActionResult Secret()
20 | {
21 | return View();
22 | }
23 |
24 | public IActionResult Authenticate()
25 | {
26 | var claims = new[]
27 | {
28 | new Claim(JwtRegisteredClaimNames.Sub, "some_id"),
29 | new Claim("granny", "cookie")
30 | };
31 |
32 | var secretBytes = Encoding.UTF8.GetBytes(Constants.Secret);
33 | var key = new SymmetricSecurityKey(secretBytes);
34 | var algorithm = SecurityAlgorithms.HmacSha256;
35 |
36 | var signingCredentials = new SigningCredentials(key, algorithm);
37 |
38 | var token = new JwtSecurityToken(
39 | Constants.Issuer,
40 | Constants.Audiance,
41 | claims,
42 | notBefore: DateTime.Now,
43 | expires: DateTime.Now.AddHours(1),
44 | signingCredentials);
45 |
46 | var tokenJson = new JwtSecurityTokenHandler().WriteToken(token);
47 |
48 | return Ok(new { access_token = tokenJson });
49 | }
50 |
51 | public IActionResult Decode(string part)
52 | {
53 | var bytes = Convert.FromBase64String(part);
54 | return Ok(Encoding.UTF8.GetString(bytes));
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/WpfApp/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/Resources/AboutResources.txt:
--------------------------------------------------------------------------------
1 | Images, layout descriptions, binary blobs and string dictionaries can be included
2 | in your application as resource files. Various Android APIs are designed to
3 | operate on the resource IDs instead of dealing with images, strings or binary blobs
4 | directly.
5 |
6 | For example, a sample Android app that contains a user interface layout (main.xml),
7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
8 | would keep its resources in the "Resources" directory of the application:
9 |
10 | Resources/
11 | drawable-hdpi/
12 | icon.png
13 |
14 | drawable-ldpi/
15 | icon.png
16 |
17 | drawable-mdpi/
18 | icon.png
19 |
20 | layout/
21 | main.xml
22 |
23 | values/
24 | strings.xml
25 |
26 | In order to get the build system to recognize Android resources, set the build action to
27 | "AndroidResource". The native Android APIs do not operate directly with filenames, but
28 | instead operate on resource IDs. When you compile an Android application that uses resources,
29 | the build system will package the resources for distribution and generate a class called
30 | "Resource" that contains the tokens for each one of the resources included. For example,
31 | for the above Resources layout, this is what the Resource class would expose:
32 |
33 | public class Resource {
34 | public class drawable {
35 | public const int icon = 0x123;
36 | }
37 |
38 | public class layout {
39 | public const int main = 0x456;
40 | }
41 |
42 | public class strings {
43 | public const int first_string = 0xabc;
44 | public const int second_string = 0xbcd;
45 | }
46 | }
47 |
48 | You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main
49 | to reference the layout/main.xml file, or Resource.strings.first_string to reference the first
50 | string in the dictionary file values/strings.xml.
51 |
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp.Android/ChromeCustomTabsBrowser.cs:
--------------------------------------------------------------------------------
1 | using Android.App;
2 | using Android.Content;
3 | using Android.Graphics;
4 | using Android.Support.CustomTabs;
5 | using IdentityModel.OidcClient.Browser;
6 | using Plugin.CurrentActivity;
7 | using System;
8 | using System.Threading;
9 | using System.Threading.Tasks;
10 |
11 | namespace XamarinApp.Droid
12 | {
13 | public class ChromeCustomTabsBrowser : IBrowser
14 | {
15 | private readonly Activity _context;
16 | private readonly CustomTabsActivityManager _manager;
17 |
18 | public ChromeCustomTabsBrowser() : this(CrossCurrentActivity.Current.Activity) { }
19 |
20 |
21 | public ChromeCustomTabsBrowser(Activity context)
22 | {
23 | _context = context;
24 | _manager = new CustomTabsActivityManager(_context);
25 | }
26 |
27 | public Task InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default)
28 | {
29 | var task = new TaskCompletionSource();
30 |
31 | var builder = new CustomTabsIntent.Builder(_manager.Session)
32 | .SetToolbarColor(Color.Argb(255, 52, 152, 219))
33 | .SetShowTitle(true)
34 | .EnableUrlBarHiding();
35 |
36 | var customTabsIntent = builder.Build();
37 |
38 | // ensures the intent is not kept in the history stack, which makes
39 | // sure navigating away from it will close it
40 | customTabsIntent.Intent.AddFlags(ActivityFlags.NoHistory);
41 |
42 | Action callback = null;
43 | callback = url =>
44 | {
45 | OidcCallbackActivity.Callbacks -= callback;
46 |
47 | task.SetResult(new BrowserResult()
48 | {
49 | Response = url
50 | });
51 | };
52 |
53 | OidcCallbackActivity.Callbacks += callback;
54 |
55 | customTabsIntent.LaunchUrl(_context, Android.Net.Uri.Parse(options.StartUrl));
56 |
57 | return task.Task;
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/XamarinApp/XamarinApp/MainPage.xaml.cs:
--------------------------------------------------------------------------------
1 | using IdentityModel.OidcClient;
2 | using IdentityModel.OidcClient.Browser;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.ComponentModel;
6 | using System.Linq;
7 | using System.Net.Http;
8 | using System.Net.Http.Headers;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 | using Xamarin.Forms;
12 |
13 | namespace XamarinApp
14 | {
15 | // Learn more about making custom code visible in the Xamarin.Forms previewer
16 | // by visiting https://aka.ms/xamarinforms-previewer
17 | [DesignTimeVisible(false)]
18 | public partial class MainPage : ContentPage
19 | {
20 | OidcClient _client;
21 | LoginResult _result;
22 |
23 | Lazy _apiClient = new Lazy(() => new HttpClient());
24 |
25 |
26 | public MainPage()
27 | {
28 | InitializeComponent();
29 |
30 | var browser = DependencyService.Get();
31 |
32 | var options = new OidcClientOptions
33 | {
34 | Authority = "http://192.168.1.107:5000/",
35 | ClientId = "xamarin",
36 | Scope = "openid ApiOne",
37 | RedirectUri = "xamarinformsclients://callback",
38 | Browser = browser,
39 |
40 | ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect
41 | };
42 |
43 | options.Policy.Discovery.RequireHttps = false;
44 |
45 | _client = new OidcClient(options);
46 | _apiClient.Value.BaseAddress = new Uri("http://192.168.1.107:5002/");
47 | }
48 |
49 | private async void Login(object sender, EventArgs e)
50 | {
51 | _result = await _client.LoginAsync(new LoginRequest());
52 |
53 | if (_result.IsError)
54 | {
55 | return;
56 | }
57 |
58 | _apiClient.Value.DefaultRequestHeaders.Authorization =
59 | new AuthenticationHeaderValue("Bearer", _result?.AccessToken ?? "");
60 | }
61 |
62 | private async void CallApi(object sender, EventArgs e)
63 | {
64 | var result = await _apiClient.Value.GetStringAsync("secret");
65 |
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/JavascriptClient/wwwroot/main.js:
--------------------------------------------------------------------------------
1 | var config = {
2 | userStore: new Oidc.WebStorageStateStore({ store: window.localStorage }),
3 | authority: "https://localhost:44305/",
4 | client_id: "client_id_js",
5 | redirect_uri: "https://localhost:44345/Home/SignIn",
6 | post_logout_redirect_uri: "https://localhost:44345/Home/Index",
7 | response_type: "code",
8 | scope: "openid rc.scope ApiOne ApiTwo"
9 | };
10 |
11 | var userManager = new Oidc.UserManager(config);
12 |
13 | var signIn = function () {
14 | userManager.signinRedirect();
15 | };
16 |
17 | var signOut = function() {
18 | userManager.signoutRedirect();
19 | };
20 |
21 | userManager.getUser().then(user => {
22 | console.log("user:", user);
23 | if (user) {
24 | axios.defaults.headers.common["Authorization"] = "Bearer " + user.access_token;
25 | }
26 | });
27 |
28 | var callApi = function () {
29 | axios.get("https://localhost:44337/secret")
30 | .then(res => {
31 | console.log(res);
32 | });
33 | };
34 |
35 | var refreshing = false;
36 |
37 | axios.interceptors.response.use(
38 | function (response) { return response; },
39 | function (error) {
40 | console.log("axios error:", error.response);
41 |
42 | var axiosConfig = error.response.config;
43 |
44 | //if error response is 401 try to refresh token
45 | if (error.response.status === 401) {
46 | console.log("axios error 401");
47 |
48 | // if already refreshing don't make another request
49 | if (!refreshing) {
50 | console.log("starting token refresh");
51 | refreshing = true;
52 |
53 | // do the refresh
54 | return userManager.signinSilent().then(user => {
55 | console.log("new user:", user);
56 | //update the http request and client
57 | axios.defaults.headers.common["Authorization"] = "Bearer " + user.access_token;
58 | axiosConfig.headers["Authorization"] = "Bearer " + user.access_token;
59 | //retry the http request
60 | return axios(axiosConfig);
61 | });
62 | }
63 | }
64 |
65 | return Promise.reject(error);
66 | });
--------------------------------------------------------------------------------
/flutter_app/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | def localProperties = new Properties()
2 | def localPropertiesFile = rootProject.file('local.properties')
3 | if (localPropertiesFile.exists()) {
4 | localPropertiesFile.withReader('UTF-8') { reader ->
5 | localProperties.load(reader)
6 | }
7 | }
8 |
9 | def flutterRoot = localProperties.getProperty('flutter.sdk')
10 | if (flutterRoot == null) {
11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12 | }
13 |
14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15 | if (flutterVersionCode == null) {
16 | flutterVersionCode = '1'
17 | }
18 |
19 | def flutterVersionName = localProperties.getProperty('flutter.versionName')
20 | if (flutterVersionName == null) {
21 | flutterVersionName = '1.0'
22 | }
23 |
24 | apply plugin: 'com.android.application'
25 | apply plugin: 'kotlin-android'
26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27 |
28 | android {
29 | compileSdkVersion 28
30 |
31 | sourceSets {
32 | main.java.srcDirs += 'src/main/kotlin'
33 | }
34 |
35 | lintOptions {
36 | disable 'InvalidPackage'
37 | }
38 |
39 | defaultConfig {
40 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
41 | applicationId "com.example.flutter_app"
42 | minSdkVersion 16
43 | targetSdkVersion 28
44 | versionCode flutterVersionCode.toInteger()
45 | versionName flutterVersionName
46 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
47 | }
48 |
49 | buildTypes {
50 | release {
51 | // TODO: Add your own signing config for the release build.
52 | // Signing with the debug keys for now, so `flutter run --release` works.
53 | signingConfig signingConfigs.debug
54 | }
55 | }
56 | }
57 |
58 | flutter {
59 | source '../..'
60 | }
61 |
62 | dependencies {
63 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
64 | testImplementation 'junit:junit:4.12'
65 | androidTestImplementation 'androidx.test:runner:1.1.1'
66 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
67 | }
68 |
--------------------------------------------------------------------------------
/Server/Startup.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authentication.JwtBearer;
2 | using Microsoft.AspNetCore.Builder;
3 | using Microsoft.AspNetCore.Hosting;
4 | using Microsoft.Extensions.DependencyInjection;
5 | using Microsoft.Extensions.Hosting;
6 | using Microsoft.IdentityModel.Tokens;
7 | using System;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace Server
12 | {
13 | public class Startup
14 | {
15 | public void ConfigureServices(IServiceCollection services)
16 | {
17 | services.AddAuthentication("OAuth")
18 | .AddJwtBearer("OAuth", config =>
19 | {
20 | var secretBytes = Encoding.UTF8.GetBytes(Constants.Secret);
21 | var key = new SymmetricSecurityKey(secretBytes);
22 |
23 | config.Events = new JwtBearerEvents()
24 | {
25 | OnMessageReceived = context =>
26 | {
27 | if (context.Request.Query.ContainsKey("access_token"))
28 | {
29 | context.Token = context.Request.Query["access_token"];
30 | }
31 |
32 | return Task.CompletedTask;
33 | }
34 | };
35 |
36 | config.TokenValidationParameters = new TokenValidationParameters()
37 | {
38 | ClockSkew = TimeSpan.Zero,
39 | ValidIssuer = Constants.Issuer,
40 | ValidAudience = Constants.Audiance,
41 | IssuerSigningKey = key,
42 | };
43 | });
44 |
45 | services.AddControllersWithViews()
46 | .AddRazorRuntimeCompilation();
47 | }
48 |
49 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
50 | {
51 | if (env.IsDevelopment())
52 | {
53 | app.UseDeveloperExceptionPage();
54 | }
55 |
56 | app.UseRouting();
57 |
58 | app.UseAuthentication();
59 |
60 | app.UseAuthorization();
61 |
62 | app.UseEndpoints(endpoints =>
63 | {
64 | endpoints.MapDefaultControllerRoute();
65 | });
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/IdentityExample/Startup.cs:
--------------------------------------------------------------------------------
1 | using IdentityExample.Data;
2 | using Microsoft.AspNetCore.Builder;
3 | using Microsoft.AspNetCore.Hosting;
4 | using Microsoft.AspNetCore.Identity;
5 | using Microsoft.EntityFrameworkCore;
6 | using Microsoft.Extensions.Configuration;
7 | using Microsoft.Extensions.DependencyInjection;
8 | using Microsoft.Extensions.Hosting;
9 | using NETCore.MailKit.Extensions;
10 | using NETCore.MailKit.Infrastructure.Internal;
11 |
12 | namespace IdentityExample
13 | {
14 | public class Startup
15 | {
16 | private IConfiguration _config;
17 |
18 | public Startup(IConfiguration config)
19 | {
20 | _config = config;
21 | }
22 |
23 | public void ConfigureServices(IServiceCollection services)
24 | {
25 | services.AddDbContext(config =>
26 | {
27 | config.UseInMemoryDatabase("Memory");
28 | });
29 |
30 | // AddIdentity registers the services
31 | services.AddIdentity(config =>
32 | {
33 | config.Password.RequiredLength = 4;
34 | config.Password.RequireDigit = false;
35 | config.Password.RequireNonAlphanumeric = false;
36 | config.Password.RequireUppercase = false;
37 | config.SignIn.RequireConfirmedEmail = true;
38 | })
39 | .AddEntityFrameworkStores()
40 | .AddDefaultTokenProviders();
41 |
42 | services.ConfigureApplicationCookie(config =>
43 | {
44 | config.Cookie.Name = "Identity.Cookie";
45 | config.LoginPath = "/Home/Login";
46 | });
47 |
48 | services.AddMailKit(config => config.UseMailKit(_config.GetSection("Email").Get()));
49 |
50 | services.AddControllersWithViews();
51 | }
52 |
53 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
54 | {
55 | if (env.IsDevelopment())
56 | {
57 | app.UseDeveloperExceptionPage();
58 | }
59 |
60 | app.UseRouting();
61 |
62 | app.UseAuthentication();
63 |
64 | app.UseAuthorization();
65 |
66 | app.UseEndpoints(endpoints =>
67 | {
68 | endpoints.MapDefaultControllerRoute();
69 | });
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/WpfApp/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using IdentityModel.OidcClient;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Net.Http;
6 | using System.Net.Http.Headers;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows;
10 | using System.Windows.Controls;
11 | using System.Windows.Data;
12 | using System.Windows.Documents;
13 | using System.Windows.Input;
14 | using System.Windows.Media;
15 | using System.Windows.Media.Imaging;
16 | using System.Windows.Navigation;
17 | using System.Windows.Shapes;
18 |
19 | namespace WpfApp
20 | {
21 | ///
22 | /// Interaction logic for MainWindow.xaml
23 | ///
24 | public partial class MainWindow : Window
25 | {
26 | private OidcClient _oidcClient = null;
27 |
28 | public MainWindow()
29 | {
30 | InitializeComponent();
31 | }
32 |
33 | private async void Button_Click(object sender, RoutedEventArgs e)
34 | {
35 | var options = new OidcClientOptions()
36 | {
37 | Authority = "https://localhost:44305/",
38 | ClientId = "wpf",
39 | Scope = "openid ApiOne",
40 | RedirectUri = "http://localhost/sample-wpf-app",
41 | Browser = new WpfEmbeddedBrowser()
42 | };
43 |
44 | _oidcClient = new OidcClient(options);
45 |
46 | LoginResult result;
47 | try
48 | {
49 | result = await _oidcClient.LoginAsync();
50 | }
51 | catch (Exception ex)
52 | {
53 | //Message.Text = $"Unexpected Error: {ex.Message}";
54 | return;
55 | }
56 |
57 | if (result.IsError)
58 | {
59 | //Message.Text = result.Error == "UserCancel" ? "The sign-in window was closed before authorization was completed." : result.Error;
60 |
61 | }
62 | else
63 | {
64 | var name = result.User.Identity.Name;
65 |
66 | var client = new HttpClient();
67 | client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
68 | var apiResult = await client.GetStringAsync("https://localhost:44337/secret");
69 | //Message.Text = $"Hello {name}";
70 | }
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Basics/Controllers/OperationsController.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authorization;
2 | using Microsoft.AspNetCore.Authorization.Infrastructure;
3 | using Microsoft.AspNetCore.Mvc;
4 | using System.Threading.Tasks;
5 |
6 | namespace Basics.Controllers
7 | {
8 | public class OperationsController : Controller
9 | {
10 | private readonly IAuthorizationService _authorizationService;
11 |
12 | public OperationsController(IAuthorizationService authorizationService)
13 | {
14 | _authorizationService = authorizationService;
15 | }
16 |
17 | public async Task Open()
18 | {
19 | var cookieJar = new CookieJar(); // get cookie jar from db
20 | await _authorizationService.AuthorizeAsync(User, cookieJar, CookieJarAuthOperations.Open);
21 | return View();
22 | }
23 | }
24 |
25 | public class CookieJarAuthorizationHandler
26 | : AuthorizationHandler
27 | {
28 | protected override Task HandleRequirementAsync(
29 | AuthorizationHandlerContext context,
30 | OperationAuthorizationRequirement requirement,
31 | CookieJar cookieJar)
32 | {
33 | if (requirement.Name == CookieJarOperations.Look)
34 | {
35 | if (context.User.Identity.IsAuthenticated)
36 | {
37 | context.Succeed(requirement);
38 | }
39 | }
40 | else if (requirement.Name == CookieJarOperations.ComeNear)
41 | {
42 | if (context.User.HasClaim("Friend", "Good"))
43 | {
44 | context.Succeed(requirement);
45 | }
46 | }
47 |
48 | return Task.CompletedTask;
49 | }
50 | }
51 |
52 | public static class CookieJarAuthOperations
53 | {
54 | public static OperationAuthorizationRequirement Open = new OperationAuthorizationRequirement
55 | {
56 | Name = CookieJarOperations.Open
57 | };
58 | }
59 |
60 | public static class CookieJarOperations
61 | {
62 | public static string Open = "Open";
63 | public static string TakeCookie = "TakeCookie";
64 | public static string ComeNear = "ComeNear";
65 | public static string Look = "Look";
66 | }
67 |
68 | public class CookieJar
69 | {
70 | public string Name { get; set; }
71 | }
72 | }
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
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 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/WpfApp/WpfEmbeddedBrowser.cs:
--------------------------------------------------------------------------------
1 | using IdentityModel.OidcClient.Browser;
2 | using System;
3 | using System.Linq;
4 | using System.Threading;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 |
9 | namespace WpfApp
10 | {
11 | public class WpfEmbeddedBrowser : IBrowser
12 | {
13 | private BrowserOptions _options = null;
14 |
15 | public WpfEmbeddedBrowser()
16 | {
17 |
18 | }
19 |
20 | public async Task InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default)
21 | {
22 | _options = options;
23 |
24 | var window = new Window()
25 | {
26 | Width = 900,
27 | Height = 625,
28 | Title = "IdentityServer Demo Login"
29 | };
30 |
31 | // Note: Unfortunately, WebBrowser is very limited and does not give sufficient information for
32 | // robust error handling. The alternative is to use a system browser or third party embedded
33 | // library (which tend to balloon the size of your application and are complicated).
34 | var webBrowser = new WebBrowser();
35 |
36 | var signal = new SemaphoreSlim(0, 1);
37 |
38 | var result = new BrowserResult()
39 | {
40 | ResultType = BrowserResultType.UserCancel
41 | };
42 |
43 | webBrowser.Navigating += (s, e) =>
44 | {
45 | if (BrowserIsNavigatingToRedirectUri(e.Uri))
46 | {
47 | e.Cancel = true;
48 |
49 | result = new BrowserResult()
50 | {
51 | ResultType = BrowserResultType.Success,
52 | Response = e.Uri.AbsoluteUri
53 | };
54 |
55 | signal.Release();
56 |
57 | window.Close();
58 | }
59 | };
60 |
61 | window.Closing += (s, e) =>
62 | {
63 | signal.Release();
64 | };
65 |
66 | window.Content = webBrowser;
67 | window.Show();
68 | webBrowser.Source = new Uri(_options.StartUrl);
69 |
70 | await signal.WaitAsync();
71 |
72 | return result;
73 | }
74 |
75 | private bool BrowserIsNavigatingToRedirectUri(Uri uri)
76 | {
77 | return uri.AbsoluteUri.StartsWith(_options.EndUrl);
78 | }
79 | }
80 | }
--------------------------------------------------------------------------------
/WpfApp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("WpfApp")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("WpfApp")]
15 | [assembly: AssemblyCopyright("Copyright © 2020")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/MvcClient/Startup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Authentication;
6 | using Microsoft.AspNetCore.Builder;
7 | using Microsoft.AspNetCore.Hosting;
8 | using Microsoft.AspNetCore.Http;
9 | using Microsoft.Extensions.DependencyInjection;
10 | using Microsoft.Extensions.Hosting;
11 |
12 | namespace MvcClient
13 | {
14 | public class Startup
15 | {
16 | public void ConfigureServices(IServiceCollection services)
17 | {
18 | services.AddAuthentication(config => {
19 | config.DefaultScheme = "Cookie";
20 | config.DefaultChallengeScheme = "oidc";
21 | })
22 | .AddCookie("Cookie")
23 | .AddOpenIdConnect("oidc", config => {
24 | config.Authority = "https://localhost:44305/";
25 | config.ClientId = "client_id_mvc";
26 | config.ClientSecret = "client_secret_mvc";
27 | config.SaveTokens = true;
28 | config.ResponseType = "code";
29 | config.SignedOutCallbackPath = "/Home/Index";
30 |
31 | // configure cookie claim mapping
32 | config.ClaimActions.DeleteClaim("amr");
33 | config.ClaimActions.DeleteClaim("s_hash");
34 | config.ClaimActions.MapUniqueJsonKey("RawCoding.Grandma", "rc.garndma");
35 |
36 | // two trips to load claims in to the cookie
37 | // but the id token is smaller !
38 | config.GetClaimsFromUserInfoEndpoint = true;
39 |
40 | // configure scope
41 | config.Scope.Clear();
42 | config.Scope.Add("openid");
43 | config.Scope.Add("rc.scope");
44 | config.Scope.Add("ApiOne");
45 | config.Scope.Add("ApiTwo");
46 | config.Scope.Add("offline_access");
47 |
48 | });
49 |
50 | services.AddHttpClient();
51 |
52 | services.AddControllersWithViews();
53 | }
54 |
55 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
56 | {
57 | if (env.IsDevelopment())
58 | {
59 | app.UseDeveloperExceptionPage();
60 | }
61 |
62 | app.UseRouting();
63 |
64 | app.UseAuthentication();
65 |
66 | app.UseAuthorization();
67 |
68 | app.UseEndpoints(endpoints =>
69 | {
70 | endpoints.MapDefaultControllerRoute();
71 | });
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/flutter_app/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: flutter_app
2 | description: A new Flutter project.
3 |
4 | # The following defines the version and build number for your application.
5 | # A version number is three numbers separated by dots, like 1.2.43
6 | # followed by an optional build number separated by a +.
7 | # Both the version and the builder number may be overridden in flutter
8 | # build by specifying --build-name and --build-number, respectively.
9 | # In Android, build-name is used as versionName while build-number used as versionCode.
10 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
11 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
12 | # Read more about iOS versioning at
13 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
14 | version: 1.0.0+1
15 |
16 | environment:
17 | sdk: ">=2.1.0 <3.0.0"
18 |
19 | dependencies:
20 | flutter:
21 | sdk: flutter
22 | cupertino_icons: ^0.1.2
23 | openid_client: ^0.2.5
24 | url_launcher: ^5.4.5
25 | http: ^0.12.1
26 |
27 | dev_dependencies:
28 | flutter_test:
29 | sdk: flutter
30 |
31 |
32 | # For information on the generic Dart part of this file, see the
33 | # following page: https://dart.dev/tools/pub/pubspec
34 |
35 | # The following section is specific to Flutter.
36 | flutter:
37 |
38 | # The following line ensures that the Material Icons font is
39 | # included with your application, so that you can use the icons in
40 | # the material Icons class.
41 | uses-material-design: true
42 |
43 | # To add assets to your application, add an assets section, like this:
44 | # assets:
45 | # - images/a_dot_burr.jpeg
46 | # - images/a_dot_ham.jpeg
47 |
48 | # An image asset can refer to one or more resolution-specific "variants", see
49 | # https://flutter.dev/assets-and-images/#resolution-aware.
50 |
51 | # For details regarding adding assets from package dependencies, see
52 | # https://flutter.dev/assets-and-images/#from-packages
53 |
54 | # To add custom fonts to your application, add a fonts section here,
55 | # in this "flutter" section. Each entry in this list should have a
56 | # "family" key with the font family name, and a "fonts" key with a
57 | # list giving the asset and other descriptors for the font. For
58 | # example:
59 | # fonts:
60 | # - family: Schyler
61 | # fonts:
62 | # - asset: fonts/Schyler-Regular.ttf
63 | # - asset: fonts/Schyler-Italic.ttf
64 | # style: italic
65 | # - family: Trajan Pro
66 | # fonts:
67 | # - asset: fonts/TrajanPro.ttf
68 | # - asset: fonts/TrajanPro_Bold.ttf
69 | # weight: 700
70 | #
71 | # For details regarding fonts from package dependencies,
72 | # see https://flutter.dev/custom-fonts/#from-packages
73 |
--------------------------------------------------------------------------------
/IdentityServer/Program.cs:
--------------------------------------------------------------------------------
1 | using IdentityServer4.EntityFramework.DbContexts;
2 | using IdentityServer4.EntityFramework.Mappers;
3 | using Microsoft.AspNetCore.Hosting;
4 | using Microsoft.AspNetCore.Identity;
5 | using Microsoft.EntityFrameworkCore;
6 | using Microsoft.Extensions.DependencyInjection;
7 | using Microsoft.Extensions.Hosting;
8 | using System.Linq;
9 | using System.Security.Claims;
10 |
11 | namespace IdentityServer
12 | {
13 | public class Program
14 | {
15 | public static void Main(string[] args)
16 | {
17 | var host = CreateHostBuilder(args).Build();
18 |
19 | using (var scope = host.Services.CreateScope())
20 | {
21 | var userManager = scope.ServiceProvider
22 | .GetRequiredService>();
23 |
24 | var user = new IdentityUser("bob");
25 | userManager.CreateAsync(user, "password").GetAwaiter().GetResult();
26 | userManager.AddClaimAsync(user, new Claim("rc.garndma", "big.cookie"))
27 | .GetAwaiter().GetResult();
28 | userManager.AddClaimAsync(user,
29 | new Claim("rc.api.garndma", "big.api.cookie"))
30 | .GetAwaiter().GetResult();
31 |
32 | //scope.ServiceProvider.GetRequiredService()
33 | // .Database.Migrate();
34 |
35 | //var context = scope.ServiceProvider.GetRequiredService();
36 |
37 | //context.Database.Migrate();
38 |
39 | //if (!context.Clients.Any())
40 | //{
41 | // foreach (var client in Configuration.GetClients())
42 | // {
43 | // context.Clients.Add(client.ToEntity());
44 | // }
45 | // context.SaveChanges();
46 | //}
47 |
48 | //if (!context.IdentityResources.Any())
49 | //{
50 | // foreach (var resource in Configuration.GetIdentityResources())
51 | // {
52 | // context.IdentityResources.Add(resource.ToEntity());
53 | // }
54 | // context.SaveChanges();
55 | //}
56 |
57 | //if (!context.ApiResources.Any())
58 | //{
59 | // foreach (var resource in Configuration.GetApis())
60 | // {
61 | // context.ApiResources.Add(resource.ToEntity());
62 | // }
63 | // context.SaveChanges();
64 | //}
65 | }
66 |
67 | host.Run();
68 | }
69 |
70 | public static IHostBuilder CreateHostBuilder(string[] args) =>
71 | Host.CreateDefaultBuilder(args)
72 | .ConfigureWebHostDefaults(webBuilder =>
73 | {
74 | webBuilder.UseStartup();
75 | });
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/WpfApp/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WpfApp.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WpfApp.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Angular/angular-app/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/guide/browser-support
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
22 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
23 |
24 | /**
25 | * Web Animations `@angular/platform-browser/animations`
26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
28 | */
29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
30 |
31 | /**
32 | * By default, zone.js will patch all possible macroTask and DomEvents
33 | * user can disable parts of macroTask/DomEvents patch by setting following flags
34 | * because those flags need to be set before `zone.js` being loaded, and webpack
35 | * will put import in the top of bundle, so user need to create a separate file
36 | * in this directory (for example: zone-flags.ts), and put the following flags
37 | * into that file, and then add the following code before importing zone.js.
38 | * import './zone-flags';
39 | *
40 | * The flags allowed in zone-flags.ts are listed here.
41 | *
42 | * The following flags will work for all browsers.
43 | *
44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
47 | *
48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
50 | *
51 | * (window as any).__Zone_enable_cross_context_check = true;
52 | *
53 | */
54 |
55 | /***************************************************************************************************
56 | * Zone JS is required by default for Angular itself.
57 | */
58 | import 'zone.js/dist/zone'; // Included with Angular CLI.
59 |
60 |
61 | /***************************************************************************************************
62 | * APPLICATION IMPORTS
63 | */
64 |
--------------------------------------------------------------------------------
/flutter_app/lib/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:openid_client/openid_client_io.dart';
3 | import 'package:url_launcher/url_launcher.dart';
4 | import 'package:http/http.dart' as http;
5 |
6 | void main() => runApp(MyApp());
7 |
8 | class MyApp extends StatelessWidget {
9 | @override
10 | Widget build(BuildContext context) {
11 | return MaterialApp(
12 | title: 'Flutter Demo',
13 | theme: ThemeData(
14 | primarySwatch: Colors.blue,
15 | ),
16 | home: MyHomePage(title: 'Flutter Demo Home Page'),
17 | );
18 | }
19 | }
20 |
21 | class MyHomePage extends StatefulWidget {
22 | MyHomePage({Key key, this.title}) : super(key: key);
23 | final String title;
24 |
25 | @override
26 | _MyHomePageState createState() => _MyHomePageState();
27 | }
28 |
29 | class _MyHomePageState extends State {
30 | int _counter = 0;
31 |
32 | void _incrementCounter() {
33 | setState(() {
34 | _counter++;
35 | });
36 | }
37 |
38 | TokenResponse tokenResponse;
39 |
40 | void _auth() async {
41 | // create the client
42 | var uri = new Uri(scheme: "http", host: "192.168.1.107", port: 5000);
43 | var issuer = await Issuer.discover(uri);
44 | var client = new Client(issuer, "flutter");
45 |
46 | // create a function to open a browser with an url
47 | urlLauncher(String url) async {
48 | if (await canLaunch(url)) {
49 | await launch(url, forceWebView: true);
50 | } else {
51 | throw 'Could not launch $url';
52 | }
53 | }
54 |
55 | // create an authenticator
56 | var authenticator = new Authenticator(client,
57 | scopes: ["openid", "ApiOne"], port: 4000, urlLancher: urlLauncher);
58 |
59 | // starts the authentication
60 | var c = await authenticator.authorize();
61 | tokenResponse = await c.getTokenResponse();
62 |
63 | // close the webview when finished
64 | closeWebView();
65 | }
66 |
67 | void _callApi() async {
68 | var url = 'http://192.168.1.107:5002/secret';
69 | var access_token = tokenResponse.accessToken;
70 |
71 | var response = await http
72 | .get(url, headers: {"Authorization": "Bearer $access_token"});
73 | var body = response.body;
74 | var a = "";
75 | }
76 |
77 | @override
78 | Widget build(BuildContext context) {
79 | return Scaffold(
80 | appBar: AppBar(
81 | title: Text(widget.title),
82 | ),
83 | body: Center(
84 | child: Column(
85 | mainAxisAlignment: MainAxisAlignment.center,
86 | children: [
87 | OutlineButton(
88 | onPressed: _auth,
89 | child: Text("Login"),
90 | ),
91 | OutlineButton(
92 | onPressed: _callApi,
93 | child: Text("Call Api"),
94 | )
95 | ],
96 | ),
97 | ),
98 | floatingActionButton: FloatingActionButton(
99 | onPressed: _incrementCounter,
100 | tooltip: 'Increment',
101 | child: Icon(Icons.add),
102 | ),
103 | );
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/flutter_app/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-App-20x20@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-App-29x29@1x.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-App-29x29@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "29x29",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-App-29x29@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-App-40x40@2x.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "40x40",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-App-40x40@3x.png",
43 | "scale" : "3x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-App-60x60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-App-60x60@3x.png",
55 | "scale" : "3x"
56 | },
57 | {
58 | "size" : "20x20",
59 | "idiom" : "ipad",
60 | "filename" : "Icon-App-20x20@1x.png",
61 | "scale" : "1x"
62 | },
63 | {
64 | "size" : "20x20",
65 | "idiom" : "ipad",
66 | "filename" : "Icon-App-20x20@2x.png",
67 | "scale" : "2x"
68 | },
69 | {
70 | "size" : "29x29",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-App-29x29@1x.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "29x29",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-App-29x29@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "40x40",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-App-40x40@1x.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "40x40",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-App-40x40@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "76x76",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-App-76x76@1x.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "76x76",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-App-76x76@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "83.5x83.5",
107 | "idiom" : "ipad",
108 | "filename" : "Icon-App-83.5x83.5@2x.png",
109 | "scale" : "2x"
110 | },
111 | {
112 | "size" : "1024x1024",
113 | "idiom" : "ios-marketing",
114 | "filename" : "Icon-App-1024x1024@1x.png",
115 | "scale" : "1x"
116 | }
117 | ],
118 | "info" : {
119 | "version" : 1,
120 | "author" : "xcode"
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/Basics/Controllers/HomeController.cs:
--------------------------------------------------------------------------------
1 | using Basics.CustomPolicyProvider;
2 | using Microsoft.AspNetCore.Authentication;
3 | using Microsoft.AspNetCore.Authorization;
4 | using Microsoft.AspNetCore.Mvc;
5 | using System.Collections.Generic;
6 | using System.Security.Claims;
7 | using System.Threading.Tasks;
8 |
9 | namespace Basics.Controllers
10 | {
11 | public class HomeController : Controller
12 | {
13 |
14 | public IActionResult Index()
15 | {
16 | return View();
17 | }
18 |
19 | [Authorize]
20 | public IActionResult Secret()
21 | {
22 | return View();
23 | }
24 |
25 | [Authorize(Policy = "Claim.DoB")]
26 | public IActionResult SecretPolicy()
27 | {
28 | return View("Secret");
29 | }
30 |
31 | [Authorize(Roles = "Admin")]
32 | public IActionResult SecretRole()
33 | {
34 | return View("Secret");
35 | }
36 |
37 | [SecurityLevel(5)]
38 | public IActionResult SecretLevel()
39 | {
40 | return View("Secret");
41 | }
42 |
43 | [SecurityLevel(10)]
44 | public IActionResult SecretHigherLevel()
45 | {
46 | return View("Secret");
47 | }
48 |
49 | [AllowAnonymous]
50 | public IActionResult Authenticate()
51 | {
52 | var grandmaClaims = new List()
53 | {
54 | new Claim(ClaimTypes.Name, "Bob"),
55 | new Claim(ClaimTypes.Email, "Bob@fmail.com"),
56 | new Claim(ClaimTypes.DateOfBirth, "11/11/2000"),
57 | new Claim(ClaimTypes.Role, "Admin"),
58 | new Claim(ClaimTypes.Role, "AdminTwo"),
59 | new Claim(DynamicPolicies.SecurityLevel, "7"),
60 | new Claim("Grandma.Says", "Very nice boi."),
61 | };
62 |
63 | var licenseClaims = new List()
64 | {
65 | new Claim(ClaimTypes.Name, "Bob K Foo"),
66 | new Claim("DrivingLicense", "A+"),
67 | };
68 |
69 | var grandmaIdentity = new ClaimsIdentity(grandmaClaims, "Grandma Identity");
70 | var licenseIdentity = new ClaimsIdentity(licenseClaims, "Government");
71 |
72 | var userPrincipal = new ClaimsPrincipal(new[] { grandmaIdentity, licenseIdentity });
73 | //-----------------------------------------------------------
74 | HttpContext.SignInAsync(userPrincipal);
75 |
76 | return RedirectToAction("Index");
77 | }
78 |
79 | public async Task DoStuff(
80 | [FromServices] IAuthorizationService authorizationService)
81 | {
82 | // we are doing stuff here
83 |
84 | var builder = new AuthorizationPolicyBuilder("Schema");
85 | var customPolicy = builder.RequireClaim("Hello").Build();
86 |
87 | var authResult = await authorizationService.AuthorizeAsync(User, customPolicy);
88 |
89 | if (authResult.Succeeded)
90 | {
91 | return View("Index");
92 | }
93 |
94 | return View("Index");
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/Client/Startup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Security.Claims;
5 | using System.Text;
6 | using System.Text.Json.Serialization;
7 | using System.Threading.Tasks;
8 | using Microsoft.AspNetCore.Authentication.OAuth;
9 | using Microsoft.AspNetCore.Builder;
10 | using Microsoft.AspNetCore.Hosting;
11 | using Microsoft.AspNetCore.Http;
12 | using Microsoft.Extensions.DependencyInjection;
13 | using Microsoft.Extensions.Hosting;
14 | using Newtonsoft.Json;
15 |
16 | namespace Client
17 | {
18 | public class Startup
19 | {
20 | public void ConfigureServices(IServiceCollection services)
21 | {
22 | services.AddAuthentication(config => {
23 | // We check the cookie to confirm that we are authenticated
24 | config.DefaultAuthenticateScheme = "ClientCookie";
25 | // When we sign in we will deal out a cookie
26 | config.DefaultSignInScheme = "ClientCookie";
27 | // use this to check if we are allowed to do something.
28 | config.DefaultChallengeScheme = "OurServer";
29 | })
30 | .AddCookie("ClientCookie")
31 | .AddOAuth("OurServer", config => {
32 | config.ClientId = "client_id";
33 | config.ClientSecret = "client_secret";
34 | config.CallbackPath = "/oauth/callback";
35 | config.AuthorizationEndpoint = "https://localhost:44382/oauth/authorize";
36 | config.TokenEndpoint = "https://localhost:44382/oauth/token";
37 | config.SaveTokens = true;
38 |
39 | config.Events = new OAuthEvents()
40 | {
41 | OnCreatingTicket = context =>
42 | {
43 | var accessToken = context.AccessToken;
44 | var base64payload = accessToken.Split('.')[1];
45 | var bytes = Convert.FromBase64String(base64payload);
46 | var jsonPayload = Encoding.UTF8.GetString(bytes);
47 | var claims = JsonConvert.DeserializeObject>(jsonPayload);
48 |
49 | foreach(var claim in claims)
50 | {
51 | context.Identity.AddClaim(new Claim(claim.Key, claim.Value));
52 | }
53 |
54 | return Task.CompletedTask;
55 | }
56 | };
57 | });
58 |
59 | services.AddHttpClient();
60 |
61 | services.AddControllersWithViews()
62 | .AddRazorRuntimeCompilation();
63 | }
64 |
65 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
66 | {
67 | if (env.IsDevelopment())
68 | {
69 | app.UseDeveloperExceptionPage();
70 | }
71 |
72 | app.UseRouting();
73 |
74 | app.UseAuthentication();
75 |
76 | app.UseAuthorization();
77 |
78 | app.UseEndpoints(endpoints =>
79 | {
80 | endpoints.MapDefaultControllerRoute();
81 | });
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/IdentityServer/Data/Migrations/IdentityServer/PersistedGrantDb/20191201205312_InitialIdentityServerPersistedGrantDbMigration.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.EntityFrameworkCore.Migrations;
3 |
4 | namespace IdentityServer.Data.Migrations.IdentityServer.PersistedGrantDb
5 | {
6 | public partial class InitialIdentityServerPersistedGrantDbMigration : Migration
7 | {
8 | protected override void Up(MigrationBuilder migrationBuilder)
9 | {
10 | migrationBuilder.CreateTable(
11 | name: "DeviceCodes",
12 | columns: table => new
13 | {
14 | UserCode = table.Column(maxLength: 200, nullable: false),
15 | DeviceCode = table.Column(maxLength: 200, nullable: false),
16 | SubjectId = table.Column(maxLength: 200, nullable: true),
17 | ClientId = table.Column(maxLength: 200, nullable: false),
18 | CreationTime = table.Column(nullable: false),
19 | Expiration = table.Column(nullable: false),
20 | Data = table.Column(maxLength: 50000, nullable: false)
21 | },
22 | constraints: table =>
23 | {
24 | table.PrimaryKey("PK_DeviceCodes", x => x.UserCode);
25 | });
26 |
27 | migrationBuilder.CreateTable(
28 | name: "PersistedGrants",
29 | columns: table => new
30 | {
31 | Key = table.Column(maxLength: 200, nullable: false),
32 | Type = table.Column(maxLength: 50, nullable: false),
33 | SubjectId = table.Column(maxLength: 200, nullable: true),
34 | ClientId = table.Column(maxLength: 200, nullable: false),
35 | CreationTime = table.Column(nullable: false),
36 | Expiration = table.Column(nullable: true),
37 | Data = table.Column(maxLength: 50000, nullable: false)
38 | },
39 | constraints: table =>
40 | {
41 | table.PrimaryKey("PK_PersistedGrants", x => x.Key);
42 | });
43 |
44 | migrationBuilder.CreateIndex(
45 | name: "IX_DeviceCodes_DeviceCode",
46 | table: "DeviceCodes",
47 | column: "DeviceCode",
48 | unique: true);
49 |
50 | migrationBuilder.CreateIndex(
51 | name: "IX_DeviceCodes_Expiration",
52 | table: "DeviceCodes",
53 | column: "Expiration");
54 |
55 | migrationBuilder.CreateIndex(
56 | name: "IX_PersistedGrants_Expiration",
57 | table: "PersistedGrants",
58 | column: "Expiration");
59 |
60 | migrationBuilder.CreateIndex(
61 | name: "IX_PersistedGrants_SubjectId_ClientId_Type",
62 | table: "PersistedGrants",
63 | columns: new[] { "SubjectId", "ClientId", "Type" });
64 | }
65 |
66 | protected override void Down(MigrationBuilder migrationBuilder)
67 | {
68 | migrationBuilder.DropTable(
69 | name: "DeviceCodes");
70 |
71 | migrationBuilder.DropTable(
72 | name: "PersistedGrants");
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/MvcClient/Controllers/HomeController.cs:
--------------------------------------------------------------------------------
1 | using IdentityModel.Client;
2 | using Microsoft.AspNetCore.Authentication;
3 | using Microsoft.AspNetCore.Authorization;
4 | using Microsoft.AspNetCore.Mvc;
5 | using System.IdentityModel.Tokens.Jwt;
6 | using System.Linq;
7 | using System.Net.Http;
8 | using System.Threading.Tasks;
9 |
10 | namespace MvcClient.Controllers
11 | {
12 | public class HomeController : Controller
13 | {
14 | private readonly IHttpClientFactory _httpClientFactory;
15 |
16 | public HomeController(IHttpClientFactory httpClientFactory)
17 | {
18 | _httpClientFactory = httpClientFactory;
19 | }
20 |
21 | public IActionResult Index()
22 | {
23 | return View();
24 | }
25 |
26 | [Authorize]
27 | public async Task Secret()
28 | {
29 | var accessToken = await HttpContext.GetTokenAsync("access_token");
30 | var idToken = await HttpContext.GetTokenAsync("id_token");
31 | var refreshToken = await HttpContext.GetTokenAsync("refresh_token");
32 |
33 | var claims = User.Claims.ToList();
34 | var _accessToken = new JwtSecurityTokenHandler().ReadJwtToken(accessToken);
35 | var _idToken = new JwtSecurityTokenHandler().ReadJwtToken(idToken);
36 |
37 | var result = await GetSecret(accessToken);
38 |
39 | await RefreshAccessToken();
40 |
41 | return View();
42 | }
43 |
44 | public IActionResult Logout()
45 | {
46 | return SignOut("Cookie", "oidc");
47 | }
48 |
49 | public async Task GetSecret(string accessToken)
50 | {
51 | var apiClient = _httpClientFactory.CreateClient();
52 |
53 | apiClient.SetBearerToken(accessToken);
54 |
55 | var response = await apiClient.GetAsync("https://localhost:44337/secret");
56 |
57 | var content = await response.Content.ReadAsStringAsync();
58 |
59 | return content;
60 | }
61 |
62 | private async Task RefreshAccessToken()
63 | {
64 | var serverClient = _httpClientFactory.CreateClient();
65 | var discoveryDocument = await serverClient.GetDiscoveryDocumentAsync("https://localhost:44305/");
66 |
67 | var accessToken = await HttpContext.GetTokenAsync("access_token");
68 | var idToken = await HttpContext.GetTokenAsync("id_token");
69 | var refreshToken = await HttpContext.GetTokenAsync("refresh_token");
70 | var refreshTokenClient = _httpClientFactory.CreateClient();
71 |
72 | var tokenResponse = await refreshTokenClient.RequestRefreshTokenAsync(
73 | new RefreshTokenRequest
74 | {
75 | Address = discoveryDocument.TokenEndpoint,
76 | RefreshToken = refreshToken,
77 | ClientId = "client_id_mvc",
78 | ClientSecret = "client_secret_mvc"
79 | });
80 |
81 | var authInfo = await HttpContext.AuthenticateAsync("Cookie");
82 |
83 | authInfo.Properties.UpdateTokenValue("access_token", tokenResponse.AccessToken);
84 | authInfo.Properties.UpdateTokenValue("id_token", tokenResponse.IdentityToken);
85 | authInfo.Properties.UpdateTokenValue("refresh_token", tokenResponse.RefreshToken);
86 |
87 | await HttpContext.SignInAsync("Cookie", authInfo.Principal, authInfo.Properties);
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/Basics/CustomPolicyProvider/CustomAuthorizationPolicyProvider.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authorization;
2 | using Microsoft.Extensions.Options;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 |
8 | namespace Basics.CustomPolicyProvider
9 | {
10 | public class SecurityLevelAttribute : AuthorizeAttribute
11 | {
12 | public SecurityLevelAttribute(int level)
13 | {
14 | Policy = $"{DynamicPolicies.SecurityLevel}.{level}";
15 | }
16 | }
17 |
18 | // {type}
19 | public static class DynamicPolicies
20 | {
21 | public static IEnumerable Get()
22 | {
23 | yield return SecurityLevel;
24 | yield return Rank;
25 | }
26 |
27 | public const string SecurityLevel = "SecurityLevel";
28 | public const string Rank = "Rank";
29 | }
30 |
31 | public static class DynamicAuthorizationPilicyFactory
32 | {
33 | public static AuthorizationPolicy Create(string policyName)
34 | {
35 | var parts = policyName.Split('.');
36 | var type = parts.First();
37 | var value = parts.Last();
38 |
39 | switch (type)
40 | {
41 | case DynamicPolicies.Rank:
42 | return new AuthorizationPolicyBuilder()
43 | .RequireClaim("Rank", value)
44 | .Build();
45 | case DynamicPolicies.SecurityLevel:
46 | return new AuthorizationPolicyBuilder()
47 | .AddRequirements(new SecurityLevelRequirement(Convert.ToInt32(value)))
48 | .Build();
49 | default:
50 | return null;
51 | }
52 | }
53 | }
54 |
55 | public class SecurityLevelRequirement : IAuthorizationRequirement
56 | {
57 | public int Level { get; }
58 | public SecurityLevelRequirement(int level)
59 | {
60 | Level = level;
61 | }
62 | }
63 |
64 | public class SecurityLevelHandler : AuthorizationHandler
65 | {
66 | protected override Task HandleRequirementAsync(
67 | AuthorizationHandlerContext context,
68 | SecurityLevelRequirement requirement)
69 | {
70 | var claimValue = Convert.ToInt32(context.User.Claims
71 | .FirstOrDefault(x => x.Type == DynamicPolicies.SecurityLevel)
72 | ?.Value ?? "0");
73 |
74 | if (requirement.Level <= claimValue)
75 | {
76 | context.Succeed(requirement);
77 | }
78 | return Task.CompletedTask;
79 | }
80 | }
81 |
82 | public class CustomAuthorizationPolicyProvider
83 | : DefaultAuthorizationPolicyProvider
84 | {
85 | public CustomAuthorizationPolicyProvider(IOptions options) : base(options)
86 | {
87 | }
88 |
89 | public override Task GetPolicyAsync(string policyName)
90 | {
91 | foreach (var customPolicy in DynamicPolicies.Get())
92 | {
93 | if (policyName.StartsWith(customPolicy))
94 | {
95 | var policy = DynamicAuthorizationPilicyFactory.Create(policyName);
96 |
97 | return Task.FromResult(policy);
98 | }
99 | }
100 |
101 | return base.GetPolicyAsync(policyName);
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/flutter_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/Angular/angular-app/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "tslint:recommended",
3 | "rules": {
4 | "align": {
5 | "options": [
6 | "parameters",
7 | "statements"
8 | ]
9 | },
10 | "array-type": false,
11 | "arrow-return-shorthand": true,
12 | "curly": true,
13 | "deprecation": {
14 | "severity": "warning"
15 | },
16 | "component-class-suffix": true,
17 | "contextual-lifecycle": true,
18 | "directive-class-suffix": true,
19 | "directive-selector": [
20 | true,
21 | "attribute",
22 | "app",
23 | "camelCase"
24 | ],
25 | "component-selector": [
26 | true,
27 | "element",
28 | "app",
29 | "kebab-case"
30 | ],
31 | "eofline": true,
32 | "import-blacklist": [
33 | true,
34 | "rxjs/Rx"
35 | ],
36 | "import-spacing": true,
37 | "indent": {
38 | "options": [
39 | "spaces"
40 | ]
41 | },
42 | "max-classes-per-file": false,
43 | "max-line-length": [
44 | true,
45 | 140
46 | ],
47 | "member-ordering": [
48 | true,
49 | {
50 | "order": [
51 | "static-field",
52 | "instance-field",
53 | "static-method",
54 | "instance-method"
55 | ]
56 | }
57 | ],
58 | "no-console": [
59 | true,
60 | "debug",
61 | "info",
62 | "time",
63 | "timeEnd",
64 | "trace"
65 | ],
66 | "no-empty": false,
67 | "no-inferrable-types": [
68 | true,
69 | "ignore-params"
70 | ],
71 | "no-non-null-assertion": true,
72 | "no-redundant-jsdoc": true,
73 | "no-switch-case-fall-through": true,
74 | "no-var-requires": false,
75 | "object-literal-key-quotes": [
76 | true,
77 | "as-needed"
78 | ],
79 | "quotemark": [
80 | true,
81 | "single"
82 | ],
83 | "semicolon": {
84 | "options": [
85 | "always"
86 | ]
87 | },
88 | "space-before-function-paren": {
89 | "options": {
90 | "anonymous": "never",
91 | "asyncArrow": "always",
92 | "constructor": "never",
93 | "method": "never",
94 | "named": "never"
95 | }
96 | },
97 | "typedef-whitespace": {
98 | "options": [
99 | {
100 | "call-signature": "nospace",
101 | "index-signature": "nospace",
102 | "parameter": "nospace",
103 | "property-declaration": "nospace",
104 | "variable-declaration": "nospace"
105 | },
106 | {
107 | "call-signature": "onespace",
108 | "index-signature": "onespace",
109 | "parameter": "onespace",
110 | "property-declaration": "onespace",
111 | "variable-declaration": "onespace"
112 | }
113 | ]
114 | },
115 | "variable-name": {
116 | "options": [
117 | "ban-keywords",
118 | "check-format",
119 | "allow-pascal-case"
120 | ]
121 | },
122 | "whitespace": {
123 | "options": [
124 | "check-branch",
125 | "check-decl",
126 | "check-operator",
127 | "check-separator",
128 | "check-type",
129 | "check-typecast"
130 | ]
131 | },
132 | "no-conflicting-lifecycle": true,
133 | "no-host-metadata-property": true,
134 | "no-input-rename": true,
135 | "no-inputs-metadata-property": true,
136 | "no-output-native": true,
137 | "no-output-on-prefix": true,
138 | "no-output-rename": true,
139 | "no-outputs-metadata-property": true,
140 | "template-banana-in-box": true,
141 | "template-no-negated-async": true,
142 | "use-lifecycle-interface": true,
143 | "use-pipe-transform-interface": true
144 | },
145 | "rulesDirectory": [
146 | "codelyzer"
147 | ]
148 | }
--------------------------------------------------------------------------------
/IdentityExample/Controllers/HomeController.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authorization;
2 | using Microsoft.AspNetCore.Identity;
3 | using Microsoft.AspNetCore.Mvc;
4 | using NETCore.MailKit.Core;
5 | using System.Threading.Tasks;
6 |
7 | namespace IdentityExample.Controllers
8 | {
9 | public class HomeController : Controller
10 | {
11 | private readonly UserManager _userManager;
12 | private readonly SignInManager _signInManager;
13 | private readonly IEmailService _emailService;
14 |
15 | public HomeController(
16 | UserManager userManager,
17 | SignInManager signInManager,
18 | IEmailService emailService)
19 | {
20 | _userManager = userManager;
21 | _signInManager = signInManager;
22 | _emailService = emailService;
23 | }
24 |
25 | public IActionResult Index()
26 | {
27 | return View();
28 | }
29 |
30 | [Authorize]
31 | public IActionResult Secret()
32 | {
33 | return View();
34 | }
35 | public IActionResult Login()
36 | {
37 | return View();
38 | }
39 |
40 | [HttpPost]
41 | public async Task Login(string username, string password)
42 | {
43 | //login functionality
44 | var user = await _userManager.FindByNameAsync(username);
45 |
46 | if (user != null)
47 | {
48 | //sign in
49 | var signInResult = await _signInManager.PasswordSignInAsync(user, password, false, false);
50 |
51 | if (signInResult.Succeeded)
52 | {
53 | return RedirectToAction("Index");
54 | }
55 | }
56 |
57 | return RedirectToAction("Index");
58 | }
59 |
60 | public IActionResult Register()
61 | {
62 | return View();
63 | }
64 |
65 | [HttpPost]
66 | public async Task Register(string username, string password)
67 | {
68 | //register functionality
69 |
70 | var user = new IdentityUser
71 | {
72 | UserName = username,
73 | Email = "",
74 | };
75 |
76 | var result = await _userManager.CreateAsync(user, password);
77 |
78 | if (result.Succeeded)
79 | {
80 | //generation of the email token
81 | var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
82 |
83 | var link = Url.Action(nameof(VerifyEmail), "Home", new { userId = user.Id, code }, Request.Scheme, Request.Host.ToString());
84 |
85 | await _emailService.SendAsync("test@test.com", "email verify", $"Verify Email", true);
86 |
87 | return RedirectToAction("EmailVerification");
88 | }
89 |
90 | return RedirectToAction("Index");
91 | }
92 |
93 | public async Task VerifyEmail(string userId, string code)
94 | {
95 | var user = await _userManager.FindByIdAsync(userId);
96 |
97 | if (user == null) return BadRequest();
98 |
99 | var result = await _userManager.ConfirmEmailAsync(user, code);
100 |
101 | if (result.Succeeded)
102 | {
103 | return View();
104 | }
105 |
106 | return BadRequest();
107 | }
108 |
109 | public IActionResult EmailVerification() => View();
110 |
111 | public async Task LogOut()
112 | {
113 | await _signInManager.SignOutAsync();
114 | return RedirectToAction("Index");
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/Server/Controllers/OAuthController.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Authorization;
2 | using Microsoft.AspNetCore.Http.Extensions;
3 | using Microsoft.AspNetCore.Mvc;
4 | using Microsoft.IdentityModel.Tokens;
5 | using Newtonsoft.Json;
6 | using System;
7 | using System.IdentityModel.Tokens.Jwt;
8 | using System.Security.Claims;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 |
12 | namespace Server.Controllers
13 | {
14 | public class OAuthController : Controller
15 | {
16 | [HttpGet]
17 | public IActionResult Authorize(
18 | string response_type, // authorization flow type
19 | string client_id, // client id
20 | string redirect_uri,
21 | string scope, // what info I want = email,grandma,tel
22 | string state) // random string generated to confirm that we are going to back to the same client
23 | {
24 | // ?a=foo&b=bar
25 | var query = new QueryBuilder();
26 | query.Add("redirectUri", redirect_uri);
27 | query.Add("state", state);
28 |
29 | return View(model: query.ToString());
30 | }
31 |
32 | [HttpPost]
33 | public IActionResult Authorize(
34 | string username,
35 | string redirectUri,
36 | string state)
37 | {
38 | const string code = "BABAABABABA";
39 |
40 | var query = new QueryBuilder();
41 | query.Add("code", code);
42 | query.Add("state", state);
43 |
44 |
45 | return Redirect($"{redirectUri}{query.ToString()}");
46 | }
47 |
48 | public async Task Token(
49 | string grant_type, // flow of access_token request
50 | string code, // confirmation of the authentication process
51 | string redirect_uri,
52 | string client_id,
53 | string refresh_token)
54 | {
55 | // some mechanism for validating the code
56 |
57 | var claims = new[]
58 | {
59 | new Claim(JwtRegisteredClaimNames.Sub, "some_id"),
60 | new Claim("granny", "cookie")
61 | };
62 |
63 | var secretBytes = Encoding.UTF8.GetBytes(Constants.Secret);
64 | var key = new SymmetricSecurityKey(secretBytes);
65 | var algorithm = SecurityAlgorithms.HmacSha256;
66 |
67 | var signingCredentials = new SigningCredentials(key, algorithm);
68 |
69 | var token = new JwtSecurityToken(
70 | Constants.Issuer,
71 | Constants.Audiance,
72 | claims,
73 | notBefore: DateTime.Now,
74 | expires: grant_type == "refresh_token"
75 | ? DateTime.Now.AddMinutes(5)
76 | : DateTime.Now.AddMilliseconds(1),
77 | signingCredentials);
78 |
79 | var access_token = new JwtSecurityTokenHandler().WriteToken(token);
80 |
81 | var responseObject = new
82 | {
83 | access_token,
84 | token_type = "Bearer",
85 | raw_claim = "oauthTutorial",
86 | refresh_token = "RefreshTokenSampleValueSomething77"
87 | };
88 |
89 | var responseJson = JsonConvert.SerializeObject(responseObject);
90 | var responseBytes = Encoding.UTF8.GetBytes(responseJson);
91 |
92 | await Response.Body.WriteAsync(responseBytes, 0, responseBytes.Length);
93 |
94 | return Redirect(redirect_uri);
95 | }
96 |
97 | [Authorize]
98 | public IActionResult Validate()
99 | {
100 | if (HttpContext.Request.Query.TryGetValue("access_token", out var accessToken))
101 | {
102 |
103 | return Ok();
104 | }
105 | return BadRequest();
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------