1 // Copyright 2020 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 //////////////////////////////////////////////////////////////////////////////// 16 17 package com.google.crypto.tink.jwt; 18 19 final class JwtNames { 20 /** 21 * Registered claim names, as defined in https://tools.ietf.org/html/rfc7519#section-4.1. If 22 * update, please update validateClaim(). 23 */ 24 static final String CLAIM_ISSUER = "iss"; 25 26 static final String CLAIM_SUBJECT = "sub"; 27 static final String CLAIM_AUDIENCE = "aud"; 28 static final String CLAIM_EXPIRATION = "exp"; 29 static final String CLAIM_NOT_BEFORE = "nbf"; 30 static final String CLAIM_ISSUED_AT = "iat"; 31 static final String CLAIM_JWT_ID = "jti"; 32 33 /** 34 * Supported protected headers, as described in https://tools.ietf.org/html/rfc7515#section-4.1 35 */ 36 static final String HEADER_ALGORITHM = "alg"; 37 38 static final String HEADER_KEY_ID = "kid"; 39 static final String HEADER_TYPE = "typ"; 40 static final String HEADER_CRITICAL = "crit"; 41 validate(String name)42 static void validate(String name) { 43 if (isRegisteredName(name)) { 44 throw new IllegalArgumentException( 45 String.format( 46 "claim '%s' is invalid because it's a registered name; use the corresponding" 47 + " setter method.", 48 name)); 49 } 50 } 51 isRegisteredName(String name)52 static boolean isRegisteredName(String name) { 53 return name.equals(CLAIM_ISSUER) 54 || name.equals(CLAIM_SUBJECT) 55 || name.equals(CLAIM_AUDIENCE) 56 || name.equals(CLAIM_EXPIRATION) 57 || name.equals(CLAIM_NOT_BEFORE) 58 || name.equals(CLAIM_ISSUED_AT) 59 || name.equals(CLAIM_JWT_ID); 60 } 61 JwtNames()62 private JwtNames() {} 63 } 64