Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. def authorize_with_services
  2. begin
  3. self.client = Google::APIClient.new(application_name: 'Playground', application_version: '1')
  4.  
  5. p12 = OpenSSL::PKCS12.create('notasecret', 'descriptor',
  6. OpenSSL::PKey.read(ENV['PRIVATE_KEY']),
  7. OpenSSL::X509::Certificate.new(ENV['CERT']))
  8.  
  9. p12_binary = p12.to_der
  10.  
  11. self.client.authorization = Signet::OAuth2::Client.new(
  12. token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
  13. audience: 'https://accounts.google.com/o/oauth2/token',
  14. scope: 'https://www.googleapis.com/auth/analytics.readonly',
  15. issuer: GA_EMAIL,
  16. signing_key: Google::APIClient::PKCS12.load_key(p12_binary, 'notasecret')
  17. ).tap { |auth| auth.fetch_access_token! }
  18. rescue Signet::AuthorizationError
  19. self.client = nil
  20. end
  21.  
  22. self.client
  23. end
  24.  
  25. 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"
  26.  
  27. 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