@@ -129,7 +129,12 @@ public final class AuthorizationException extends Exception {
129129 /**
130130 * The error type for persistence specific errors.
131131 */
132- public static final int TYPE_ENCRYPTION_ERROR = 4 ;
132+ public static final int TYPE_ENCRYPTION_ERROR = 5 ;
133+
134+ /**
135+ * The error type for OAuth token validation errors.
136+ */
137+ public static final int TYPE_OAUTH_VALIDATION_TOKEN_ERROR = 6 ;
133138
134139 @ VisibleForTesting
135140 static final String KEY_TYPE = "type" ;
@@ -524,6 +529,63 @@ public static AuthorizationException byEncryptionException(EncryptionException e
524529 }
525530 }
526531
532+ /**
533+ * Error codes related to failed during token validation.
534+ */
535+ public static final class TokenValidationError {
536+ public static final int NOT_SUPPORTED_ALGORITHM_ERROR = 6000 ;
537+ public static final int ISSUER_MISMATCH_ERROR = 6001 ;
538+ public static final int ISSUER_NOT_HTTPS_URL_ERROR = 6002 ;
539+ public static final int ISSUER_HOST_EMPTY_ERROR = 6003 ;
540+ public static final int ISSUER_URL_CONTAIN_OTHER_COMPONENTS_ERROR = 6004 ;
541+ public static final int AUDIENCE_MISMATCH_ERROR = 6005 ;
542+ public static final int ID_TOKEN_EXPIRED_ERROR = 6006 ;
543+ public static final int ID_TOKEN_WRONG_ISSUED_TIME_ERROR = 6007 ;
544+ public static final int NONCE_MISMATCH_ERROR = 6008 ;
545+ public static final int AUTH_TIME_MISSING_ERROR = 6009 ;
546+
547+ public static AuthorizationException createNotSupportedAlgorithmException (String alg ) {
548+ return tokenValidationEx (NOT_SUPPORTED_ALGORITHM_ERROR ,
549+ "JWT Header 'alg' of [" + alg + "] " +
550+ "is not supported, only RSA256 signatures are supported" );
551+ }
552+
553+ public static final AuthorizationException ISSUER_MISMATCH =
554+ tokenValidationEx (ISSUER_MISMATCH_ERROR , "Issuer mismatch" );
555+
556+ public static final AuthorizationException ISSUER_NOT_HTTPS_URL =
557+ tokenValidationEx (ISSUER_NOT_HTTPS_URL_ERROR ,
558+ "Issuer must be an https URL" );
559+
560+ public static final AuthorizationException ISSUER_HOST_EMPTY =
561+ tokenValidationEx (ISSUER_HOST_EMPTY_ERROR ,
562+ "Issuer host can not be empty" );
563+
564+ public static final AuthorizationException ISSUER_URL_CONTAIN_OTHER_COMPONENTS =
565+ tokenValidationEx (ISSUER_URL_CONTAIN_OTHER_COMPONENTS_ERROR ,
566+ "Issuer URL contains query parameters or fragment components" );
567+
568+ public static final AuthorizationException AUDIENCE_MISMATCH =
569+ tokenValidationEx (AUDIENCE_MISMATCH_ERROR , "Audience mismatch" );
570+
571+ public static final AuthorizationException ID_TOKEN_EXPIRED =
572+ tokenValidationEx (ID_TOKEN_EXPIRED_ERROR , "ID Token expired" );
573+
574+ public static AuthorizationException createWrongTokenIssuedTime (int minutes ) {
575+ return tokenValidationEx (ID_TOKEN_WRONG_ISSUED_TIME_ERROR ,
576+ "Issued at time is more than "
577+ + minutes + " minutes before or after the current time" );
578+ }
579+
580+ public static final AuthorizationException NONCE_MISMATCH =
581+ tokenValidationEx (NONCE_MISMATCH_ERROR , "Nonce mismatch" );
582+
583+ public static final AuthorizationException AUTH_TIME_MISSING =
584+ tokenValidationEx (AUTH_TIME_MISSING_ERROR ,
585+ "max_age provided but auth_time is missing" );
586+
587+ }
588+
527589 private static AuthorizationException generalEx (int code , @ Nullable String errorDescription ) {
528590 return new AuthorizationException (
529591 TYPE_GENERAL_ERROR , code , null , errorDescription , null , null );
@@ -544,6 +606,11 @@ private static AuthorizationException registrationEx(int code, @Nullable String
544606 TYPE_OAUTH_REGISTRATION_ERROR , code , error , null , null , null );
545607 }
546608
609+ private static AuthorizationException tokenValidationEx (int code , @ Nullable String error ) {
610+ return new AuthorizationException (
611+ TYPE_OAUTH_VALIDATION_TOKEN_ERROR , code , null , error , null , null );
612+ }
613+
547614 /**
548615 * Creates an exception based on one of the existing values defined in
549616 * {@link GeneralErrors}, {@link AuthorizationRequestErrors} or {@link TokenRequestErrors},
0 commit comments