Skip to content

Latest commit

 

History

History
53 lines (36 loc) · 1.89 KB

README.rdoc

File metadata and controls

53 lines (36 loc) · 1.89 KB

GoogleIDToken

GoogleIDToken currently provides a single useful class “Validator”, which provides a single method “#check”, which parses and validates an ID Token allegedly generated by Google auth servers.

Creating a new validator takes a single optional hash argument. If the hash has an entry for :x509_key, that value is taken to be a key as created by OpenSSL::X509::Certificate.new, and the token is validated using that key. If there is no such entry, the keys are fetched from the Google certs endpoint www.googleapis.com/oauth2/v1/certs.

NOTE

Google is now maintaining this gem so it is better if you use their version:

github.com/google/google-id-token

Installation

This is a fork from: https://code.google.com/p/google-id-token/

gem 'google-id-token', github: 'Nerian/google-id-token'

Examples

validator = GoogleIDToken::Validator.new
jwt = validator.check(token, required_audience, optional_client_id)
if jwt
  email = jwt['email']
else
  report "Cannot validate: #{validator.problem}"
end

cert = OpenSSL::X509::Certificate.new(File.read('my-cert.pem'))
validator = GoogleIDToken::Validator.new(:x509_cert => cert)
jwt = validator.check(token, required_audience, required_client_id)
if jwt
  email = jwt['email']
else
  report "Cannot validate: #{validator.problem}"
end

LICENSE

Copyright 2015 Tim Bray, Bob Aman

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.