-->

vue 使用 oidc-client 连接IdentityServer4

2020-10-16 11:22发布

问题:

authority: "http://192.168.1.50:2000", //授权新中心
授权地址用本址localhost使用没有问题,但如果使用192.168.1.50的服务器,在callback页面上就会报错:Error: No matching state found in storage
at OidcClient.js:121

<template></template>

<script>
import Oidc from "oidc-client";

import { UserManager } from "oidc-client";
const userManagerConfig = {
  client_id: "localadmin", //storeadmin
  redirect_uri: `http://localhost:8080/callback.html`,
  response_type: "code",
  scope:
    "openid profile master notification article catalog message filemanagement",
  authority: "http://192.168.1.50:2000", //授权新中心
  silent_redirect_uri: `http://localhost:8080/silentRenews.html`,
  automaticSilentRenew: true,
  filterProtocolClaims: true,
  loadUserInfo: true,
  monitorSession: true,
};
var manager = new UserManager(userManagerConfig);
export default {
  beforeCreate() {
    manager.signinRedirect();
  },
};
</script>

callback.html

new Oidc.UserManager({ response_mode: "query" }).signinRedirectCallback().then(function () {
            window.location = "/";
        }).catch(function (e) {
            console.error(e); //此处获取到错误信息:Error: No matching state found in storage
    at OidcClient.js:121
        });

回答1:

原来是因为时间的问题,我的服务器时间不正确。。