5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/firebase_token_auth/validator.rb', line 5
def validate(project_id, decoded_jwt)
payload = decoded_jwt[0]
= decoded_jwt[1]
issuer = ISSUER_BASE_URL + project_id
raise ValidationError, 'Firebase ID token has no "kid" claim.' unless ['kid']
raise ValidationError, "Firebase ID token has incorrect algorithm. Expected \"#{ALGORITHM}\" but got \"#{['alg']}\"." unless ['alg'] == ALGORITHM
raise ValidationError, "Firebase ID token has incorrect \"aud\" (audience) claim. Expected \"#{project_id}\" but got \"#{payload['aud']}\"." unless payload['aud'] == project_id
raise ValidationError, "Firebase ID token has \"iss\" (issuer) claim. Expected \"#{issuer}\" but got \"#{payload['iss']}\"." unless payload['iss'] == issuer
raise ValidationError, 'Firebase ID token has no "sub" (subject) claim.' unless payload['sub'].is_a?(String)
raise ValidationError, 'Firebase ID token has an empty string "sub" (subject) claim.' if payload['sub'].empty?
raise ValidationError, 'Firebase ID token has "sub" (subject) claim longer than 128 characters.' if payload['sub'].size > 128
raise ValidationError, 'Firebase ID token has expired.' if expired?(payload['exp'])
end
|