Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def authorize_with_services
- begin
- self.client = Google::APIClient.new(application_name: 'Playground', application_version: '1')
- p12 = OpenSSL::PKCS12.create('notasecret', 'descriptor',
- OpenSSL::PKey.read(ENV['PRIVATE_KEY']),
- OpenSSL::X509::Certificate.new(ENV['CERT']))
- p12_binary = p12.to_der
- self.client.authorization = Signet::OAuth2::Client.new(
- token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
- audience: 'https://accounts.google.com/o/oauth2/token',
- scope: 'https://www.googleapis.com/auth/analytics.readonly',
- issuer: GA_EMAIL,
- signing_key: Google::APIClient::PKCS12.load_key(p12_binary, 'notasecret')
- ).tap { |auth| auth.fetch_access_token! }
- rescue Signet::AuthorizationError
- self.client = nil
- end
- self.client
- end
- PRIVATE_KEY: "Bag Attributesn friendlyName: privatekeyn localKeyID: 54 69 6D 65 20 31 34 33 35 36 38 34 30 33 31 30 32 39nKey Attributes: <No Attributes>n-----BEGIN RSA PRIVATE KEY-----nKEYn-----END RSA PRIVATE KEY-----n"
- CERT: "Bag AttributesnfriendlyName: privatekeynlocalKeyID: 54 69 6D 65 20 31 34 33 35 36 38 34 30 33 31 30 32 39nsubject=/CN=636085506886-096q9j1uotf9kp1tv4evhn2crip6dec8.apps.googleusercontent.comnissuer=/CN=636085506886-096q9j1uotf9kp1tv4evhn2crip6dec8.apps.googleusercontent.comn-----BEGIN CERTIFICATE-----nCERTn-----END CERTIFICATE-----n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement