Skip to content

Commit ba3d04c

Browse files
authored
Merge pull request #81 from speakeasy-sdks/ms/machine-auth-additional-changes
machine auth additional changes
2 parents 7ca7654 + 1ec6b3c commit ba3d04c

12 files changed

Lines changed: 610 additions & 53 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.clerk.backend_api.helpers.security.models;
2+
3+
import io.jsonwebtoken.Claims;
4+
import java.util.List;
5+
import java.util.Map;
6+
7+
public class APIKeyMachineAuthObject implements AuthObject {
8+
private TokenType tokenType = TokenType.API_KEY;
9+
private String id;
10+
private String userId;
11+
private String orgId;
12+
private String name;
13+
private List<String> scopes;
14+
private Map<String, Object> claims;
15+
16+
public APIKeyMachineAuthObject(String id, String userId, String orgId, String name,
17+
List<String> scopes, Map<String, Object> claims) {
18+
this.id = id;
19+
this.userId = userId;
20+
this.orgId = orgId;
21+
this.name = name;
22+
this.scopes = scopes;
23+
this.claims = claims;
24+
}
25+
26+
public TokenType getTokenType() {
27+
return tokenType;
28+
}
29+
30+
public String getId() {
31+
return id;
32+
}
33+
34+
public String getUserId() {
35+
return userId;
36+
}
37+
38+
public String getOrgId() {
39+
return orgId;
40+
}
41+
42+
public String getName() {
43+
return name;
44+
}
45+
46+
public List<String> getScopes() {
47+
return scopes;
48+
}
49+
50+
public Map<String, Object> getClaims() {
51+
return claims;
52+
}
53+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.clerk.backend_api.helpers.security.models;
2+
3+
public interface AuthObject {
4+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.clerk.backend_api.helpers.security.models;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
public class M2MMachineAuthObject implements AuthObject {
7+
private TokenType token_type = TokenType.MACHINE_TOKEN;
8+
private String id;
9+
private String machineId;
10+
private String clientId;
11+
private String name;
12+
private List<String> scopes;
13+
private Map<String, Object> claims;
14+
15+
public M2MMachineAuthObject(String id, String machineId, String clientId, String name,
16+
List<String> scopes, Map<String, Object> claims) {
17+
this.id = id;
18+
this.machineId = machineId;
19+
this.clientId = clientId;
20+
this.name = name;
21+
this.scopes = scopes;
22+
this.claims = claims;
23+
}
24+
25+
public TokenType getToken_type() {
26+
return token_type;
27+
}
28+
29+
public String getId() {
30+
return id;
31+
}
32+
33+
public String getMachineId() {
34+
return machineId;
35+
}
36+
37+
public String getClientId() {
38+
return clientId;
39+
}
40+
41+
public String getName() {
42+
return name;
43+
}
44+
45+
public List<String> getScopes() {
46+
return scopes;
47+
}
48+
49+
public Map<String, Object> getClaims() {
50+
return claims;
51+
}
52+
}

src/main/java/com/clerk/backend_api/helpers/security/models/MachineAuthVerificationData.java

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import java.util.List;
5-
import java.util.Objects;
5+
import java.util.Map;
66

77
public class MachineAuthVerificationData {
88

@@ -12,6 +12,9 @@ public class MachineAuthVerificationData {
1212
@JsonProperty("id")
1313
private String id;
1414

15+
@JsonProperty("client_id")
16+
private String clientId;
17+
1518
@JsonProperty("type")
1619
private String type;
1720

@@ -25,7 +28,7 @@ public class MachineAuthVerificationData {
2528
private List<String> scopes;
2629

2730
@JsonProperty("claims")
28-
private Claims claims;
31+
private Map<String, Object> claims;
2932

3033
@JsonProperty("created_at")
3134
private Long createdAt;
@@ -48,46 +51,30 @@ public class MachineAuthVerificationData {
4851
@JsonProperty("created_by")
4952
private String createdBy;
5053

51-
// Nested class for claims
52-
public static class Claims {
53-
@JsonProperty("permissions")
54-
private List<String> permissions;
55-
56-
// Default constructor
57-
public Claims() {}
58-
59-
// Getters and setters
60-
public List<String> getPermissions() {
61-
return permissions;
62-
}
63-
64-
public void setPermissions(List<String> permissions) {
65-
this.permissions = permissions;
66-
}
67-
68-
@Override
69-
public boolean equals(Object o) {
70-
if (this == o) return true;
71-
if (o == null || getClass() != o.getClass()) return false;
72-
Claims claims = (Claims) o;
73-
return Objects.equals(permissions, claims.permissions);
74-
}
75-
76-
@Override
77-
public int hashCode() {
78-
return Objects.hash(permissions);
79-
}
54+
public MachineAuthVerificationData() {}
8055

81-
@Override
82-
public String toString() {
83-
return "Claims{" +
84-
"permissions=" + permissions +
85-
'}';
86-
}
56+
public MachineAuthVerificationData(String object, String id, String clientId, String type, String name,
57+
String subject,
58+
List<String> scopes, Map<String, Object> claims, Long createdAt, Long updatedAt, Long expiration,
59+
Boolean revoked,
60+
String revocationReason, Boolean expired, String createdBy) {
61+
this.object = object;
62+
this.id = id;
63+
this.clientId = clientId;
64+
this.type = type;
65+
this.name = name;
66+
this.subject = subject;
67+
this.scopes = scopes;
68+
this.claims = claims;
69+
this.createdAt = createdAt;
70+
this.updatedAt = updatedAt;
71+
this.expiration = expiration;
72+
this.revoked = revoked;
73+
this.revocationReason = revocationReason;
74+
this.expired = expired;
75+
this.createdBy = createdBy;
8776
}
8877

89-
public MachineAuthVerificationData() {}
90-
9178
public String getObject() {
9279
return object;
9380
}
@@ -136,11 +123,11 @@ public void setScopes(List<String> scopes) {
136123
this.scopes = scopes;
137124
}
138125

139-
public Claims getClaims() {
126+
public Map<String, Object> getClaims() {
140127
return claims;
141128
}
142129

143-
public void setClaims(Claims claims) {
130+
public void setClaims(Map<String, Object> claims) {
144131
this.claims = claims;
145132
}
146133

@@ -200,6 +187,14 @@ public void setCreatedBy(String createdBy) {
200187
this.createdBy = createdBy;
201188
}
202189

190+
public String getClientId() {
191+
return clientId;
192+
}
193+
194+
public void setClientId(String clientId) {
195+
this.clientId = clientId;
196+
}
197+
203198
@Override
204199
public String toString() {
205200
return "ApiKey{" +
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.clerk.backend_api.helpers.security.models;
2+
3+
import java.util.List;
4+
5+
public class OAuthMachineAuthObject implements AuthObject {
6+
public TokenType token_type = TokenType.OAUTH_TOKEN;
7+
public String id;
8+
public String userId;
9+
public String clientId;
10+
public String name;
11+
public List<String> scopes;
12+
13+
public OAuthMachineAuthObject(String id, String userId, String clientId, String name, List<String> scopes) {
14+
this.id = id;
15+
this.userId = userId;
16+
this.clientId = clientId;
17+
this.name = name;
18+
this.scopes = scopes;
19+
}
20+
21+
public TokenType getToken_type() {
22+
return token_type;
23+
}
24+
25+
public String getId() {
26+
return id;
27+
}
28+
29+
public String getUserId() {
30+
return userId;
31+
}
32+
33+
public String getClientId() {
34+
return clientId;
35+
}
36+
37+
public String getName() {
38+
return name;
39+
}
40+
41+
public List<String> getScopes() {
42+
return scopes;
43+
}
44+
}

0 commit comments

Comments
 (0)