Fixed a silent login callback error and reworked project structure.

This commit is contained in:
Harrison Deng 2021-07-14 01:15:04 -05:00
parent bad22090a3
commit 840b59fcba
24 changed files with 72 additions and 63 deletions

View File

@ -1,33 +1,33 @@
module.exports = {
root: true,
env: {
node: true
},
extends: [
'plugin:vue/vue3-essential',
'@vue/standard'
],
parserOptions: {
parser: 'babel-eslint'
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'quotes': ['error', 'double', 'avoid-escape'],
'semi': ['error', 'always'],
'indent': ['error', 4],
'comma-dangle': ['error', 'only-multiline'],
'space-before-function-paren': ['error', 'never']
},
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)'
],
env: {
mocha: true
}
}
]
root: true,
env: {
node: true
},
extends: [
'plugin:vue/vue3-essential',
'@vue/standard'
],
parserOptions: {
parser: 'babel-eslint'
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'quotes': ['error', 'double', 'avoid-escape'],
'semi': ['error', 'always'],
'indent': ['error', 4, { "SwitchCase": 1 }],
'comma-dangle': ['error', 'only-multiline'],
'space-before-function-paren': ['error', 'never']
},
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)'
],
env: {
mocha: true
}
}
]
}

View File

@ -1,13 +0,0 @@
import { UserManager, WebStorageStateStore } from "oidc-client";
const userManager = new UserManager({
authority: window.location.origin,
client_id: "Props",
redirect_uri: window.location.origin + "/authentication/login-callback",
post_logout_redirect_uri: window.location.origin + "/authentication/logout-callback",
response_type: "code",
scope: "openid profile",
userStore: new WebStorageStateStore({ store: window.localStorage }),
});
userManager.signinSilentCallback();

View File

@ -1,16 +1,18 @@
<!-- Completely separate static html should improve silent login performance as we don't need to load entire SPA. -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>authentication</title>
<script type="module" src="callback-handler.js"></script>
</head>
<body>
<div>
Silently authenticating user. If you are seeing this page, you probably want to <a href="/">go back to the app</a>.
Processing... If you're seeing this, you may want to <a href="/">go back to the app</a>.
</div>
</body>
</html>

View File

@ -13,7 +13,7 @@
</template>
<script>
import { identityPaths } from "../services/authentication";
import { identityPaths } from "@/services/authentication";
import WaitCircle from "./WaitCircle.vue";
export default {
components: {
@ -29,7 +29,7 @@ export default {
},
data() {
return {
manageUrl: identityPaths.Manage,
manageUrl: identityPaths.Manage
};
},
computed: {

View File

@ -4,8 +4,8 @@ import "./registerServiceWorker";
import router from "./router";
import store from "./store";
import "../node_modules/bootstrap-icons/font/bootstrap-icons.css";
import "./assets/scss/main.scss"; // Main global scss file.
import "@/../node_modules/bootstrap-icons/font/bootstrap-icons.css";
import "@/assets/scss/main.scss"; // Main global scss file.
const app = createApp(App);

View File

@ -1,7 +1,7 @@
import router from "../router";
import { identityPaths, identityQueryParameters, userManager } from "../services/authentication";
import { addBearerTokenInterceptor, apiHttp, removeBearerTokenInterceptor } from "../services/http";
import { get, put } from "../services/persistence";
import { identityPaths, identityQueryParameters, userManager } from "@/services/authentication";
import { addBearerTokenInterceptor, apiHttp, removeBearerTokenInterceptor } from "@/services/http";
import { get, put } from "@/services/persistence";
const identity = {
state: () => ({
@ -67,7 +67,7 @@ const identity = {
if (!context.getters.isAuthenticated) {
try {
const user = await userManager.signinSilent({
redirect_uri: window.location.origin + "/authentication/silent-login-callback.html"
redirect_uri: window.location.origin + "/silent/login-callback"
});
context.commit("login", { user });

View File

@ -15,7 +15,7 @@
<script>
import WaitCircle from "../components/WaitCircle.vue";
import { userManager } from "../services/authentication";
import { userManager } from "@/services/authentication";
export default {
name: "Authentication",
@ -44,7 +44,9 @@ export default {
await userManager.signoutRedirectCallback();
this.$store.dispatch("completeDeauthentication");
} else if (this.action === "silent-login") {
this.$store.dispatch("attemptSilentAuthentication", { redirect: true });
this.$store.dispatch("attemptSilentAuthentication", {
redirect: true
});
} else {
console.warn("Unknown callback: " + this.action);
}

View File

@ -4,7 +4,7 @@
<img
id="large-logo"
alt="SHAID logo"
src="../assets/images/logo.svg"
src="@/assets/images/logo.svg"
class="img-fluid"
/>
</div>

View File

@ -0,0 +1,12 @@
const { userManager } = require("../services/authentication");
const action = window.location.pathname.split("/").pop();
switch (action) {
case "login-callback":
userManager.signinSilentCallback();
break;
default:
console.warn("Unknown silent action: " + action);
break;
}

View File

@ -1,9 +1,13 @@
module.exports = {
pages: {
index: {
entry: "src/main.js",
entry: "src/index/main.js",
template: "public/index.html",
title: "Props"
},
silent: {
entry: "src/silent/main.js",
template: "public/silent.html",
}
},
css: {

View File

@ -2,11 +2,11 @@ using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Props.Data;
using Props.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Props.Data;
using Props.Models;
namespace Props
{
@ -35,9 +35,11 @@ namespace Props
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>(
options => {
options.Clients.AddIdentityServerSPA("Props", spa => {
spa.WithRedirectUri("/authentication/silent-login-callback.html");
options =>
{
options.Clients.AddIdentityServerSPA("Props", spa =>
{
spa.WithRedirectUri("/silent/login-callback");
spa.WithRedirectUri("/authentication/login-callback");
spa.WithLogoutRedirectUri("/authentication/logout-callback");
});