Skip to content

Commit d22f67f

Browse files
committed
Masking client id in JWT payload details
1 parent ed39a21 commit d22f67f

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

native/SampleApps/AuthFlowTester/AuthFlowTester/Views/JwtAccessView.swift

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,24 @@ struct JwtHeaderView: View {
8383
VStack(alignment: .leading, spacing: 8) {
8484
let header = token.header
8585

86-
JwtFieldRow(label: "Algorithm (alg):", value: header.algorithm)
87-
JwtFieldRow(label: "Type (typ):", value: header.type)
88-
JwtFieldRow(label: "Key ID (kid):", value: header.keyId)
89-
JwtFieldRow(label: "Token Type (tty):", value: header.tokenType)
90-
JwtFieldRow(label: "Tenant Key (tnk):", value: header.tenantKey)
91-
JwtFieldRow(label: "Version (ver):", value: header.version)
86+
if let algorithm = header.algorithm {
87+
InfoRowView(label: "Algorithm (alg):", value: algorithm)
88+
}
89+
if let type = header.type {
90+
InfoRowView(label: "Type (typ):", value: type)
91+
}
92+
if let keyId = header.keyId {
93+
InfoRowView(label: "Key ID (kid):", value: keyId)
94+
}
95+
if let tokenType = header.tokenType {
96+
InfoRowView(label: "Token Type (tty):", value: tokenType)
97+
}
98+
if let tenantKey = header.tenantKey {
99+
InfoRowView(label: "Tenant Key (tnk):", value: tenantKey)
100+
}
101+
if let version = header.version {
102+
InfoRowView(label: "Version (ver):", value: version)
103+
}
92104
}
93105
.padding(8)
94106
.background(Color(.systemGray6))
@@ -106,17 +118,25 @@ struct JwtPayloadView: View {
106118
let payload = token.payload
107119

108120
if let audience = payload.audience {
109-
JwtFieldRow(label: "Audience (aud):", value: audience.joined(separator: ", "))
121+
InfoRowView(label: "Audience (aud):", value: audience.joined(separator: ", "))
110122
}
111123

112124
if let expirationDate = token.expirationDate() {
113-
JwtFieldRow(label: "Expiration Date (exp):", value: formatDate(expirationDate))
125+
InfoRowView(label: "Expiration Date (exp):", value: formatDate(expirationDate))
114126
}
115127

116-
JwtFieldRow(label: "Issuer (iss):", value: payload.issuer)
117-
JwtFieldRow(label: "Subject (sub):", value: payload.subject)
118-
JwtFieldRow(label: "Scopes (scp):", value: payload.scopes)
119-
JwtFieldRow(label: "Client ID (client_id):", value: payload.clientId)
128+
if let issuer = payload.issuer {
129+
InfoRowView(label: "Issuer (iss):", value: issuer)
130+
}
131+
if let subject = payload.subject {
132+
InfoRowView(label: "Subject (sub):", value: subject)
133+
}
134+
if let scopes = payload.scopes {
135+
InfoRowView(label: "Scopes (scp):", value: scopes)
136+
}
137+
if let clientId = payload.clientId {
138+
InfoRowView(label: "Client ID (client_id):", value: clientId, isSensitive: true)
139+
}
120140
}
121141
.padding(8)
122142
.background(Color(.systemGray6))
@@ -131,23 +151,4 @@ struct JwtPayloadView: View {
131151
}
132152
}
133153

134-
// MARK: - Helper Views
135-
136-
struct JwtFieldRow: View {
137-
let label: String
138-
let value: String?
139-
140-
var body: some View {
141-
if let value = value, !value.isEmpty {
142-
VStack(alignment: .leading, spacing: 2) {
143-
Text(label)
144-
.font(.caption)
145-
.foregroundColor(.secondary)
146-
Text(value)
147-
.font(.system(.caption, design: .monospaced))
148-
.foregroundColor(.primary)
149-
}
150-
}
151-
}
152-
}
153154

0 commit comments

Comments
 (0)