index.html 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8"/>
    <title>zlt</title>
    <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
</head>
<body>
<div>
    <p>用户名:<span id="userName"></span></p>
    <p>应用id:<span id="clientId"></span></p>
    <p>token:<span id="accessToken"></span></p>
    <p><input type="button" value="登出" onclick="logout()"/></p>
</div>
<script>
    //应用id
    let clientId = 'app';
    //授权中心地址
    let uaaUri = 'http://127.0.0.1:9900/api-uaa/oauth/';

    window.onload = function() {
        let accessToken = sessionStorage.getItem('access_token');
        if (accessToken) {//已登录
            let username = sessionStorage.getItem('username');
            $('#accessToken').html(accessToken);
            $('#userName').html(username);
            $('#clientId').html(clientId);
        } else {//未登录
            sessionStorage.setItem("visitUri", window.location.href);
            window.location = uaaUri+'authorize?client_id='+clientId+'&redirect_uri=http://127.0.0.1:8081/login.html&response_type=code';
        }
    };

    function logout() {
        let accessToken = sessionStorage.getItem('access_token');
        sessionStorage.removeItem('access_token');
        sessionStorage.removeItem('username');
        window.location = uaaUri+'remove/token?redirect_uri=http://127.0.0.1:8081/index.html&access_token='+accessToken;
    }
</script>
</body>
</html>