├── .gitignore ├── client ├── angular-oidc-oauth2-ngrx │ ├── .editorconfig │ ├── .gitignore │ ├── README.md │ ├── angular.json │ ├── browserslist │ ├── e2e │ │ ├── protractor.conf.js │ │ ├── src │ │ │ ├── app.e2e-spec.ts │ │ │ └── app.po.ts │ │ └── tsconfig.json │ ├── karma.conf.js │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── app │ │ │ ├── app-routing.module.ts │ │ │ ├── app.component.css │ │ │ ├── app.component.html │ │ │ ├── app.component.spec.ts │ │ │ ├── app.component.ts │ │ │ ├── app.module.ts │ │ │ ├── auth.guard.ts │ │ │ ├── auth.interceptor.ts │ │ │ ├── home │ │ │ │ ├── home.component.css │ │ │ │ ├── home.component.html │ │ │ │ ├── home.component.spec.ts │ │ │ │ └── home.component.ts │ │ │ ├── protected │ │ │ │ ├── protected.component.css │ │ │ │ ├── protected.component.html │ │ │ │ ├── protected.component.spec.ts │ │ │ │ └── protected.component.ts │ │ │ ├── services │ │ │ │ ├── auth.service.ts │ │ │ │ └── data.service.ts │ │ │ ├── store │ │ │ │ ├── auth │ │ │ │ │ ├── auth.actions.ts │ │ │ │ │ ├── auth.effects.ts │ │ │ │ │ ├── auth.reducer.ts │ │ │ │ │ ├── auth.selectors.ts │ │ │ │ │ └── index.ts │ │ │ │ ├── data │ │ │ │ │ ├── data.actions.ts │ │ │ │ │ ├── data.effects.ts │ │ │ │ │ ├── data.reducer.ts │ │ │ │ │ ├── data.selectors.ts │ │ │ │ │ └── index.ts │ │ │ │ └── index.ts │ │ │ └── unauthorized │ │ │ │ ├── unauthorized.component.css │ │ │ │ ├── unauthorized.component.html │ │ │ │ ├── unauthorized.component.spec.ts │ │ │ │ └── unauthorized.component.ts │ │ ├── assets │ │ │ └── .gitkeep │ │ ├── environments │ │ │ ├── environment.prod.ts │ │ │ └── environment.ts │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── main.ts │ │ ├── polyfills.ts │ │ ├── styles.css │ │ └── test.ts │ ├── tsconfig.app.json │ ├── tsconfig.json │ ├── tsconfig.spec.json │ └── tslint.json └── angular-oidc-oauth2 │ ├── .editorconfig │ ├── README.md │ ├── angular.json │ ├── browserslist │ ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json │ ├── karma.conf.js │ ├── package-lock.json │ ├── package.json │ ├── src │ ├── app │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── auth.interceptor.ts │ │ ├── auth.service.ts │ │ ├── home │ │ │ ├── home.component.css │ │ │ ├── home.component.html │ │ │ ├── home.component.spec.ts │ │ │ └── home.component.ts │ │ └── unauthorized │ │ │ ├── unauthorized.component.css │ │ │ ├── unauthorized.component.html │ │ │ ├── unauthorized.component.spec.ts │ │ │ └── unauthorized.component.ts │ ├── assets │ │ └── .gitkeep │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ └── test.ts │ ├── tsconfig.app.json │ ├── tsconfig.json │ ├── tsconfig.spec.json │ └── tslint.json ├── readme.md └── server ├── Controllers └── SecureValuesController.cs ├── Program.cs ├── Properties └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json └── server.csproj /.gitignore: -------------------------------------------------------------------------------- 1 | /server/bin 2 | /server/obj/ 3 | /client/angular-oidc-oauth2/node_modules 4 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/.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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/.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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/README.md: -------------------------------------------------------------------------------- 1 | # AngularOidcOauth2Ngrx 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.3. 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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "angular-oidc-oauth2-ngrx": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/angular-oidc-oauth2-ngrx", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "tsconfig.app.json", 21 | "aot": true, 22 | "assets": [ 23 | "src/favicon.ico", 24 | "src/assets" 25 | ], 26 | "styles": [ 27 | "src/styles.css" 28 | ], 29 | "scripts": [] 30 | }, 31 | "configurations": { 32 | "production": { 33 | "fileReplacements": [ 34 | { 35 | "replace": "src/environments/environment.ts", 36 | "with": "src/environments/environment.prod.ts" 37 | } 38 | ], 39 | "optimization": true, 40 | "outputHashing": "all", 41 | "sourceMap": false, 42 | "extractCss": true, 43 | "namedChunks": false, 44 | "extractLicenses": true, 45 | "vendorChunk": false, 46 | "buildOptimizer": true, 47 | "budgets": [ 48 | { 49 | "type": "initial", 50 | "maximumWarning": "2mb", 51 | "maximumError": "5mb" 52 | }, 53 | { 54 | "type": "anyComponentStyle", 55 | "maximumWarning": "6kb", 56 | "maximumError": "10kb" 57 | } 58 | ] 59 | } 60 | } 61 | }, 62 | "serve": { 63 | "builder": "@angular-devkit/build-angular:dev-server", 64 | "options": { 65 | "browserTarget": "angular-oidc-oauth2-ngrx:build" 66 | }, 67 | "configurations": { 68 | "production": { 69 | "browserTarget": "angular-oidc-oauth2-ngrx:build:production" 70 | } 71 | } 72 | }, 73 | "extract-i18n": { 74 | "builder": "@angular-devkit/build-angular:extract-i18n", 75 | "options": { 76 | "browserTarget": "angular-oidc-oauth2-ngrx:build" 77 | } 78 | }, 79 | "test": { 80 | "builder": "@angular-devkit/build-angular:karma", 81 | "options": { 82 | "main": "src/test.ts", 83 | "polyfills": "src/polyfills.ts", 84 | "tsConfig": "tsconfig.spec.json", 85 | "karmaConfig": "karma.conf.js", 86 | "assets": [ 87 | "src/favicon.ico", 88 | "src/assets" 89 | ], 90 | "styles": [ 91 | "src/styles.css" 92 | ], 93 | "scripts": [] 94 | } 95 | }, 96 | "lint": { 97 | "builder": "@angular-devkit/build-angular:tslint", 98 | "options": { 99 | "tsConfig": [ 100 | "tsconfig.app.json", 101 | "tsconfig.spec.json", 102 | "e2e/tsconfig.json" 103 | ], 104 | "exclude": [ 105 | "**/node_modules/**" 106 | ] 107 | } 108 | }, 109 | "e2e": { 110 | "builder": "@angular-devkit/build-angular:protractor", 111 | "options": { 112 | "protractorConfig": "e2e/protractor.conf.js", 113 | "devServerTarget": "angular-oidc-oauth2-ngrx:serve" 114 | }, 115 | "configurations": { 116 | "production": { 117 | "devServerTarget": "angular-oidc-oauth2-ngrx:serve:production" 118 | } 119 | } 120 | } 121 | } 122 | } 123 | }, 124 | "defaultProject": "angular-oidc-oauth2-ngrx", 125 | "cli": { 126 | "analytics": false 127 | } 128 | } -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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'. -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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 | }; -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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-oidc-oauth2-ngrx 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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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-oidc-oauth2-ngrx'), 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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-oidc-oauth2-ngrx", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve --ssl", 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.3", 15 | "@angular/common": "~9.1.3", 16 | "@angular/compiler": "~9.1.3", 17 | "@angular/core": "~9.1.3", 18 | "@angular/forms": "~9.1.3", 19 | "@angular/platform-browser": "~9.1.3", 20 | "@angular/platform-browser-dynamic": "~9.1.3", 21 | "@angular/router": "~9.1.3", 22 | "@ngrx/effects": "^9.1.2", 23 | "@ngrx/store": "^9.1.2", 24 | "angular-auth-oidc-client": "^11.1.1", 25 | "rxjs": "~6.5.4", 26 | "tslib": "^1.10.0", 27 | "zone.js": "~0.10.2" 28 | }, 29 | "devDependencies": { 30 | "@angular-devkit/build-angular": "~0.901.3", 31 | "@angular/cli": "~9.1.3", 32 | "@angular/compiler-cli": "~9.1.3", 33 | "@angular/language-service": "~9.1.3", 34 | "@types/node": "^12.11.1", 35 | "@types/jasmine": "~3.5.0", 36 | "@types/jasminewd2": "~2.0.3", 37 | "codelyzer": "^5.1.2", 38 | "jasmine-core": "~3.5.0", 39 | "jasmine-spec-reporter": "~4.2.1", 40 | "karma": "~5.0.0", 41 | "karma-chrome-launcher": "~3.1.0", 42 | "karma-coverage-istanbul-reporter": "~2.1.0", 43 | "karma-jasmine": "~3.0.1", 44 | "karma-jasmine-html-reporter": "^1.4.2", 45 | "protractor": "~5.4.3", 46 | "ts-node": "~8.3.0", 47 | "tslint": "~6.1.0", 48 | "typescript": "~3.8.3" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { HomeComponent } from './home/home.component'; 4 | import { UnauthorizedComponent } from './unauthorized/unauthorized.component'; 5 | import { ProtectedComponent } from './protected/protected.component'; 6 | import { AuthorizationGuard } from './auth.guard'; 7 | 8 | const routes: Routes = [ 9 | { path: '', redirectTo: 'home', pathMatch: 'full' }, 10 | { path: 'home', component: HomeComponent }, 11 | { 12 | path: 'protected', 13 | component: ProtectedComponent, 14 | canActivate: [AuthorizationGuard], 15 | }, 16 | { path: 'unauthorized', component: UnauthorizedComponent }, 17 | ]; 18 | 19 | @NgModule({ 20 | imports: [RouterModule.forRoot(routes)], 21 | exports: [RouterModule], 22 | }) 23 | export class AppRoutingModule {} 24 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FabianGosebrink/angular-oauth2-oidc-sample/efb3cb9287ff83c37fceded71fef0aff8295ae24/client/angular-oidc-oauth2-ngrx/src/app/app.component.css -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |

