Class: Google::APIClient::InstalledAppFlow Deprecated
- Inherits:
- 
      Object
      
        - Object
- Google::APIClient::InstalledAppFlow
 
- Defined in:
- lib/google/api_client/auth/installed_app.rb
Overview
Deprecated. 
Use google-auth-library-ruby instead
Small helper for the sample apps for performing OAuth 2.0 flows from the command line or in any other installed app environment.
Constant Summary collapse
- RESPONSE_BODY =
- <<-HTML <html> <head> <script> function closeWindow() { window.open('', '_self', ''); window.close(); } setTimeout(closeWindow, 10); </script> </head> <body>You may close this window.</body> </html> HTML 
Instance Method Summary collapse
- 
  
    
      #authorize(storage = nil, options = {})  ⇒ Signet::OAuth2::Client 
    
    
  
  
  
  
  
  
  
  
  
    Request authorization. 
- 
  
    
      #initialize(options)  ⇒ InstalledAppFlow 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Configure the flow. 
Constructor Details
#initialize(options) ⇒ InstalledAppFlow
Configure the flow
| 71 72 73 74 75 76 77 78 | # File 'lib/google/api_client/auth/installed_app.rb', line 71 def initialize() @port = [:port] || 9292 @authorization = Signet::OAuth2::Client.new({ :authorization_uri => 'https://accounts.google.com/o/oauth2/auth', :token_credential_uri => 'https://accounts.google.com/o/oauth2/token', :redirect_uri => "http://localhost:#{@port}/"}.update() ) end | 
Instance Method Details
#authorize(storage = nil, options = {}) ⇒ Signet::OAuth2::Client
Request authorization. Opens a browser and waits for response.
| 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | # File 'lib/google/api_client/auth/installed_app.rb', line 89 def (storage=nil, ={}) auth = @authorization server = WEBrick::HTTPServer.new( :Port => @port, :BindAddress =>"localhost", :Logger => WEBrick::Log.new(STDOUT, 0), :AccessLog => [] ) begin trap("INT") { server.shutdown } server.mount_proc '/' do |req, res| auth.code = req.query['code'] if auth.code auth.fetch_access_token! end res.status = WEBrick::HTTPStatus::RC_ACCEPTED res.body = RESPONSE_BODY server.stop end Launchy.open(auth.().to_s) server.start ensure server.shutdown end if @authorization.access_token if storage.respond_to?(:write_credentials) storage.write_credentials(@authorization) end return @authorization else return nil end end |