-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathIdToken.java
More file actions
133 lines (117 loc) · 4.89 KB
/
IdToken.java
File metadata and controls
133 lines (117 loc) · 4.89 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.aad.msal4j;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.io.Serializable;
import java.util.Objects;
class IdToken implements Serializable, JsonSerializable<IdToken> {
protected String issuer;
protected String subject;
protected String audience;
protected Long expirationTime;
protected Long issuedAt;
protected Long notBefore;
protected String name;
protected String preferredUsername;
protected String objectIdentifier;
protected String tenantIdentifier;
protected String upn;
protected String uniqueName;
static IdToken fromJson(JsonReader jsonReader) throws IOException {
IdToken idToken = new IdToken();
return jsonReader.readObject(reader -> {
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
switch (fieldName) {
case "iss":
idToken.issuer = reader.getString();
break;
case "sub":
idToken.subject = reader.getString();
break;
case "aud":
idToken.audience = reader.getString();
break;
case "exp":
idToken.expirationTime = reader.getLong();
break;
case "iat":
idToken.issuedAt = reader.getLong();
break;
case "nbf":
idToken.notBefore = reader.getLong();
break;
case "name":
idToken.name = reader.getString();
break;
case "preferred_username":
idToken.preferredUsername = reader.getString();
break;
case "oid":
idToken.objectIdentifier = reader.getString();
break;
case "tid":
idToken.tenantIdentifier = reader.getString();
break;
case "upn":
idToken.upn = reader.getString();
break;
case "unique_name":
idToken.uniqueName = reader.getString();
break;
default:
reader.skipChildren();
break;
}
}
return idToken;
});
}
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("iss", issuer);
jsonWriter.writeStringField("sub", subject);
jsonWriter.writeStringField("aud", audience);
jsonWriter.writeNumberField("exp", expirationTime);
jsonWriter.writeNumberField("iat", issuedAt);
jsonWriter.writeNumberField("nbf", notBefore);
jsonWriter.writeStringField("name", name);
jsonWriter.writeStringField("preferred_username", preferredUsername);
jsonWriter.writeStringField("oid", objectIdentifier);
jsonWriter.writeStringField("tid", tenantIdentifier);
jsonWriter.writeStringField("upn", upn);
jsonWriter.writeStringField("unique_name", uniqueName);
jsonWriter.writeEndObject();
return jsonWriter;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof IdToken)) return false;
IdToken other = (IdToken) o;
return Objects.equals(issuer, other.issuer)
&& Objects.equals(subject, other.subject)
&& Objects.equals(audience, other.audience)
&& Objects.equals(expirationTime, other.expirationTime)
&& Objects.equals(issuedAt, other.issuedAt)
&& Objects.equals(notBefore, other.notBefore)
&& Objects.equals(name, other.name)
&& Objects.equals(preferredUsername, other.preferredUsername)
&& Objects.equals(objectIdentifier, other.objectIdentifier)
&& Objects.equals(tenantIdentifier, other.tenantIdentifier)
&& Objects.equals(upn, other.upn)
&& Objects.equals(uniqueName, other.uniqueName);
}
@Override
public int hashCode() {
return Objects.hash(issuer, subject, audience, expirationTime, issuedAt,
notBefore, name, preferredUsername, objectIdentifier,
tenantIdentifier, upn, uniqueName);
}
}