7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/ruby_firebase_verify.rb', line 7
def self.verify_id_token(id_token)
= JSON.parse(Base64.decode64(id_token.slice(0 .. id_token.index('.')-1)))
client_cert_url = 'https://www.googleapis.com/robot/v1/metadata/x509/[email protected]'
response = HTTParty.get(client_cert_url)
certificates = JSON.parse(response.body)
raise 'Certificate not found' unless certificates.key?(['kid'])
x509 = OpenSSL::X509::Certificate.new(certificates[['kid']])
decoded_token = JWT.decode(id_token, x509.public_key, true, { algorithm: ['alg'], verify_iat: false })
decoded_token[0]['sub']
end
|