├── .gitignore ├── .idea └── misc.xml ├── LICENSE ├── README.md ├── build.sh ├── client ├── .angular-cli.json ├── .editorconfig ├── .gitignore ├── README.md ├── e2e │ ├── app.e2e-spec.ts │ ├── app.po.ts │ └── tsconfig.e2e.json ├── karma.conf.js ├── package.json ├── protractor.conf.js ├── src │ ├── app │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── login │ │ │ ├── login.component.css │ │ │ ├── login.component.html │ │ │ ├── login.component.spec.ts │ │ │ └── login.component.ts │ │ ├── note-detail │ │ │ ├── note-detail.component.css │ │ │ ├── note-detail.component.html │ │ │ ├── note-detail.component.spec.ts │ │ │ └── note-detail.component.ts │ │ ├── note-list │ │ │ ├── note-list.component.css │ │ │ ├── note-list.component.html │ │ │ ├── note-list.component.spec.ts │ │ │ └── note-list.component.ts │ │ └── shared │ │ │ ├── note │ │ │ ├── note.service.spec.ts │ │ │ └── note.service.ts │ │ │ └── okta │ │ │ ├── index.ts │ │ │ ├── okta.guard.ts │ │ │ ├── okta.interceptor.ts │ │ │ └── okta.service.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.spec.json │ └── typings.d.ts ├── tsconfig.json ├── tslint.json └── yarn.lock ├── manifest.yml ├── reset.sh └── server ├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── kotlin │ └── com │ │ └── okta │ │ └── developer │ │ └── notes │ │ └── NotesApplication.kt └── resources │ └── application.properties └── test └── kotlin └── com └── okta └── developer └── notes └── NotesApplicationTests.kt /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 Okta, Inc. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Kotlin and TypeScript Notes Example 2 | 3 | This example app shows how to build a basic notes app with Kotlin, Spring Boot, Spring Data, TypeScript, and Angular. 4 | 5 | Please read [Build a Secure Notes Application with Kotlin, TypeScript, and Okta](https://developer.okta.com/blog/2017/09/19/build-a-secure-notes-application-with-kotlin-typescript-and-okta) to see how this app was created. 6 | 7 | **Prerequisites:** [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) and [Node.js](https://nodejs.org/). 8 | 9 | > [Okta](https://developer.okta.com/) has Authentication and User Management APIs that reduce development time with instant-on, scalable user infrastructure. Okta's intuitive API and expert support make it easy for developers to authenticate, manage and secure users and roles in any application. 10 | 11 | * [Getting Started](#getting-started) 12 | * [Links](#links) 13 | * [Help](#help) 14 | * [License](#license) 15 | 16 | ## Getting Started 17 | 18 | To install this example application, run the following commands: 19 | 20 | ```bash 21 | git clone https://github.com/oktadeveloper/okta-kotlin-typescript-notes-example.git 22 | cd okta-kotlin-typescript-notes-example 23 | ``` 24 | 25 | This will get a copy of the project installed locally. To install all of its dependencies and start each app, follow the instructions below. 26 | 27 | To run the server, cd into the `server` folder and run: 28 | 29 | ```bash 30 | ./mvnw 31 | ``` 32 | 33 | To run the client, cd into the `client` folder and run: 34 | 35 | ```bash 36 | yarn && yarn start 37 | ``` 38 | 39 | ### Create an OIDC App in Okta 40 | 41 | You will need to [create an OIDC App in Okta](https://developer.okta.com/blog/2017/09/19/build-a-secure-notes-application-with-kotlin-typescript-and-okta#add-an-openid-connect-application) to get a `clientId`. 42 | 43 | Log in to your Okta Developer account (or [sign up](https://developer.okta.com/signup/) if you don’t have an account) and navigate to **Applications** and click on **Add Application**. Select Single Page App (SPA) and click **Next**. Give the application a name (e.g. “My OIDC App”) and specify `http://localhost:4200` as a Login redirect URI. Click **Done** and admire your handiwork! 44 | 45 | My OIDC App 46 | 47 | #### Server Configuration 48 | 49 | Set the `issuer` and copy the `clientId` into `server/src/main/resources/application.properties`. 50 | 51 | **NOTE:** The value of `{yourOktaDomain}` should be something like `dev-123456.oktapreview`. Make sure you don't include `-admin` in the value! 52 | 53 | ```properties 54 | okta.oauth.issuer=https://{yourOktaDomain}.com/oauth2/default 55 | okta.oauth.clientId={clientId} 56 | ``` 57 | 58 | #### Client Configuration 59 | 60 | For the client, set the `issuer` and copy the `clientId` into `client/src/app/shared/okta.service.ts`. 61 | 62 | ```typescript 63 | signIn = new OktaSignIn({ 64 | baseUrl: 'https://{yourOktaDomain}.com', 65 | clientId: '{clientId}', 66 | redirectUri: 'http://localhost:4200', 67 | authParams: { 68 | issuer: 'default', 69 | responseType: ['id_token', 'token'], 70 | scopes: ['openid', 'email', 'profile'] 71 | } 72 | }); 73 | ``` 74 | 75 | **NOTE:** There’s one issue with Okta’s Sign-In Widget I still haven’t fully figured out. Not every time, but everyone once it in a while, it requires me to move my mouse or click on the screen to make the notes list load after logging in. I opened [an issue](https://github.com/okta/okta-signin-widget/issues/268) for this, and tried the suggested solution, but it doesn’t work 100% of the time. 76 | 77 | ## Links 78 | 79 | This example uses the following libraries provided by Okta: 80 | 81 | * [Okta Spring Boot Starter](https://github.com/okta/okta-spring-boot) 82 | * [Okta Sign-In Widget](https://github.com/okta/okta-oidc-js/tree/master/packages/okta-angular) 83 | 84 | ## Help 85 | 86 | Please post any questions as comments on the [blog post](https://developer.okta.com/blog/2017/12/04/basic-crud-angular-and-spring-boot), or visit our [Okta Developer Forums](https://devforum.okta.com/). You can also email developers@okta.com if would like to create a support ticket. 87 | 88 | ## License 89 | 90 | Apache 2.0, see [LICENSE](LICENSE). 91 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | start=`pwd` 4 | 5 | # set origin for client on server 6 | sed -i -e "s|http://localhost:4200|https://notes-with-typescript.cfapps.io|g" $start/server/src/main/kotlin/com/okta/developer/notes/NotesApplication.kt 7 | 8 | mvn clean package -f $start/server/pom.xml 9 | 10 | cd $start/client 11 | rm -rf dist 12 | # set API URL 13 | sed -i -e "s|http://localhost:8080|https://notes-by-kotlin.cfapps.io|g" $start/client/src/app/shared/note/note.service.ts 14 | # set redirectURI to client URI 15 | sed -i -e "s|http://localhost:4200|https://notes-with-typescript.cfapps.io|g" $start/client/src/app/shared/okta/okta.service.ts 16 | yarn && ng build -prod --aot 17 | touch dist/Staticfile 18 | # enable pushstate so no 404s on refresh 19 | echo 'pushstate: enabled' > dist/Staticfile 20 | 21 | cd $start 22 | cf push 23 | 24 | # reset and remove changed files 25 | git checkout $start 26 | rm -rf $start/server/src/main/kotlin/com/okta/developer/notes/NotesApplication.kt-e 27 | rm -rf $start/client/src/app/shared/note/note.service.ts-e 28 | rm -rf $start/client/src/app/shared/okta/okta.service.ts-e 29 | -------------------------------------------------------------------------------- /client/.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "notes" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "polyfills": "polyfills.ts", 17 | "test": "test.ts", 18 | "tsconfig": "tsconfig.app.json", 19 | "testTsconfig": "tsconfig.spec.json", 20 | "prefix": "app", 21 | "styles": [ 22 | "styles.css" 23 | ], 24 | "scripts": [], 25 | "environmentSource": "environments/environment.ts", 26 | "environments": { 27 | "dev": "environments/environment.ts", 28 | "prod": "environments/environment.prod.ts" 29 | } 30 | } 31 | ], 32 | "e2e": { 33 | "protractor": { 34 | "config": "./protractor.conf.js" 35 | } 36 | }, 37 | "lint": [ 38 | { 39 | "project": "src/tsconfig.app.json", 40 | "exclude": "**/node_modules/**" 41 | }, 42 | { 43 | "project": "src/tsconfig.spec.json", 44 | "exclude": "**/node_modules/**" 45 | }, 46 | { 47 | "project": "e2e/tsconfig.e2e.json", 48 | "exclude": "**/node_modules/**" 49 | } 50 | ], 51 | "test": { 52 | "karma": { 53 | "config": "./karma.conf.js" 54 | } 55 | }, 56 | "defaults": { 57 | "styleExt": "css", 58 | "component": {} 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /client/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://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 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /client/.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 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | testem.log 34 | /typings 35 | yarn-error.log 36 | 37 | # e2e 38 | /e2e/*.js 39 | /e2e/*.map 40 | 41 | # System Files 42 | .DS_Store 43 | Thumbs.db 44 | -------------------------------------------------------------------------------- /client/README.md: -------------------------------------------------------------------------------- 1 | # Notes 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.5.5. 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/e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('notes App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to app!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /client/e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /client/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "jasminewd2", 11 | "node" 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /client/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/cli'], 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/cli/plugins/karma') 14 | ], 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | reports: [ 'html', 'lcovonly' ], 20 | fixWebpackSourcePaths: true 21 | }, 22 | angularCli: { 23 | environment: 'dev' 24 | }, 25 | reporters: ['progress', 'kjhtml'], 26 | port: 9876, 27 | colors: true, 28 | logLevel: config.LOG_INFO, 29 | autoWatch: true, 30 | browsers: ['Chrome'], 31 | singleRun: false 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "notes", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/animations": "^5.0.0", 16 | "@angular/cdk": "^5.0.0-rc.2", 17 | "@angular/common": "^5.0.0", 18 | "@angular/compiler": "^5.0.0", 19 | "@angular/core": "^5.0.0", 20 | "@angular/forms": "^5.0.0", 21 | "@angular/http": "^5.0.0", 22 | "@angular/material": "^5.0.0-rc.2", 23 | "@angular/platform-browser": "^5.0.0", 24 | "@angular/platform-browser-dynamic": "^5.0.0", 25 | "@angular/router": "^5.0.0", 26 | "@okta/okta-signin-widget": "^2.5.0", 27 | "core-js": "^2.4.1", 28 | "rxjs": "^5.5.2", 29 | "zone.js": "^0.8.14" 30 | }, 31 | "devDependencies": { 32 | "@angular/cli": "1.5.5", 33 | "@angular/compiler-cli": "^5.0.0", 34 | "@angular/language-service": "^5.0.0", 35 | "@types/jasmine": "~2.5.53", 36 | "@types/jasminewd2": "~2.0.2", 37 | "@types/node": "~6.0.60", 38 | "codelyzer": "^4.0.1", 39 | "jasmine-core": "~2.6.2", 40 | "jasmine-spec-reporter": "~4.1.0", 41 | "karma": "~1.7.0", 42 | "karma-chrome-launcher": "~2.1.1", 43 | "karma-cli": "~1.0.1", 44 | "karma-coverage-istanbul-reporter": "^1.2.1", 45 | "karma-jasmine": "~1.1.0", 46 | "karma-jasmine-html-reporter": "^0.2.2", 47 | "protractor": "~5.1.2", 48 | "ts-node": "~3.2.0", 49 | "tslint": "~5.7.0", 50 | "typescript": "~2.4.2" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /client/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './e2e/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: 'e2e/tsconfig.e2e.json' 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /client/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | mat-toolbar a { 2 | color: rgba(255, 255, 255, .87); 3 | text-decoration: none; 4 | } 5 | 6 | .fill-remaining-space { 7 | flex: 1 1 auto; 8 | } 9 | -------------------------------------------------------------------------------- /client/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | {{title}} 3 | 4 | 5 | Welcome {{user?.name}}! 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /client/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | declarations: [ 9 | AppComponent 10 | ], 11 | }).compileComponents(); 12 | })); 13 | 14 | it('should create the app', async(() => { 15 | const fixture = TestBed.createComponent(AppComponent); 16 | const app = fixture.debugElement.componentInstance; 17 | expect(app).toBeTruthy(); 18 | })); 19 | 20 | it(`should have as title 'app'`, async(() => { 21 | const fixture = TestBed.createComponent(AppComponent); 22 | const app = fixture.debugElement.componentInstance; 23 | expect(app.title).toEqual('app'); 24 | })); 25 | 26 | it('should render title in a h1 tag', async(() => { 27 | const fixture = TestBed.createComponent(AppComponent); 28 | fixture.detectChanges(); 29 | const compiled = fixture.debugElement.nativeElement; 30 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!'); 31 | })); 32 | }); 33 | -------------------------------------------------------------------------------- /client/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { OktaAuthService } from './shared/okta/okta.service'; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | templateUrl: './app.component.html', 7 | styleUrls: ['./app.component.css'] 8 | }) 9 | export class AppComponent implements OnInit { 10 | title = 'My Notes'; 11 | user; 12 | 13 | constructor(public oktaService: OktaAuthService) { 14 | } 15 | 16 | ngOnInit() { 17 | if (this.oktaService.isAuthenticated()) { 18 | this.user = this.oktaService.idTokenAsUser; 19 | } 20 | 21 | this.oktaService.user$.subscribe(user => { 22 | this.user = user; 23 | }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /client/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { AppComponent } from './app.component'; 5 | import { NoteListComponent } from './note-list/note-list.component'; 6 | import { NoteService } from './shared/note/note.service'; 7 | import { RouterModule, Routes } from '@angular/router'; 8 | import { OktaAuthGuard, OktaAuthInterceptor, OktaAuthService } from './shared/okta'; 9 | import { 10 | MatButtonModule, 11 | MatCardModule, 12 | MatIconModule, 13 | MatInputModule, 14 | MatListModule, 15 | MatToolbarModule 16 | } from '@angular/material'; 17 | import { NoteDetailComponent } from './note-detail/note-detail.component'; 18 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 19 | import { FormsModule } from '@angular/forms'; 20 | import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http'; 21 | import { LoginComponent } from './login/login.component'; 22 | 23 | const appRoutes: Routes = [ 24 | {path: 'login', component: LoginComponent}, 25 | {path: 'notes', component: NoteListComponent, canActivate: [OktaAuthGuard]}, 26 | {path: 'notes/:id', component: NoteDetailComponent, canActivate: [OktaAuthGuard]}, 27 | {path: '', redirectTo: '/notes', pathMatch: 'full'} 28 | ]; 29 | 30 | @NgModule({ 31 | declarations: [ 32 | AppComponent, 33 | NoteListComponent, 34 | NoteDetailComponent, 35 | LoginComponent 36 | ], 37 | imports: [ 38 | BrowserModule, 39 | HttpClientModule, 40 | RouterModule.forRoot(appRoutes), 41 | BrowserAnimationsModule, 42 | MatToolbarModule, 43 | MatListModule, 44 | MatCardModule, 45 | MatButtonModule, 46 | MatIconModule, 47 | MatInputModule, 48 | FormsModule 49 | ], 50 | providers: [NoteService, OktaAuthService, OktaAuthGuard, { 51 | provide: HTTP_INTERCEPTORS, 52 | useClass: OktaAuthInterceptor, 53 | multi: true 54 | }], 55 | bootstrap: [AppComponent] 56 | }) 57 | export class AppModule { 58 | } 59 | -------------------------------------------------------------------------------- /client/src/app/login/login.component.css: -------------------------------------------------------------------------------- 1 | #okta-signin-container { 2 | margin-top: 25px; 3 | } 4 | 5 | @media only screen 6 | and (min-device-width: 414px) 7 | and (max-device-width: 736px) 8 | and (-webkit-min-device-pixel-ratio: 3) { 9 | #okta-signin-container { 10 | margin-top: 0; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /client/src/app/login/login.component.html: -------------------------------------------------------------------------------- 1 |
2 | -------------------------------------------------------------------------------- /client/src/app/login/login.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LoginComponent } from './login.component'; 4 | 5 | describe('LoginComponent', () => { 6 | let component: LoginComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LoginComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LoginComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/login/login.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { OktaAuthService } from '../shared/okta/okta.service'; 3 | import { Router } from '@angular/router'; 4 | 5 | @Component({ 6 | selector: 'app-login', 7 | templateUrl: './login.component.html', 8 | styleUrls: ['./login.component.css'] 9 | }) 10 | export class LoginComponent implements OnInit { 11 | 12 | constructor(private oktaService: OktaAuthService, 13 | private router: Router) { 14 | } 15 | 16 | ngOnInit() { 17 | if (this.oktaService.isAuthenticated()) { 18 | this.router.navigate(['/']); 19 | } else { 20 | this.oktaService.showLogin(); 21 | } 22 | 23 | // user authentication listener 24 | this.oktaService.user$.subscribe(user => { 25 | this.router.navigate(['/']); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /client/src/app/note-detail/note-detail.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oktadev/okta-kotlin-typescript-notes-example/8b3e68030bfcdaa11b2083508c60cf4099162a25/client/src/app/note-detail/note-detail.component.css -------------------------------------------------------------------------------- /client/src/app/note-detail/note-detail.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 | {{note?.href ? 'Edit Note' : 'Add Note'}} 6 | 7 | 8 | 9 | 11 | 12 |
13 | Name is required 14 |
15 |
16 | 17 | 20 | 22 | Cancel 23 | 24 |
25 |
26 | -------------------------------------------------------------------------------- /client/src/app/note-detail/note-detail.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { NoteDetailComponent } from './note-detail.component'; 4 | 5 | describe('NoteDetailComponent', () => { 6 | let component: NoteDetailComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ NoteDetailComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(NoteDetailComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/note-detail/note-detail.component.ts: -------------------------------------------------------------------------------- 1 | import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core'; 2 | import { ActivatedRoute, Router } from '@angular/router'; 3 | import { NoteService } from '../shared/note/note.service'; 4 | import { NgForm } from '@angular/forms'; 5 | import { MatInput } from '@angular/material'; 6 | 7 | @Component({ 8 | selector: 'app-note-detail', 9 | templateUrl: './note-detail.component.html', 10 | styleUrls: ['./note-detail.component.css'] 11 | }) 12 | export class NoteDetailComponent implements OnInit, AfterViewInit { 13 | note: any = {text: ''}; 14 | @ViewChild(MatInput) text: MatInput; 15 | 16 | constructor(private route: ActivatedRoute, 17 | private router: Router, 18 | private noteService: NoteService) { 19 | } 20 | 21 | ngOnInit() { 22 | this.route.params.subscribe(params => { 23 | if (params.id !== 'add') { 24 | this.noteService.get(params.id).subscribe((note: any) => { 25 | this.note = note; 26 | this.note.href = note._links.self.href; 27 | }, error => console.error(error)); 28 | } 29 | }); 30 | } 31 | 32 | ngAfterViewInit() { 33 | setTimeout(() => { 34 | this.text.focus(); 35 | }, 150); 36 | } 37 | 38 | onSubmit(form: NgForm) { 39 | this.noteService.save(form).subscribe(() => { 40 | this.router.navigate(['/notes']); 41 | }); 42 | } 43 | 44 | remove(href) { 45 | this.noteService.remove(href).subscribe(() => { 46 | this.router.navigate(['/notes']); 47 | }); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /client/src/app/note-list/note-list.component.css: -------------------------------------------------------------------------------- 1 | :host { 2 | padding-left: 5px; 3 | display: block; 4 | } 5 | 6 | .btn-add { 7 | margin-left: 10px; 8 | margin-top: 10px; 9 | } 10 | 11 | .link { 12 | cursor: pointer; 13 | } 14 | -------------------------------------------------------------------------------- /client/src/app/note-list/note-list.component.html: -------------------------------------------------------------------------------- 1 | 2 | Notes List 3 | 4 | 5 | 7 | {{note.text}} 8 | 9 | 10 |

No notes found.

11 |
12 |
13 | 16 |
17 |
18 | -------------------------------------------------------------------------------- /client/src/app/note-list/note-list.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { NoteListComponent } from './note-list.component'; 4 | 5 | describe('NoteListComponent', () => { 6 | let component: NoteListComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ NoteListComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(NoteListComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should be created', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/note-list/note-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { NoteService } from '../shared/note/note.service'; 3 | 4 | @Component({ 5 | selector: 'app-note-list', 6 | templateUrl: './note-list.component.html', 7 | styleUrls: ['./note-list.component.css'] 8 | }) 9 | export class NoteListComponent implements OnInit { 10 | notes: Array; 11 | 12 | constructor(private noteService: NoteService) { 13 | } 14 | 15 | ngOnInit() { 16 | this.noteService.getAll().subscribe(data => { 17 | this.notes = data; 18 | }, error => console.error(error)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /client/src/app/shared/note/note.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { NoteService } from './note.service'; 4 | 5 | describe('NoteService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [NoteService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([NoteService], (service: NoteService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /client/src/app/shared/note/note.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Response } from '@angular/http'; 3 | import { Observable } from 'rxjs/Observable'; 4 | import 'rxjs/add/operator/map'; 5 | import 'rxjs/add/operator/catch'; 6 | import { HttpClient } from '@angular/common/http'; 7 | 8 | @Injectable() 9 | export class NoteService { 10 | public API = 'http://localhost:8080'; 11 | public NOTE_API = this.API + '/notes'; 12 | 13 | constructor(private http: HttpClient) { 14 | } 15 | 16 | getAll(): Observable { 17 | return this.http.get(this.API); 18 | } 19 | 20 | get(id: string) { 21 | return this.http.get(this.NOTE_API + '/' + id); 22 | } 23 | 24 | save(note: any): Observable { 25 | let result: Observable; 26 | if (note['href']) { 27 | result = this.http.put(note.href, note); 28 | } else { 29 | result = this.http.post(this.NOTE_API, note); 30 | } 31 | return result.catch(error => Observable.throw(error)); 32 | } 33 | 34 | remove(href: string) { 35 | return this.http.delete(href); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /client/src/app/shared/okta/index.ts: -------------------------------------------------------------------------------- 1 | export * from './okta.service'; 2 | export * from './okta.guard'; 3 | export * from './okta.interceptor'; 4 | -------------------------------------------------------------------------------- /client/src/app/shared/okta/okta.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router'; 3 | import { OktaAuthService } from './okta.service'; 4 | 5 | @Injectable() 6 | export class OktaAuthGuard implements CanActivate { 7 | signIn; 8 | authenticated; 9 | 10 | constructor(private oktaService: OktaAuthService) { 11 | this.signIn = oktaService; 12 | } 13 | 14 | canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { 15 | this.authenticated = this.oktaService.isAuthenticated(); 16 | if (this.authenticated) { 17 | return true; 18 | } 19 | this.signIn.login(); 20 | return false; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /client/src/app/shared/okta/okta.interceptor.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { 3 | HttpRequest, 4 | HttpHandler, 5 | HttpEvent, 6 | HttpInterceptor, HttpErrorResponse, HttpResponse 7 | } from '@angular/common/http'; 8 | import { Observable } from 'rxjs/Observable'; 9 | import { OktaAuthService } from './okta.service'; 10 | import 'rxjs/add/operator/do'; 11 | 12 | @Injectable() 13 | export class OktaAuthInterceptor implements HttpInterceptor { 14 | 15 | constructor(private oktaService: OktaAuthService) { 16 | } 17 | 18 | intercept(request: HttpRequest, next: HttpHandler): Observable> { 19 | 20 | if (this.oktaService.isAuthenticated()) { 21 | const accessToken = this.oktaService.signIn.tokenManager.get('accessToken'); 22 | request = request.clone({ 23 | setHeaders: { 24 | Authorization: `${accessToken.tokenType} ${accessToken.accessToken}` 25 | } 26 | }); 27 | } 28 | 29 | return next.handle(request).do((event: HttpEvent) => { 30 | if (event instanceof HttpResponse) { 31 | return event; 32 | } else if (event instanceof HttpErrorResponse) { 33 | if (event.status === 401) { 34 | this.oktaService.login(); 35 | } 36 | } 37 | }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /client/src/app/shared/okta/okta.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import * as OktaSignIn from '@okta/okta-signin-widget'; 3 | import { ReplaySubject } from 'rxjs/ReplaySubject'; 4 | import { Observable } from 'rxjs/Observable'; 5 | import { Router } from '@angular/router'; 6 | 7 | @Injectable() 8 | export class OktaAuthService { 9 | 10 | signIn = new OktaSignIn({ 11 | baseUrl: 'https://dev-158606.oktapreview.com', 12 | clientId: '0oabl213xlbMjGJYo0h7', 13 | redirectUri: 'http://localhost:4200', 14 | authParams: { 15 | issuer: 'default', 16 | responseType: ['id_token', 'token'], 17 | scopes: ['openid', 'email', 'profile'] 18 | } 19 | }); 20 | 21 | private userSource: ReplaySubject; 22 | public user$: Observable; 23 | 24 | constructor(private router: Router) { 25 | this.userSource = new ReplaySubject(1); 26 | this.user$ = this.userSource.asObservable(); 27 | } 28 | 29 | isAuthenticated() { 30 | // Checks if there is a current accessToken in the TokenManger. 31 | return !!this.signIn.tokenManager.get('accessToken'); 32 | } 33 | 34 | login(next?: string) { 35 | if (next) { 36 | this.router.navigate(['login', {next: next}]); 37 | } else { 38 | this.router.navigate(['login']); 39 | } 40 | } 41 | 42 | showLogin() { 43 | // Launches the widget and stores the tokens 44 | try { 45 | this.signIn.renderEl({el: '#okta-signin-container'}, response => { 46 | if (response.status === 'SUCCESS') { 47 | response.forEach(token => { 48 | if (token.idToken) { 49 | this.signIn.tokenManager.add('idToken', token); 50 | } 51 | if (token.accessToken) { 52 | this.signIn.tokenManager.add('accessToken', token); 53 | } 54 | }); 55 | this.userSource.next(this.idTokenAsUser); 56 | this.signIn.hide(); 57 | } else { 58 | console.error(response); 59 | } 60 | }); 61 | } catch (exception) { 62 | // An instance of the widget has already been rendered. Call remove() first. 63 | } 64 | } 65 | 66 | get idTokenAsUser() { 67 | const token = this.signIn.tokenManager.get('idToken'); 68 | return { 69 | name: token.claims.name, 70 | email: token.claims.email, 71 | username: token.claims.preferred_username 72 | }; 73 | } 74 | 75 | async logout() { 76 | // Terminates the session with Okta and removes current tokens. 77 | this.signIn.tokenManager.clear(); 78 | await this.signIn.signOut(); 79 | this.signIn.remove(); 80 | this.userSource.next(undefined); 81 | this.login(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /client/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oktadev/okta-kotlin-typescript-notes-example/8b3e68030bfcdaa11b2083508c60cf4099162a25/client/src/assets/.gitkeep -------------------------------------------------------------------------------- /client/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /client/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `.angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /client/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oktadev/okta-kotlin-typescript-notes-example/8b3e68030bfcdaa11b2083508c60cf4099162a25/client/src/favicon.ico -------------------------------------------------------------------------------- /client/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Notes 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /client/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 | -------------------------------------------------------------------------------- /client/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/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** IE10 and IE11 requires the following for the Reflect API. */ 41 | // import 'core-js/es6/reflect'; 42 | 43 | 44 | /** Evergreen browsers require these. **/ 45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. 46 | import 'core-js/es7/reflect'; 47 | 48 | 49 | /** 50 | * Required to support Web Animations `@angular/platform-browser/animations`. 51 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation 52 | **/ 53 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 54 | 55 | 56 | 57 | /*************************************************************************************************** 58 | * Zone JS is required by Angular itself. 59 | */ 60 | import 'zone.js/dist/zone'; // Included with Angular CLI. 61 | 62 | 63 | 64 | /*************************************************************************************************** 65 | * APPLICATION IMPORTS 66 | */ 67 | 68 | /** 69 | * Date, currency, decimal and percent pipes. 70 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 71 | */ 72 | // import 'intl'; // Run `npm install --save intl`. 73 | /** 74 | * Need to import at least one locale-data with intl. 75 | */ 76 | // import 'intl/locale-data/jsonp/en'; 77 | -------------------------------------------------------------------------------- /client/src/styles.css: -------------------------------------------------------------------------------- 1 | @import '~@okta/okta-signin-widget/dist/css/okta-sign-in.min.css'; 2 | @import '~@okta/okta-signin-widget/dist/css/okta-theme.css'; 3 | @import "~@angular/material/prebuilt-themes/indigo-pink.css"; 4 | @import '~https://fonts.googleapis.com/icon?family=Material+Icons'; 5 | 6 | body { 7 | margin: 0; 8 | font-family: Roboto, sans-serif; 9 | } 10 | 11 | #okta-sign-in.auth-container { 12 | font-family: Roboto, sans-serif; 13 | } 14 | -------------------------------------------------------------------------------- /client/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/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | import { getTestBed } from '@angular/core/testing'; 10 | import { 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting 13 | } from '@angular/platform-browser-dynamic/testing'; 14 | 15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 16 | declare const __karma__: any; 17 | declare const require: any; 18 | 19 | // Prevent Karma from running prematurely. 20 | __karma__.loaded = function () {}; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting() 26 | ); 27 | // Then we find all the tests. 28 | const context = require.context('./', true, /\.spec\.ts$/); 29 | // And load the modules. 30 | context.keys().map(context); 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /client/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "baseUrl": "./", 6 | "module": "es2015", 7 | "types": [] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /client/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | }, 13 | "files": [ 14 | "test.ts" 15 | ], 16 | "include": [ 17 | "**/*.spec.ts", 18 | "**/*.d.ts" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /client/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "sourceMap": true, 6 | "declaration": false, 7 | "moduleResolution": "node", 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "target": "es5", 11 | "typeRoots": [ 12 | "node_modules/@types" 13 | ], 14 | "lib": [ 15 | "es2017", 16 | "dom" 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /client/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "eofline": true, 15 | "forin": true, 16 | "import-blacklist": [ 17 | true, 18 | "rxjs" 19 | ], 20 | "import-spacing": true, 21 | "indent": [ 22 | true, 23 | "spaces" 24 | ], 25 | "interface-over-type-literal": true, 26 | "label-position": true, 27 | "max-line-length": [ 28 | true, 29 | 140 30 | ], 31 | "member-access": false, 32 | "member-ordering": [ 33 | true, 34 | { 35 | "order": [ 36 | "static-field", 37 | "instance-field", 38 | "static-method", 39 | "instance-method" 40 | ] 41 | } 42 | ], 43 | "no-arg": true, 44 | "no-bitwise": true, 45 | "no-console": [ 46 | true, 47 | "debug", 48 | "info", 49 | "time", 50 | "timeEnd", 51 | "trace" 52 | ], 53 | "no-construct": true, 54 | "no-debugger": true, 55 | "no-duplicate-super": true, 56 | "no-empty": false, 57 | "no-empty-interface": true, 58 | "no-eval": true, 59 | "no-inferrable-types": [ 60 | true, 61 | "ignore-params" 62 | ], 63 | "no-misused-new": true, 64 | "no-non-null-assertion": true, 65 | "no-shadowed-variable": true, 66 | "no-string-literal": false, 67 | "no-string-throw": true, 68 | "no-switch-case-fall-through": true, 69 | "no-trailing-whitespace": true, 70 | "no-unnecessary-initializer": true, 71 | "no-unused-expression": true, 72 | "no-use-before-declare": true, 73 | "no-var-keyword": true, 74 | "object-literal-sort-keys": false, 75 | "one-line": [ 76 | true, 77 | "check-open-brace", 78 | "check-catch", 79 | "check-else", 80 | "check-whitespace" 81 | ], 82 | "prefer-const": true, 83 | "quotemark": [ 84 | true, 85 | "single" 86 | ], 87 | "radix": true, 88 | "semicolon": [ 89 | true, 90 | "always" 91 | ], 92 | "triple-equals": [ 93 | true, 94 | "allow-null-check" 95 | ], 96 | "typedef-whitespace": [ 97 | true, 98 | { 99 | "call-signature": "nospace", 100 | "index-signature": "nospace", 101 | "parameter": "nospace", 102 | "property-declaration": "nospace", 103 | "variable-declaration": "nospace" 104 | } 105 | ], 106 | "typeof-compare": true, 107 | "unified-signatures": true, 108 | "variable-name": false, 109 | "whitespace": [ 110 | true, 111 | "check-branch", 112 | "check-decl", 113 | "check-operator", 114 | "check-separator", 115 | "check-type" 116 | ], 117 | "directive-selector": [ 118 | true, 119 | "attribute", 120 | "app", 121 | "camelCase" 122 | ], 123 | "component-selector": [ 124 | true, 125 | "element", 126 | "app", 127 | "kebab-case" 128 | ], 129 | "use-input-property-decorator": true, 130 | "use-output-property-decorator": true, 131 | "use-host-property-decorator": true, 132 | "no-input-rename": true, 133 | "no-output-rename": true, 134 | "use-life-cycle-interface": true, 135 | "use-pipe-transform-interface": true, 136 | "component-class-suffix": true, 137 | "directive-class-suffix": true, 138 | "no-access-missing-member": true, 139 | "templates-use-public": true, 140 | "invoke-injectable": true 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /manifest.yml: -------------------------------------------------------------------------------- 1 | --- 2 | applications: 3 | 4 | - name: notes-server 5 | host: notes-by-kotlin 6 | path: ./server/target/notes-0.0.1-SNAPSHOT.jar 7 | env : 8 | FORCE_HTTPS: true 9 | 10 | - name: notes-client 11 | host: notes-with-typescript 12 | path: ./client/dist/ 13 | env : 14 | FORCE_HTTPS: true 15 | -------------------------------------------------------------------------------- /reset.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cf d -f notes-server 4 | cf d -f notes-client 5 | 6 | cf delete-orphaned-routes 7 | -------------------------------------------------------------------------------- /server/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oktadev/okta-kotlin-typescript-notes-example/8b3e68030bfcdaa11b2083508c60cf4099162a25/server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /server/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /server/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.okta.developer 7 | notes 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | notes 12 | Notes Server with Kotlin and Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | true 23 | UTF-8 24 | UTF-8 25 | 1.8 26 | 1.1.61 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-data-jpa 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-data-rest 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-web 41 | 42 | 43 | com.okta.spring 44 | okta-spring-security-starter 45 | 0.1.0 46 | 47 | 48 | org.jetbrains.kotlin 49 | kotlin-stdlib-jre8 50 | ${kotlin.version} 51 | 52 | 53 | org.jetbrains.kotlin 54 | kotlin-reflect 55 | ${kotlin.version} 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-devtools 60 | runtime 61 | 62 | 63 | com.h2database 64 | h2 65 | runtime 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-starter-test 70 | test 71 | 72 | 73 | org.springframework.security 74 | spring-security-test 75 | test 76 | 77 | 78 | 79 | 80 | 81 | 82 | org.springframework.security.oauth 83 | spring-security-oauth2 84 | 2.2.0.RELEASE 85 | 86 | 87 | 88 | 89 | 90 | spring-boot:run 91 | ${project.basedir}/src/main/kotlin 92 | ${project.basedir}/src/test/kotlin 93 | 94 | 95 | org.springframework.boot 96 | spring-boot-maven-plugin 97 | 98 | 99 | kotlin-maven-plugin 100 | org.jetbrains.kotlin 101 | ${kotlin.version} 102 | 103 | 104 | spring 105 | 106 | 1.8 107 | 108 | 109 | 110 | compile 111 | compile 112 | 113 | compile 114 | 115 | 116 | 117 | test-compile 118 | test-compile 119 | 120 | test-compile 121 | 122 | 123 | 124 | 125 | 126 | org.jetbrains.kotlin 127 | kotlin-maven-allopen 128 | ${kotlin.version} 129 | 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /server/src/main/kotlin/com/okta/developer/notes/NotesApplication.kt: -------------------------------------------------------------------------------- 1 | package com.okta.developer.notes 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore 4 | import org.springframework.boot.ApplicationArguments 5 | import org.springframework.boot.ApplicationRunner 6 | import org.springframework.boot.SpringApplication 7 | import org.springframework.boot.autoconfigure.SpringBootApplication 8 | import org.springframework.boot.web.servlet.FilterRegistrationBean 9 | import org.springframework.context.annotation.Bean 10 | import org.springframework.core.Ordered 11 | import org.springframework.data.jpa.repository.JpaRepository 12 | import org.springframework.data.rest.core.annotation.HandleBeforeCreate 13 | import org.springframework.data.rest.core.annotation.RepositoryEventHandler 14 | import org.springframework.data.rest.core.annotation.RepositoryRestResource 15 | import org.springframework.security.core.context.SecurityContextHolder 16 | import org.springframework.stereotype.Component 17 | import org.springframework.web.bind.annotation.GetMapping 18 | import org.springframework.web.bind.annotation.RestController 19 | import org.springframework.web.cors.CorsConfiguration 20 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource 21 | import org.springframework.web.filter.CorsFilter 22 | import java.security.Principal 23 | import javax.persistence.Entity 24 | import javax.persistence.GeneratedValue 25 | import javax.persistence.Id 26 | 27 | @SpringBootApplication 28 | class NotesApplication { 29 | 30 | @Bean 31 | fun simpleCorsFilter(): FilterRegistrationBean { 32 | val source = UrlBasedCorsConfigurationSource() 33 | val config = CorsConfiguration() 34 | config.allowCredentials = true 35 | config.allowedOrigins = listOf("http://localhost:4200") 36 | config.allowedMethods = listOf("*"); 37 | config.allowedHeaders = listOf("*") 38 | source.registerCorsConfiguration("/**", config) 39 | val bean = FilterRegistrationBean(CorsFilter(source)) 40 | bean.order = Ordered.HIGHEST_PRECEDENCE 41 | return bean 42 | } 43 | } 44 | 45 | fun main(args: Array) { 46 | SpringApplication.run(NotesApplication::class.java, *args) 47 | } 48 | 49 | @Entity 50 | data class Note(@Id @GeneratedValue var id: Long? = null, 51 | var text: String? = null, 52 | @JsonIgnore var user: String? = null) 53 | 54 | @RepositoryRestResource 55 | interface NotesRepository : JpaRepository { 56 | fun findAllByUser(name: String): List 57 | } 58 | 59 | @Component 60 | class DataInitializer(val repository: NotesRepository) : ApplicationRunner { 61 | 62 | @Throws(Exception::class) 63 | override fun run(args: ApplicationArguments) { 64 | listOf("Note 1", "Note 2", "Note 3").forEach { 65 | repository.save(Note(text = it, user = "user")) 66 | } 67 | repository.findAll().forEach { println(it) } 68 | } 69 | } 70 | 71 | @Component 72 | @RepositoryEventHandler(Note::class) 73 | class AddUserToNote { 74 | 75 | @HandleBeforeCreate 76 | fun handleCreate(note: Note) { 77 | val username: String = SecurityContextHolder.getContext().getAuthentication().name 78 | println("Creating note: $note with user: $username") 79 | note.user = username 80 | } 81 | } 82 | 83 | @RestController 84 | class HomeController(val repository: NotesRepository) { 85 | 86 | @GetMapping("/") 87 | fun home(principal: Principal): List { 88 | println("Fetching notes for user: ${principal.name}") 89 | val notes = repository.findAllByUser(principal.name) 90 | if (notes.isEmpty()) { 91 | return listOf() 92 | } else { 93 | return notes 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | okta.oauth.issuer=https://dev-158606.oktapreview.com/oauth2/default 2 | okta.oauth.clientId=0oabl213xlbMjGJYo0h7 -------------------------------------------------------------------------------- /server/src/test/kotlin/com/okta/developer/notes/NotesApplicationTests.kt: -------------------------------------------------------------------------------- 1 | package com.okta.developer.notes 2 | 3 | import org.hamcrest.Matchers.hasItem 4 | import org.hamcrest.Matchers.hasSize 5 | import org.junit.Before 6 | import org.junit.Ignore 7 | import org.junit.Test 8 | import org.junit.runner.RunWith 9 | import org.springframework.beans.factory.annotation.Autowired 10 | import org.springframework.boot.test.context.SpringBootTest 11 | import org.springframework.http.MediaType 12 | import org.springframework.security.test.context.support.WithMockUser 13 | import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity 14 | import org.springframework.test.context.junit4.SpringRunner 15 | import org.springframework.test.web.servlet.MockMvc 16 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get 17 | import org.springframework.test.web.servlet.result.MockMvcResultMatchers.* 18 | import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder 19 | import org.springframework.test.web.servlet.setup.MockMvcBuilders 20 | import org.springframework.web.context.WebApplicationContext 21 | 22 | @RunWith(SpringRunner::class) 23 | @SpringBootTest 24 | class NotesApplicationTests { 25 | 26 | @Autowired 27 | lateinit var context: WebApplicationContext 28 | 29 | private var mockMvc: MockMvc? = null 30 | 31 | @Before 32 | fun setup() { 33 | mockMvc = MockMvcBuilders 34 | .webAppContextSetup(context) 35 | .apply(springSecurity()).build() 36 | } 37 | 38 | @Test 39 | @WithMockUser 40 | @Ignore("Doesn't pass with Okta Spring Security starter") 41 | fun getDefaultNotes() { 42 | mockMvc!!.perform(get("/")) 43 | .andExpect(status().isOk()) 44 | .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON_UTF8_VALUE)) 45 | .andExpect(jsonPath>("$", hasSize(3))) 46 | .andExpect(jsonPath("$.[*].id").value(hasItem(1))) 47 | .andExpect(jsonPath("$.[*].text").value(hasItem("Note 3"))) 48 | } 49 | } 50 | --------------------------------------------------------------------------------