Code
@objc(MoEngageJwtAuthenticationErrorDetailsCode)
public enum Code : Int, RawRepresentable, CustomStringConvertible
JWT Authentication Error Codes.
This enum defines all possible JWT authentication error codes that can occur during token processing and validation. Each code represents a specific failure scenario with a unique integer value for easy identification.
-
Token has expired or time constraints failed (Error Code: 4010).
This error occurs when the JWT token has expired based on its
exp(expiration) claim or when time-based validation fails. This is the most common JWT error.Common Causes
- Token expiration time (
expclaim) has passed - Clock skew between client and server
- Token issued in the future (
iatornbfclaims)
Resolution
- Refresh the JWT token with a new one
- Ensure system clock is synchronized
- Check token generation logic for correct timestamps
Declaration
Swift
case timeConstraintFailure = 4010 - Token expiration time (
-
Token decryption failed (Error Code: 4000).
This error occurs when the JWT token cannot be decrypted or decoded properly. This typically indicates issues with token format or encryption.
Common Causes
- Malformed JWT token structure
- Incorrect encoding (not Base64URL)
- Corrupted token data during transmission
- Wrong encryption algorithm or keys
Resolution
- Verify token format and structure
- Check token generation and encoding process
- Ensure proper token transmission without corruption
Declaration
Swift
case decryptionFailed = 4000 -
JWT header type is incompatible (Error Code: 4001).
This error occurs when the JWT header contains an unsupported or invalid token type or algorithm specification.
Common Causes
- Unsupported
alg(algorithm) in JWT header - Invalid
typ(type) field in header - Missing required header fields
- Incompatible JWT version or format
Resolution
- Use supported JWT algorithms (RS256, HS256, etc.)
- Ensure proper JWT header format
- Verify algorithm compatibility with server
Declaration
Swift
case headerTypeIncompatible = 4001 - Unsupported
-
Token payload content is missing or invalid (Error Code: 4002).
This error occurs when the JWT payload (claims) is missing required information or contains invalid data.
Common Causes
- Missing required claims (sub, iss, aud, etc.)
- Invalid claim values or formats
- Empty or corrupted payload
- Malformed JSON in payload
Resolution
- Include all required JWT claims
- Validate claim values and formats
- Ensure proper JSON structure in payload
Declaration
Swift
case tokenPayloadContentMissing = 4002 -
Token signature validation failed (Error Code: 4030).
This error occurs when the JWT signature cannot be verified, indicating potential token tampering or key mismatch.
Common Causes
- Token has been modified or tampered with
- Wrong signing key or algorithm
- Key rotation without proper handling
- Signature corruption during transmission
Resolution
- Verify signing keys and algorithms
- Check for token tampering
- Implement proper key rotation handling
- Ensure secure token transmission
Declaration
Swift
case invalidSignature = 4030 -
User identifier mismatch (Error Code: 4031).
This error occurs when the user identifier in the JWT token doesn’t match the expected user context or session.
Common Causes
- Token issued for different user
- User context changed after token issuance
- Cross-user token usage
- Session management issues
Resolution
- Verify user context and token association
- Implement proper session management
- Re-authenticate with correct user credentials
Declaration
Swift
case identifierMismatch = 4031 -
Unknown or unspecified authentication error (Error Code: 4050).
This error occurs when an authentication failure happens but doesn’t fit into other specific error categories.
Common Causes
- Server-side processing errors
- Network or communication issues
- Unexpected server responses
- New error types not yet categorized
Resolution
- Check server logs for detailed error information
- Verify network connectivity and server status
- Contact support if error persists
- Implement generic error handling
Declaration
Swift
case unknown = 4050 -
JWT token is not available when required (Error Code: 1001).
This error occurs when a JWT token is required for authentication but no token has been provided or stored.
Common Causes
- No token provided via
passJwtTokenmethod - Token cleared or expired locally
- SDK not properly initialized with JWT
- Authentication flow not completed
Resolution
- Call
passJwtTokenwith valid token and user identifier - Ensure proper authentication flow completion
- Check JWT configuration in SDK initialization
Declaration
Swift
case tokenNotAvailable = 1001 - No token provided via
-
Human-readable description of the error code.
Declaration
Swift
public var description: String { get }