diff --git a/_source/_posts/2022-08-15-spring-boot-crud-update.md b/_source/_posts/2022-08-15-spring-boot-crud-update.md index 106f9d0de8..8510ef3046 100644 --- a/_source/_posts/2022-08-15-spring-boot-crud-update.md +++ b/_source/_posts/2022-08-15-spring-boot-crud-update.md @@ -12,6 +12,7 @@ tweets: - "" image: type: conversion + --- You're going to use Vue and Spring Boot to build a todo list web application. The application will include CRUD abilities, meaning that you will be able to **c**reate, **r**ead, **u**pdate, and **d**elete the todo items on the Spring Boot server via the client. The Vue front-end client will use the Quasar framework for presentation. Both the Spring Boot server and the Vue client will be secured with OAuth 2.0 and OpenID Connect (OIDC) using Okta as the security provider. @@ -415,7 +416,7 @@ npm i --save axios vuejs3-logger vue-router@4 @okta/okta-vue To learn more about how Okta integrates with Vue, take a look at [the GitHub page](https://github.com/okta/okta-vue) for the `okta/okta-vue` project. There are also more resources and example applications listed on in [the general Okta docs](https://developer.okta.com/code/vue/). -Replace `main.js` with the following. Look at the `OktaAuth` configuration object. Notice **there are two values that need to be filled in**: the client ID and the Okta domain for the issuer URI. +Replace `main.js` with the following. Look at the `OktaAuth` configuration object. Notice there are two values that are pulled from a `.env` file. `src/main.js` @@ -431,9 +432,13 @@ import createApi from './Api' import { OktaAuth } from '@okta/okta-auth-js' import OktaVue from '@okta/okta-vue' +if (process.env.VUE_APP_ISSUER_URI == null || process.env.VUE_APP_CLIENT_ID == null || process.env.VUE_APP_SERVER_URI == null) { + throw "Please define VUE_APP_ISSUER_URI, VUE_APP_CLIENT_ID, and VUE_APP_SERVER_URI in .env file" +} + const oktaAuth = new OktaAuth({ - issuer: 'https:///oauth2/default', - clientId: '', + issuer: process.env.VUE_APP_ISSUER_URI, + clientId: process.env.VUE_APP_CLIENT_ID, redirectUri: window.location.origin + '/login/callback', scopes: ['openid', 'profile', 'email'] }) @@ -459,7 +464,17 @@ app.config.globalProperties.$api = createApi(app.config.globalProperties.$auth) app.mount('#app') ``` -I'm not going to go deep into explaining Vue as a framework, but briefly the file above creates the main Vue app and configures it to use our dependencies: Quasar, VueLogger, OktaVue, and the router. It also creates the Api class that handles the requests to the resource server and passes it the `$auth` object it needs to get the JWT. +Stated very briefly, the file above creates the main Vue app and configures it to use our dependencies: Quasar, VueLogger, OktaVue, and the router. It also creates the Api class that handles the requests to the resource server and passes it the `$auth` object it needs to get the JWT. + +Create a `.env` file in the client project root directory. The **Client ID** and **Issuer URI** are the values you used above in the Spring Boot `application.properties` file. The **Server URI** is the local URI for the Spring Boot server is you can leave as it is unless you made a change (this gets used in the `Api.js` module). + +`.env` + +```env +VUE_APP_CLIENT_ID= +VUE_APP_ISSUER_URI= +VUE_APP_SERVER_URI=http://localhost:9000 +``` Replace `App.vue` with the following. @@ -468,8 +483,7 @@ Replace `App.vue` with the following. ```vue