<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>LINE Login Demo</title>
    <style>
        #timeJump {
            display: none;
        }
    </style>
</head>

<body>
    <!-- <h1 id="timeJump">登錄成功,<span id="jTime">5</span>秒后返回App</h1> -->
    <script type="text/javascript" src="lib/jquery-3.1.1.min.js"></script>
    <script>
        var urlParam = url_get_params();
        $.ajax({
            url: 'https://api.line.me/oauth2/v2.1/token',
            data: {
                grant_type: 'authorization_code',
                code: urlParam.code,
                redirect_uri: 'http://www.firefly.live/login/line-callback.html',
                client_id: '1654468829',
                client_secret: 'd70325add488ea05fd25ba84c6d91b6c'
            },
            type: 'POST',
            success: function (res) {
                var mAutho = res;
                $.ajax({
                    url: 'https://api.line.me/oauth2/v2.1/verify',
                    type: 'POST',
                    data: {
                        client_id: '1654468829',
                        id_token: mAutho.id_token
                    },
                    success: function (res) {
                        console.log(res)
                        
                        // window.location.href = "footseenlogin://" + encodeURIComponent("www.firefly.live?token=" + mAutho.id_token + "&name=" + res.name + "&profileImageUrl=" + res.iss + "&id=" + res.sub);
                    }
                })

            }
        })
        function lineGo(){

        }
        function url_get_params() {
            var url = location.href;
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(url.indexOf("?") + 1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }
    </script>
</body>

</html>