001/* 002 * Copyright 2026 Revetware LLC. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.revetsec.oidc; 018 019import com.revetsec.jose.Jwt; 020import com.revetsec.jose.JwtClaims; 021import com.revetsec.json.JsonBoolean; 022import com.revetsec.json.JsonString; 023import com.revetsec.json.JsonValue; 024import org.jspecify.annotations.NonNull; 025 026import javax.annotation.concurrent.Immutable; 027import java.util.Optional; 028 029import static java.util.Objects.requireNonNull; 030 031/** 032 * An ID token whose signature, registered claims and OIDC checks have all passed. There is no parse-only factory. 033 * The exact issuer and subject identify the account; email is a mutable attribute, including when verified. 034 * 035 * @author <a href="https://www.revetkn.com">Mark Allen</a> 036 * @since 1.0.0 037 */ 038@Immutable 039public final class IdToken { 040 private final @NonNull Jwt jwt; 041 042 IdToken(@NonNull Jwt jwt) { 043 this.jwt = requireNonNull(jwt); 044 } 045 046 /** 047 * Returns the authenticated claims. Their explicit JSON representation may contain personal data. 048 * 049 * @return the claims 050 * @since 1.0.0 051 */ 052 public @NonNull JwtClaims getClaims() { 053 return this.jwt.getClaims(); 054 } 055 056 /** 057 * Returns the complete signed token. This deliberately emits a credential; do not log it. 058 * 059 * @return the compact serialization 060 * @since 1.0.0 061 */ 062 public @NonNull String toCompactSerialization() { 063 return this.jwt.toCompactSerialization(); 064 } 065 066 @Override 067 public @NonNull String toString() { 068 return "IdToken{claims=<redacted>, token=<redacted>}"; 069 } 070}