UNPKG

1.73 kBJavaScriptView Raw
1"use strict";
2// Copyright 2014 Google LLC
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15Object.defineProperty(exports, "__esModule", { value: true });
16exports.LoginTicket = void 0;
17class LoginTicket {
18 /**
19 * Create a simple class to extract user ID from an ID Token
20 *
21 * @param {string} env Envelope of the jwt
22 * @param {TokenPayload} pay Payload of the jwt
23 * @constructor
24 */
25 constructor(env, pay) {
26 this.envelope = env;
27 this.payload = pay;
28 }
29 getEnvelope() {
30 return this.envelope;
31 }
32 getPayload() {
33 return this.payload;
34 }
35 /**
36 * Create a simple class to extract user ID from an ID Token
37 *
38 * @return The user ID
39 */
40 getUserId() {
41 const payload = this.getPayload();
42 if (payload && payload.sub) {
43 return payload.sub;
44 }
45 return null;
46 }
47 /**
48 * Returns attributes from the login ticket. This can contain
49 * various information about the user session.
50 *
51 * @return The envelope and payload
52 */
53 getAttributes() {
54 return { envelope: this.getEnvelope(), payload: this.getPayload() };
55 }
56}
57exports.LoginTicket = LoginTicket;