Authentication with ngrx

2 | 3 |
4 | home | 5 | protected | 6 | 7 | 8 |
9 | 10 | 11 | home | 12 | 13 |
14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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-oidc-oauth2-ngrx'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('angular-oidc-oauth2-ngrx'); 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-oidc-oauth2-ngrx app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Store, select } from '@ngrx/store'; 3 | import { checkAuth, selectIsAuthenticated, login, logout } from './store'; 4 | import { Observable } from 'rxjs'; 5 | 6 | @Component({ 7 | selector: 'app-root', 8 | templateUrl: './app.component.html', 9 | styleUrls: ['./app.component.css'], 10 | }) 11 | export class AppComponent implements OnInit { 12 | isAuthenticated$: Observable; 13 | constructor(private store: Store) {} 14 | 15 | ngOnInit() { 16 | this.store.dispatch(checkAuth()); 17 | 18 | this.isAuthenticated$ = this.store.pipe(select(selectIsAuthenticated)); 19 | } 20 | 21 | login() { 22 | this.store.dispatch(login()); 23 | } 24 | 25 | logout() { 26 | this.store.dispatch(logout()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { APP_INITIALIZER, NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | import { AuthModule, OidcConfigService } from 'angular-auth-oidc-client'; 4 | import { AppComponent } from './app.component'; 5 | import { HomeComponent } from './home/home.component'; 6 | import { UnauthorizedComponent } from './unauthorized/unauthorized.component'; 7 | import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; 8 | import { AuthInterceptor } from './auth.interceptor'; 9 | import { StoreModule } from '@ngrx/store'; 10 | import { EffectsModule } from '@ngrx/effects'; 11 | import { appReducer, appEffects } from './store'; 12 | import { AppRoutingModule } from './app-routing.module'; 13 | import { ProtectedComponent } from './protected/protected.component'; 14 | 15 | export function configureAuth(oidcConfigService: OidcConfigService) { 16 | return () => 17 | oidcConfigService.withConfig({ 18 | stsServer: 'https://offeringsolutions-sts.azurewebsites.net', 19 | redirectUrl: window.location.origin, 20 | postLogoutRedirectUri: window.location.origin, 21 | clientId: 'angularClientForHoorayApi', 22 | scope: 'openid profile email offline_access hooray_Api', 23 | responseType: 'code', 24 | silentRenew: true, 25 | useRefreshToken: true, 26 | }); 27 | } 28 | 29 | @NgModule({ 30 | declarations: [AppComponent, HomeComponent, UnauthorizedComponent, ProtectedComponent], 31 | imports: [ 32 | BrowserModule, 33 | AppRoutingModule, 34 | AuthModule.forRoot(), 35 | StoreModule.forRoot(appReducer), 36 | EffectsModule.forRoot(appEffects), 37 | HttpClientModule, 38 | ], 39 | providers: [ 40 | OidcConfigService, 41 | { 42 | provide: APP_INITIALIZER, 43 | useFactory: configureAuth, 44 | deps: [OidcConfigService], 45 | multi: true, 46 | }, 47 | { 48 | provide: HTTP_INTERCEPTORS, 49 | useClass: AuthInterceptor, 50 | multi: true, 51 | }, 52 | ], 53 | bootstrap: [AppComponent], 54 | }) 55 | export class AppModule {} 56 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/auth.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { 3 | ActivatedRouteSnapshot, 4 | CanActivate, 5 | Router, 6 | RouterStateSnapshot, 7 | } from '@angular/router'; 8 | import { Observable } from 'rxjs'; 9 | import { map, tap } from 'rxjs/operators'; 10 | import { AuthService } from './services/auth.service'; 11 | 12 | @Injectable({ providedIn: 'root' }) 13 | export class AuthorizationGuard implements CanActivate { 14 | constructor(private authService: AuthService, private router: Router) {} 15 | 16 | canActivate( 17 | route: ActivatedRouteSnapshot, 18 | state: RouterStateSnapshot 19 | ): Observable { 20 | return this.authService.isLoggedIn.pipe( 21 | map((isAuthorized: boolean) => { 22 | if (!isAuthorized) { 23 | this.router.navigate(['/unauthorized']); 24 | return false; 25 | } 26 | 27 | return true; 28 | }) 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/auth.interceptor.ts: -------------------------------------------------------------------------------- 1 | import { 2 | HttpInterceptor, 3 | HttpRequest, 4 | HttpHandler, 5 | } from '@angular/common/http'; 6 | import { Injectable } from '@angular/core'; 7 | import { AuthService } from './services/auth.service'; 8 | 9 | @Injectable() 10 | export class AuthInterceptor implements HttpInterceptor { 11 | private secureRoutes = ['https://localhost:5001/api']; 12 | 13 | constructor(private authService: AuthService) {} 14 | 15 | intercept(request: HttpRequest, next: HttpHandler) { 16 | if (!this.secureRoutes.find((x) => request.url.startsWith(x))) { 17 | return next.handle(request); 18 | } 19 | 20 | const token = this.authService.token; 21 | 22 | if (!token) { 23 | return next.handle(request); 24 | } 25 | 26 | request = request.clone({ 27 | headers: request.headers.set('Authorization', 'Bearer ' + token), 28 | }); 29 | 30 | return next.handle(request); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/home/home.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FabianGosebrink/angular-oauth2-oidc-sample/efb3cb9287ff83c37fceded71fef0aff8295ae24/client/angular-oidc-oauth2-ngrx/src/app/home/home.component.css -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/home/home.component.html: -------------------------------------------------------------------------------- 1 |
Welcome to home Route
2 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/home/home.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { HomeComponent } from './home.component'; 4 | 5 | describe('HomeComponent', () => { 6 | let component: HomeComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ HomeComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(HomeComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/home/home.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-home', 5 | templateUrl: 'home.component.html', 6 | }) 7 | export class HomeComponent implements OnInit { 8 | ngOnInit() {} 9 | } 10 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/protected/protected.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FabianGosebrink/angular-oauth2-oidc-sample/efb3cb9287ff83c37fceded71fef0aff8295ae24/client/angular-oidc-oauth2-ngrx/src/app/protected/protected.component.css -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/protected/protected.component.html: -------------------------------------------------------------------------------- 1 |

protected works!

2 | 3 |

Userdata

4 |
{{ userData | json }}
5 | 6 |
7 |

Secret Data

8 |
{{ secretData | json }}
9 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/protected/protected.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | import { ProtectedComponent } from './protected.component'; 3 | 4 | describe('ProtectedComponent', () => { 5 | let component: ProtectedComponent; 6 | let fixture: ComponentFixture; 7 | 8 | beforeEach(async(() => { 9 | TestBed.configureTestingModule({ 10 | declarations: [ProtectedComponent], 11 | }).compileComponents(); 12 | })); 13 | 14 | beforeEach(() => { 15 | fixture = TestBed.createComponent(ProtectedComponent); 16 | component = fixture.componentInstance; 17 | fixture.detectChanges(); 18 | }); 19 | 20 | it('should create', () => { 21 | expect(component).toBeTruthy(); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/protected/protected.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Observable } from 'rxjs'; 3 | import { Store, select } from '@ngrx/store'; 4 | import { selectuserInfo, getData, selectData } from '../store'; 5 | 6 | @Component({ 7 | selector: 'app-protected', 8 | templateUrl: './protected.component.html', 9 | styleUrls: ['./protected.component.css'], 10 | }) 11 | export class ProtectedComponent implements OnInit { 12 | secretData$: Observable; 13 | userData$: Observable; 14 | 15 | constructor(private store: Store) {} 16 | 17 | ngOnInit(): void { 18 | this.userData$ = this.store.pipe(select(selectuserInfo)); 19 | this.secretData$ = this.store.pipe(select(selectData)); 20 | this.store.dispatch(getData()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/services/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { of } from 'rxjs'; 3 | import { OidcSecurityService } from 'angular-auth-oidc-client'; 4 | 5 | @Injectable({ providedIn: 'root' }) 6 | export class AuthService { 7 | constructor(private oidcSecurityService: OidcSecurityService) {} 8 | 9 | get isLoggedIn() { 10 | return this.oidcSecurityService.isAuthenticated$; 11 | } 12 | 13 | get token() { 14 | return this.oidcSecurityService.getToken(); 15 | } 16 | 17 | get userData() { 18 | return this.oidcSecurityService.userData$; 19 | } 20 | 21 | checkAuth() { 22 | return this.oidcSecurityService.checkAuth(); 23 | } 24 | 25 | doLogin() { 26 | return of(this.oidcSecurityService.authorize()); 27 | } 28 | 29 | signOut() { 30 | this.oidcSecurityService.logoffAndRevokeTokens(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/services/data.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { of } from 'rxjs'; 3 | import { HttpClient } from '@angular/common/http'; 4 | import { catchError } from 'rxjs/operators'; 5 | 6 | @Injectable({ providedIn: 'root' }) 7 | export class DataService { 8 | constructor(private httpClient: HttpClient) {} 9 | 10 | getData() { 11 | return this.httpClient 12 | .get('https://localhost:5001/api/securevalues') 13 | .pipe(catchError((error) => of(error))); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/store/auth/auth.actions.ts: -------------------------------------------------------------------------------- 1 | import { createAction, props } from '@ngrx/store'; 2 | 3 | export const checkAuth = createAction('[Auth] checkAuth'); 4 | export const checkAuthComplete = createAction( 5 | '[Auth] checkAuthComplete', 6 | props<{ isLoggedIn: boolean }>() 7 | ); 8 | export const login = createAction('[Auth] login'); 9 | export const loginComplete = createAction( 10 | '[Auth] loginComplete', 11 | props<{ profile: any; isLoggedIn: boolean }>() 12 | ); 13 | export const logout = createAction('[Auth] logout'); 14 | export const logoutComplete = createAction('[Auth] logoutComplete'); 15 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/store/auth/auth.effects.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Actions, createEffect, ofType } from '@ngrx/effects'; 3 | import { map, switchMap, tap } from 'rxjs/operators'; 4 | import * as fromAuthActions from './auth.actions'; 5 | import { Router } from '@angular/router'; 6 | import { of } from 'rxjs'; 7 | import { AuthService } from '../../services/auth.service'; 8 | 9 | @Injectable() 10 | export class AuthEffects { 11 | constructor( 12 | private actions$: Actions, 13 | private authService: AuthService, 14 | private router: Router 15 | ) {} 16 | 17 | login$ = createEffect( 18 | () => 19 | this.actions$.pipe( 20 | ofType(fromAuthActions.login), 21 | switchMap(() => this.authService.doLogin()) 22 | ), 23 | { dispatch: false } 24 | ); 25 | 26 | checkauth$ = createEffect(() => 27 | this.actions$.pipe( 28 | ofType(fromAuthActions.checkAuth), 29 | switchMap(() => 30 | this.authService 31 | .checkAuth() 32 | .pipe( 33 | map((isLoggedIn) => 34 | fromAuthActions.checkAuthComplete({ isLoggedIn }) 35 | ) 36 | ) 37 | ) 38 | ) 39 | ); 40 | 41 | checkAuthComplete$ = createEffect(() => 42 | this.actions$.pipe( 43 | ofType(fromAuthActions.checkAuthComplete), 44 | switchMap(({ isLoggedIn }) => { 45 | if (isLoggedIn) { 46 | return this.authService.userData.pipe( 47 | map((profile) => 48 | fromAuthActions.loginComplete({ profile, isLoggedIn }) 49 | ) 50 | ); 51 | } 52 | return of(fromAuthActions.logoutComplete()); 53 | }) 54 | ) 55 | ); 56 | 57 | logout$ = createEffect(() => 58 | this.actions$.pipe( 59 | ofType(fromAuthActions.logout), 60 | tap(() => this.authService.signOut()), 61 | map(() => fromAuthActions.logoutComplete()) 62 | ) 63 | ); 64 | 65 | logoutComplete$ = createEffect( 66 | () => 67 | this.actions$.pipe( 68 | ofType(fromAuthActions.logoutComplete), 69 | tap(() => { 70 | this.router.navigate(['/']); 71 | }) 72 | ), 73 | { dispatch: false } 74 | ); 75 | } 76 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/store/auth/auth.reducer.ts: -------------------------------------------------------------------------------- 1 | import { createReducer, on, Action } from '@ngrx/store'; 2 | import * as authActions from './auth.actions'; 3 | 4 | export const authFeatureName = 'auth'; 5 | 6 | export interface AuthState { 7 | profile: any; 8 | isLoggedIn: boolean; 9 | } 10 | 11 | export const initialAuthState: AuthState = { 12 | isLoggedIn: false, 13 | profile: null, 14 | }; 15 | 16 | const authReducerInternal = createReducer( 17 | initialAuthState, 18 | 19 | on(authActions.loginComplete, (state, { profile, isLoggedIn }) => { 20 | return { 21 | ...state, 22 | profile, 23 | isLoggedIn, 24 | }; 25 | }), 26 | on(authActions.logout, (state, {}) => { 27 | return { 28 | ...state, 29 | profile: null, 30 | isLoggedIn: false, 31 | }; 32 | }) 33 | ); 34 | 35 | export function authReducer(state: AuthState | undefined, action: Action) { 36 | return authReducerInternal(state, action); 37 | } 38 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/store/auth/auth.selectors.ts: -------------------------------------------------------------------------------- 1 | import { AuthState, authFeatureName } from './auth.reducer'; 2 | import { createFeatureSelector, createSelector } from '@ngrx/store'; 3 | 4 | export const getAuthFeatureState = createFeatureSelector(authFeatureName); 5 | 6 | export const selectIsAuthenticated = createSelector( 7 | getAuthFeatureState, 8 | (state: AuthState) => state.isLoggedIn 9 | ); 10 | 11 | export const selectuserInfo = createSelector( 12 | getAuthFeatureState, 13 | (state: AuthState) => state.profile 14 | ); 15 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/store/auth/index.ts: -------------------------------------------------------------------------------- 1 | export * from './auth.actions'; 2 | export * from './auth.effects'; 3 | export * from './auth.reducer'; 4 | export * from './auth.selectors'; 5 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/store/data/data.actions.ts: -------------------------------------------------------------------------------- 1 | import { createAction, props } from '@ngrx/store'; 2 | 3 | export const getData = createAction('[Data] getData'); 4 | export const getDataComplete = createAction( 5 | '[Data] getDataComplete', 6 | props<{ data: any }>() 7 | ); 8 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/store/data/data.effects.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Actions, createEffect, ofType } from '@ngrx/effects'; 3 | import { map, switchMap } from 'rxjs/operators'; 4 | import * as fromDataActions from './data.actions'; 5 | import { DataService } from '../../services/data.service'; 6 | 7 | @Injectable() 8 | export class DataEffects { 9 | constructor(private actions$: Actions, private dataService: DataService) {} 10 | 11 | getData$ = createEffect(() => 12 | this.actions$.pipe( 13 | ofType(fromDataActions.getData), 14 | switchMap(() => 15 | this.dataService 16 | .getData() 17 | .pipe(map((data) => fromDataActions.getDataComplete({ data }))) 18 | ) 19 | ) 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/store/data/data.reducer.ts: -------------------------------------------------------------------------------- 1 | import { createReducer, on, Action } from '@ngrx/store'; 2 | import * as dataActions from './data.actions'; 3 | 4 | export const dataFeatureName = 'data'; 5 | 6 | export interface DataState { 7 | data: any; 8 | } 9 | 10 | export const initialDataState: DataState = { 11 | data: null, 12 | }; 13 | 14 | const dataReducerInternal = createReducer( 15 | initialDataState, 16 | 17 | on(dataActions.getDataComplete, (state, { data }) => { 18 | return { 19 | ...state, 20 | data, 21 | }; 22 | }) 23 | ); 24 | 25 | export function dataReducer(state: DataState | undefined, action: Action) { 26 | return dataReducerInternal(state, action); 27 | } 28 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/store/data/data.selectors.ts: -------------------------------------------------------------------------------- 1 | import { DataState, dataFeatureName } from './data.reducer'; 2 | import { createFeatureSelector, createSelector } from '@ngrx/store'; 3 | 4 | export const getDataFeatureState = createFeatureSelector(dataFeatureName); 5 | 6 | export const selectData = createSelector( 7 | getDataFeatureState, 8 | (state: DataState) => state.data 9 | ); 10 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/store/data/index.ts: -------------------------------------------------------------------------------- 1 | export * from './data.actions'; 2 | export * from './data.effects'; 3 | export * from './data.reducer'; 4 | export * from './data.selectors'; 5 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/store/index.ts: -------------------------------------------------------------------------------- 1 | import { authReducer, AuthEffects } from './auth'; 2 | import { DataEffects, dataReducer } from './data'; 3 | 4 | export * from './auth'; 5 | export * from './data'; 6 | 7 | export const appReducer = { 8 | auth: authReducer, 9 | data: dataReducer, 10 | }; 11 | 12 | export const appEffects = [AuthEffects, DataEffects]; 13 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/unauthorized/unauthorized.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FabianGosebrink/angular-oauth2-oidc-sample/efb3cb9287ff83c37fceded71fef0aff8295ae24/client/angular-oidc-oauth2-ngrx/src/app/unauthorized/unauthorized.component.css -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/unauthorized/unauthorized.component.html: -------------------------------------------------------------------------------- 1 |
401: You have no rights to access this. Please Login
-------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/unauthorized/unauthorized.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { UnauthorizedComponent } from './unauthorized.component'; 4 | 5 | describe('UnauthorizedComponent', () => { 6 | let component: UnauthorizedComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ UnauthorizedComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(UnauthorizedComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/app/unauthorized/unauthorized.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-unauthorized', 5 | templateUrl: 'unauthorized.component.html', 6 | }) 7 | export class UnauthorizedComponent implements OnInit { 8 | constructor() {} 9 | 10 | ngOnInit() {} 11 | } 12 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FabianGosebrink/angular-oauth2-oidc-sample/efb3cb9287ff83c37fceded71fef0aff8295ae24/client/angular-oidc-oauth2-ngrx/src/assets/.gitkeep -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FabianGosebrink/angular-oauth2-oidc-sample/efb3cb9287ff83c37fceded71fef0aff8295ae24/client/angular-oidc-oauth2-ngrx/src/favicon.ico -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularOidcOauth2Ngrx 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2-ngrx/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 | } -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/.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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/README.md: -------------------------------------------------------------------------------- 1 | # AngularOidcAuth2 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.3. 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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "angular-oidc-oauth2": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/angular-oidc-oauth2", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "tsconfig.app.json", 21 | "aot": true, 22 | "assets": ["src/favicon.ico", "src/assets"], 23 | "styles": ["src/styles.css"], 24 | "scripts": [] 25 | }, 26 | "configurations": { 27 | "production": { 28 | "fileReplacements": [ 29 | { 30 | "replace": "src/environments/environment.ts", 31 | "with": "src/environments/environment.prod.ts" 32 | } 33 | ], 34 | "optimization": true, 35 | "outputHashing": "all", 36 | "sourceMap": false, 37 | "extractCss": true, 38 | "namedChunks": false, 39 | "extractLicenses": true, 40 | "vendorChunk": false, 41 | "buildOptimizer": true, 42 | "budgets": [ 43 | { 44 | "type": "initial", 45 | "maximumWarning": "2mb", 46 | "maximumError": "5mb" 47 | }, 48 | { 49 | "type": "anyComponentStyle", 50 | "maximumWarning": "6kb", 51 | "maximumError": "10kb" 52 | } 53 | ] 54 | } 55 | } 56 | }, 57 | "serve": { 58 | "builder": "@angular-devkit/build-angular:dev-server", 59 | "options": { 60 | "browserTarget": "angular-oidc-oauth2:build" 61 | }, 62 | "configurations": { 63 | "production": { 64 | "browserTarget": "angular-oidc-oauth2:build:production" 65 | } 66 | } 67 | }, 68 | "extract-i18n": { 69 | "builder": "@angular-devkit/build-angular:extract-i18n", 70 | "options": { 71 | "browserTarget": "angular-oidc-oauth2:build" 72 | } 73 | }, 74 | "test": { 75 | "builder": "@angular-devkit/build-angular:karma", 76 | "options": { 77 | "main": "src/test.ts", 78 | "polyfills": "src/polyfills.ts", 79 | "tsConfig": "tsconfig.spec.json", 80 | "karmaConfig": "karma.conf.js", 81 | "assets": ["src/favicon.ico", "src/assets"], 82 | "styles": ["src/styles.css"], 83 | "scripts": [] 84 | } 85 | }, 86 | "lint": { 87 | "builder": "@angular-devkit/build-angular:tslint", 88 | "options": { 89 | "tsConfig": [ 90 | "tsconfig.app.json", 91 | "tsconfig.spec.json", 92 | "e2e/tsconfig.json" 93 | ], 94 | "exclude": ["**/node_modules/**"] 95 | } 96 | }, 97 | "e2e": { 98 | "builder": "@angular-devkit/build-angular:protractor", 99 | "options": { 100 | "protractorConfig": "e2e/protractor.conf.js", 101 | "devServerTarget": "angular-oidc-oauth2:serve" 102 | }, 103 | "configurations": { 104 | "production": { 105 | "devServerTarget": "angular-oidc-oauth2:serve:production" 106 | } 107 | } 108 | } 109 | } 110 | } 111 | }, 112 | "defaultProject": "angular-oidc-oauth2", 113 | "cli": { 114 | "analytics": false 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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'. -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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 | }; -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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-oidc-oauth2 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( 20 | jasmine.objectContaining({ 21 | level: logging.Level.SEVERE, 22 | } as logging.Entry) 23 | ); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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-oidc-oauth2'), 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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-oidc-oauth2", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve --ssl", 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.3", 15 | "@angular/common": "~9.1.3", 16 | "@angular/compiler": "~9.1.3", 17 | "@angular/core": "~9.1.3", 18 | "@angular/forms": "~9.1.3", 19 | "@angular/platform-browser": "~9.1.3", 20 | "@angular/platform-browser-dynamic": "~9.1.3", 21 | "@angular/router": "~9.1.3", 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.3", 29 | "@angular/cli": "~9.1.3", 30 | "@angular/compiler-cli": "~9.1.3", 31 | "@angular/language-service": "~9.1.3", 32 | "@types/node": "^12.11.1", 33 | "@types/jasmine": "~3.5.0", 34 | "@types/jasminewd2": "~2.0.3", 35 | "codelyzer": "^5.1.2", 36 | "jasmine-core": "~3.5.0", 37 | "jasmine-spec-reporter": "~4.2.1", 38 | "karma": "~5.0.0", 39 | "karma-chrome-launcher": "~3.1.0", 40 | "karma-coverage-istanbul-reporter": "~2.1.0", 41 | "karma-jasmine": "~3.0.1", 42 | "karma-jasmine-html-reporter": "^1.4.2", 43 | "protractor": "~5.4.3", 44 | "ts-node": "~8.3.0", 45 | "tslint": "~6.1.0", 46 | "typescript": "~3.8.3" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FabianGosebrink/angular-oauth2-oidc-sample/efb3cb9287ff83c37fceded71fef0aff8295ae24/client/angular-oidc-oauth2/src/app/app.component.css -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |

Sample Code Flow with refresh tokens

2 | 3 | 4 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | 4 | describe('AppComponent', () => { 5 | beforeEach(async(() => { 6 | TestBed.configureTestingModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | }).compileComponents(); 11 | })); 12 | 13 | it('should create the app', () => { 14 | const fixture = TestBed.createComponent(AppComponent); 15 | const app = fixture.debugElement.componentInstance; 16 | expect(app).toBeTruthy(); 17 | }); 18 | 19 | it(`should have as title 'testSts'`, () => { 20 | const fixture = TestBed.createComponent(AppComponent); 21 | const app = fixture.debugElement.componentInstance; 22 | expect(app.title).toEqual('testSts'); 23 | }); 24 | 25 | it('should render title in a h1 tag', () => { 26 | const fixture = TestBed.createComponent(AppComponent); 27 | fixture.detectChanges(); 28 | const compiled = fixture.debugElement.nativeElement; 29 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to testSts!'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { AuthService } from './auth.service'; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | templateUrl: 'app.component.html', 7 | }) 8 | export class AppComponent implements OnInit { 9 | constructor(public authService: AuthService) {} 10 | 11 | ngOnInit() { 12 | this.authService 13 | .checkAuth() 14 | .subscribe((isAuthenticated) => 15 | console.log('app authenticated', isAuthenticated) 16 | ); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { APP_INITIALIZER, NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | import { RouterModule } from '@angular/router'; 4 | import { AuthModule, OidcConfigService } from 'angular-auth-oidc-client'; 5 | import { AppComponent } from './app.component'; 6 | import { HomeComponent } from './home/home.component'; 7 | import { UnauthorizedComponent } from './unauthorized/unauthorized.component'; 8 | import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; 9 | import { AuthInterceptor } from './auth.interceptor'; 10 | 11 | export function configureAuth(oidcConfigService: OidcConfigService) { 12 | return () => 13 | oidcConfigService.withConfig({ 14 | stsServer: 'https://offeringsolutions-sts.azurewebsites.net', 15 | redirectUrl: window.location.origin, 16 | postLogoutRedirectUri: window.location.origin, 17 | clientId: 'angularClientForHoorayApi', 18 | scope: 'openid profile email offline_access hooray_Api', 19 | responseType: 'code', 20 | silentRenew: true, 21 | useRefreshToken: true, 22 | }); 23 | } 24 | 25 | @NgModule({ 26 | declarations: [AppComponent, HomeComponent, UnauthorizedComponent], 27 | imports: [ 28 | BrowserModule, 29 | RouterModule.forRoot([ 30 | { path: '', redirectTo: 'home', pathMatch: 'full' }, 31 | { path: 'home', component: HomeComponent }, 32 | { path: 'unauthorized', component: UnauthorizedComponent }, 33 | ]), 34 | AuthModule.forRoot(), 35 | HttpClientModule, 36 | ], 37 | providers: [ 38 | OidcConfigService, 39 | { 40 | provide: APP_INITIALIZER, 41 | useFactory: configureAuth, 42 | deps: [OidcConfigService], 43 | multi: true, 44 | }, 45 | { 46 | provide: HTTP_INTERCEPTORS, 47 | useClass: AuthInterceptor, 48 | multi: true, 49 | }, 50 | ], 51 | bootstrap: [AppComponent], 52 | }) 53 | export class AppModule {} 54 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/auth.interceptor.ts: -------------------------------------------------------------------------------- 1 | import { HttpInterceptor, HttpRequest, HttpHandler } from '@angular/common/http'; 2 | import { Injectable } from '@angular/core'; 3 | import { AuthService } from './auth.service'; 4 | 5 | @Injectable() 6 | export class AuthInterceptor implements HttpInterceptor { 7 | private secureRoutes = ['https://localhost:5001/api']; 8 | 9 | constructor(private authService: AuthService) {} 10 | 11 | intercept( 12 | request: HttpRequest, 13 | next: HttpHandler 14 | ) { 15 | if (!this.secureRoutes.find((x) => request.url.startsWith(x))) { 16 | return next.handle(request); 17 | } 18 | 19 | const token = this.authService.token; 20 | 21 | if (!token) { 22 | return next.handle(request); 23 | } 24 | 25 | request = request.clone({ 26 | headers: request.headers.set('Authorization', 'Bearer ' + token), 27 | }); 28 | 29 | return next.handle(request); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { of } from 'rxjs'; 3 | import { OidcSecurityService } from 'angular-auth-oidc-client'; 4 | 5 | @Injectable({ providedIn: 'root' }) 6 | export class AuthService { 7 | constructor(private oidcSecurityService: OidcSecurityService) {} 8 | 9 | get isLoggedIn() { 10 | return this.oidcSecurityService.isAuthenticated$; 11 | } 12 | 13 | get token() { 14 | return this.oidcSecurityService.getToken(); 15 | } 16 | 17 | get userData() { 18 | return this.oidcSecurityService.userData$; 19 | } 20 | 21 | checkAuth() { 22 | return this.oidcSecurityService.checkAuth(); 23 | } 24 | 25 | doLogin() { 26 | return of(this.oidcSecurityService.authorize()); 27 | } 28 | 29 | signOut() { 30 | this.oidcSecurityService.logoff(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/home/home.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FabianGosebrink/angular-oauth2-oidc-sample/efb3cb9287ff83c37fceded71fef0aff8295ae24/client/angular-oidc-oauth2/src/app/home/home.component.css -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/home/home.component.html: -------------------------------------------------------------------------------- 1 |
Welcome to home Route
2 | 3 |
4 | 5 |
6 | 7 |
8 | 9 | Is Authenticated: {{ isAuthenticated }} 10 | 11 |
12 | userData 13 |
{{ userData$ | async | json }}
14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 |
23 |
24 | 25 |
26 |   {{ secretData$ | async | json }}
27 | 
28 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/home/home.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { HomeComponent } from './home.component'; 4 | 5 | describe('HomeComponent', () => { 6 | let component: HomeComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ HomeComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(HomeComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/home/home.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Observable, of } from 'rxjs'; 3 | import { catchError } from 'rxjs/operators'; 4 | import { AuthService } from '../auth.service'; 5 | import { HttpClient } from '@angular/common/http'; 6 | 7 | @Component({ 8 | selector: 'app-home', 9 | templateUrl: 'home.component.html', 10 | }) 11 | export class HomeComponent implements OnInit { 12 | userData$: Observable; 13 | secretData$: Observable; 14 | isAuthenticated$: Observable; 15 | constructor( 16 | private authservice: AuthService, 17 | private httpClient: HttpClient 18 | ) {} 19 | 20 | ngOnInit() { 21 | this.userData$ = this.authservice.userData; 22 | this.isAuthenticated$ = this.authservice.isLoggedIn; 23 | 24 | this.secretData$ = this.httpClient 25 | .get('https://localhost:5001/api/securevalues') 26 | .pipe(catchError((error) => of(error))); 27 | } 28 | 29 | login() { 30 | this.authservice.doLogin(); 31 | } 32 | 33 | logout() { 34 | this.authservice.signOut(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/unauthorized/unauthorized.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FabianGosebrink/angular-oauth2-oidc-sample/efb3cb9287ff83c37fceded71fef0aff8295ae24/client/angular-oidc-oauth2/src/app/unauthorized/unauthorized.component.css -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/unauthorized/unauthorized.component.html: -------------------------------------------------------------------------------- 1 |
401: You have no rights to access this. Please Login
-------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/unauthorized/unauthorized.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { UnauthorizedComponent } from './unauthorized.component'; 4 | 5 | describe('UnauthorizedComponent', () => { 6 | let component: UnauthorizedComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ UnauthorizedComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(UnauthorizedComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/app/unauthorized/unauthorized.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-unauthorized', 5 | templateUrl: 'unauthorized.component.html', 6 | }) 7 | export class UnauthorizedComponent implements OnInit { 8 | constructor() {} 9 | 10 | ngOnInit() {} 11 | } 12 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FabianGosebrink/angular-oauth2-oidc-sample/efb3cb9287ff83c37fceded71fef0aff8295ae24/client/angular-oidc-oauth2/src/assets/.gitkeep -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FabianGosebrink/angular-oauth2-oidc-sample/efb3cb9287ff83c37fceded71fef0aff8295ae24/client/angular-oidc-oauth2/src/favicon.ico -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularOidcAuth2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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 | -------------------------------------------------------------------------------- /client/angular-oidc-oauth2/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 | } -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Angular OAuth2 and Open ID Connect (OIDC) Sample With ASP.NET Core 2 | 3 |

4 | 5 | Twitter: FabianGosebrink 6 | 7 |

8 | 9 | ## Application 10 | 11 | In this sample application we find a angular client authorizing against an STS getting a token and asking an ASP.NET Core WebAPI for data. 12 | 13 | The STS can be found here [https://github.com/FabianGosebrink/security-token-service](https://github.com/FabianGosebrink/security-token-service) 14 | 15 | Find the client in the `client` folder and the ASP.NET Core WebAPI in the `server` folder. 16 | 17 | Get the backend running by 18 | 19 | ``` 20 | dotnet run 21 | ``` 22 | 23 | and the frontend by 24 | 25 | ``` 26 | npm install 27 | ``` 28 | 29 | and 30 | 31 | ``` 32 | npm start 33 | ``` 34 | 35 | ## Show your support 36 | 37 | Give a ⭐️ if this project helped you! 38 | -------------------------------------------------------------------------------- /server/Controllers/SecureValuesController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | [Authorize] 5 | [ApiController] 6 | [Route("api/[controller]")] 7 | public class SecureValuesController : ControllerBase 8 | { 9 | [HttpGet(Name = nameof(GetAll))] 10 | public ActionResult GetAll() 11 | { 12 | var genesisMember = new { Id = 1, FirstName = "Phil", LastName = "Collins" }; 13 | return Ok(genesisMember); 14 | } 15 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /server/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:61498", 8 | "sslPort": 44321 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "weatherforecast", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "server": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "weatherforecast", 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /server/Startup.cs: -------------------------------------------------------------------------------- 1 | using IdentityServer4.AccessTokenValidation; 2 | using Microsoft.AspNetCore.Builder; 3 | using Microsoft.AspNetCore.Hosting; 4 | using Microsoft.Extensions.Configuration; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using Microsoft.Extensions.Hosting; 7 | 8 | namespace server 9 | { 10 | public class Startup 11 | { 12 | public Startup(IConfiguration configuration) 13 | { 14 | Configuration = configuration; 15 | } 16 | 17 | public IConfiguration Configuration { get; } 18 | 19 | // This method gets called by the runtime. Use this method to add services to the container. 20 | public void ConfigureServices(IServiceCollection services) 21 | { 22 | services.AddControllers(); 23 | 24 | services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) 25 | .AddIdentityServerAuthentication(options => 26 | { 27 | options.Authority = "https://offeringsolutions-sts.azurewebsites.net"; 28 | options.ApiName = "hoorayApi"; 29 | options.ApiSecret = "hoorayApiSecret"; 30 | }); 31 | 32 | 33 | services.AddCors(options => 34 | { 35 | options.AddPolicy("AllowAllOrigins", 36 | builder => 37 | { 38 | builder 39 | .AllowAnyOrigin() 40 | .AllowAnyHeader() 41 | .AllowAnyMethod(); 42 | }); 43 | }); 44 | } 45 | 46 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 47 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 48 | { 49 | if (env.IsDevelopment()) 50 | { 51 | app.UseDeveloperExceptionPage(); 52 | } 53 | 54 | app.UseHttpsRedirection(); 55 | app.UseCors("AllowAllOrigins"); 56 | 57 | app.UseRouting(); 58 | 59 | app.UseAuthentication(); 60 | app.UseAuthorization(); 61 | 62 | app.UseEndpoints(endpoints => 63 | { 64 | endpoints.MapControllers(); 65 | }); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /server/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /server/server.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | --------------------------------------------------------------------------------