patrickmonteiro / quasarOidcClient

project Quasar Framework with oidc-client library
22 stars 2 forks source link

[Improvement] Silent-renew - how about entry in quasar.config.js? #3

Open Arsync opened 5 years ago

Arsync commented 5 years ago
// quasar.config.js
const
  path = require('path'),
  HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = function (ctx) {
  ...
  build: {
    ...
    chainWebpack(chain, { isClient }) {    
      if (isClient) {      

        chain.entry('sign-in-silent')
          .add('src/sign-in-slient.ts')
          .end();

        // Important! Need to exclude this entry from main 'index.html', where chunks: 'all'     
        // Not working as expected- there is no 'html-webpack' at run,
        // but exists at 'quasar inspect'
        //
        //chain.plugin('html-webpack')
        //  .tap(args => {
        //    args[0].excludeChunks = ['sign-in-silent'];
        //    return args;
        //  });

        chain.plugin('html-silent')
          .use(new HtmlWebpackPlugin({
            template: path.resolve('src/sign-in-silent.html'),
            filename: 'sign-in-silent/index.html',
            chunks: ['sign-in-silent']
          }));
      }
    }
  }
}

Entry point for our silent callback:

// src/sign-in-silent.js
import { UserManager } from 'oidc-client';
new UserManager().signinSilentCallback();

Template:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Silent Sign-In</title>
</head>
<body>
</body>
</html>

No need to put anything into template, entry will be added by HtmlWebpackPlugin.

patrickmonteiro commented 5 years ago

@Arsync Hello, this seems to be a really great improvement. The first version I made of quasar oidc-client was made in a hurry because of the need for a project. I plan to redo a version now in quasar 1.0 as well.

Soon I will try to update this project with its improvement.

Arsync commented 5 years ago

But be careful, where am I stuck on this: https://github.com/quasarframework/quasar/issues/4999 Can't exclude 'silent-sign-in' from default entry... So it includes it in index.html too.

patrickmonteiro commented 5 years ago

In fact, I will still refactor the whole project. It really was something quite complex to implement at the time, as there is little documentation. Today with a little more knowledge I believe I can optimize many things.

But the silent renovation so far has not worked so well for me.