PageSourceSearch

https://www.vartoslo.no/view-resources/public/common/JWTCookie.js?v=1789115892-L4

js vartoslo.no collected 2026-10-01 10:43:30 UTC 2,062 bytes, 69 lines download raw bytes

1/**
2 * JWTCookie - Get data from JWT token
3 * (c) Publish Lab AS 2020
4 */
5
6if (!window.Dac) window.Dac = {}
7var Dac = window.Dac;
8Dac.JWTCookie = class {
9
10    constructor(item) {
11        this.debug = item.debug || false;
12    }
13
14    log(msg) {
15        if (!this.debug) { return; }
16        console.log('JWT cookie handler:', msg);
17    }
18
19    get(key) {
20        this.cookie = this.cookie || this.getCookie();
21        if (!this.cookie || !this.cookie.hasOwnProperty(key)) 
22            return '';
23        return this.cookie[key] || '';
24    }
25
26    getCookie() {   
27        const cookie = this.getCookieValue('Paywall-Token');
28        if(!cookie) {
29            this.log('No Paywall token found in cookies');
30            return '';
31        }
32        return parseJwt(cookie);
33
34        function parseJwt(token) {
35            try {
36                var base64Url = token.split('.')[1];
37                var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
38                var jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) {
39                    return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
40                }).join(''));
41                return JSON.parse(jsonPayload);
42            } catch(e) {
43                this.log('Error parsing cookie, cookie probably not of type JWT token');
44                return '';
45            }
46        };
47    }
48
49    getCookieValue(a) {
50        var b = document.cookie.match('(^|;)\\s*' + a + '\\s*=\\s*([^;]+)');
51        return b ? b.pop() : '';
52    }
53
54    isAuthenticated() {
55        if (this.get('userid') || this.get('sub')) { // Subscriber is set
56            var exp = this.get('exp');
57            var softExp = this.get('softExp');
58            if (exp && softExp && Date.now) {
59                exp = parseInt(exp);
60                softExp = parseInt(softExp);
61                var now = Math.floor(Date.now() / 1000);
62                if (exp && exp > now && softExp && softExp > now) {
63                    return true;
64                }
65            }
66        }
67        return false;
68    }
69}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.