Added Google::APIClient::FileStorage, to save OAuth 2 credentials to disk
[arvados.git] / lib / google / api_client / auth / installed_app.rb
index 4f7bf11a447a2fb7406b2f73984f0392bc22542f..2edf36332bae4dc89cb2b6af5b795ec19998f38f 100644 (file)
@@ -77,9 +77,13 @@ module Google
       ##
       # Request authorization. Opens a browser and waits for response.
       #
+      # @param [Google::APIClient::FileStorage] storage
+      #  Optional object that responds to :write_credentials, used to serialize
+      #  the OAuth 2 credentials after completing the flow.
+      #
       # @return [Signet::OAuth2::Client]
       #  Authorization instance, nil if user cancelled.
-      def authorize
+      def authorize(storage=nil)
         auth = @authorization
     
         server = WEBrick::HTTPServer.new(
@@ -103,6 +107,9 @@ module Google
         Launchy.open(auth.authorization_uri.to_s)
         server.start
         if @authorization.access_token
+          if storage.respond_to?(:write_credentials)
+            storage.write_credentials(@authorization)
+          end
           return @authorization
         else
           return nil