美文网首页
单点登录

单点登录

作者: littleStar_up | 来源:发表于2017-11-27 19:06 被阅读0次

在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统。
可以用cross-storage把登录信息放在服务器上
需要在服务器上放一个文件,项目登录后,调用服务器上的程序,把登录信息放在服务器上,其他项目登录时调用服务器上的程序,获取登录信息。
storage.js

import CrossStorage from 'cross-storage'
var storage = new CrossStorage.CrossStorageClient('http://localhost:7000/crossstorage/example/hub.html');//我的地址
/**添加Storage**/
export const addStorage = function(name, value) {
    storage.onConnect().then(function() {
        return storage.set(name, value);
    }).catch(function(err) {
        console.log(err)
    }).then(function() {
        storage.close();
    });
};

/**获取Storage**/
export const getStorage = function(name,callback) {
    storage.onConnect()
        .then(function() {
            return storage.get(name);
        }).then(function(res) {
            callback(res);
        })['catch'](function(err) {
                        console.log(err)
        });
};

/**删除Storage**/
export const delStorage = function(name) {
    storage.onConnect().then(function() {
        return storage.del(name);
    });
};

调用

        addStorage('token', token);
        window.location.reload();
        that.$router.replace('/main');

添加后需要需要刷新


web1 web2

web2可以获取localhost:7000上的token,不用再次登录

可以看看简单的例子

相关文章

网友评论

      本文标题:单点登录

      本文链接:https://www.haomeiwen.com/subject/jbshpxtx.html