-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAuthorizationResponse.java
More file actions
101 lines (81 loc) · 2.92 KB
/
Copy pathAuthorizationResponse.java
File metadata and controls
101 lines (81 loc) · 2.92 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
package oiccli;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import oiccli.exceptions.AtHashError;
import oiccli.exceptions.CHashError;
import oiccli.exceptions.MissingRequiredAttribute;
public class AuthorizationResponse {
private String code;
private String accessToken;
private String tokenType;
private String idToken;
public boolean verify(Map<String, String> args) throws MissingRequiredAttribute {
//super(AuthorizationResponse, self).verify(**kwargs)
if (this.contains("aud")) {
if (args.containsKey("clientId")) {
if (!this.getAudience().contains(args.get("clientId"))) {
return false;
}
}
}
if (this.contains("idToken")) {
Map<String, String> argsTemp = new HashMap<>();
for (String arg : Arrays.asList("key", "keyjar", "algs", "sender")) {
argsTemp.put(arg, args.get(arg));
}
/*
idt = IdToken().from_jwt(str(self["id_token"]), **args)
if not idt.verify(**kwargs):
raise VerificationError("Could not verify id_token", idt)
_alg = idt.jws_header["alg"]
*/
String hFunction = "HS" + algorithm.substring(0, algorithm.length() - 3);
if (this.getAccessToken() != null) {
if (this.idt.getAtHash() == null) {
throw new MissingRequiredAttribute("Missing at_hash property" +
idToken.toString());
}
if (idt.getAtHash() != jws.leftHash(this.getAccessToken(), hFunction)) {
throw new AtHashError(
"Failed to verify access_token hash " + idt.toString());
}
}
if (this.getCode() != null) {
if (this.idt.getCHash() == null) {
throw new MissingRequiredAttribute("Missing cHash property" +
idToken.toString());
}
if (idt.getCHash() != jws.leftHash(this.getCode(), hFunction)) {
throw new CHashError("Failed to verify code hash " + idt.toString());
}
}
this.setVerifiedIdToken(idt);
}
return true;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public String getTokenType() {
return tokenType;
}
public void setTokenType(String tokenType) {
this.tokenType = tokenType;
}
public String getIdToken() {
return idToken;
}
public void setIdToken(String idToken) {
this.idToken = idToken;
}
}