hydroshare / hydroshare-jupyterhub

The HydroShare Jupyterhub Notebook Server is an environment designed provide added value to existing HydroShare resources via interactive computational notebooks.
4 stars 6 forks source link

OAuth Google support #64

Open Castronova opened 7 years ago

Castronova commented 7 years ago

Enable authorization with Google.

diviningwater commented 6 years ago

I am so close to getting Google Earth Engine API access in HS Jupyter.

!pip install google-api-python-client !pip install pyCrypto !pip install earthengine-api

The last part is to enter Google Oauth token into Jupyter. Here is where the problem (or my ignorance) happens for me:

import ee
ee.Initialize()

Cell output

EEExceptionTraceback (most recent call last)
<ipython-input-6-f3577f8c04a7> in <module>()
      1 import ee
----> 2 ee.Initialize()

/opt/conda/envs/python2/lib/python2.7/site-packages/ee/__init__.pyc in Initialize(credentials, opt_url)
     88   """
     89   if credentials == 'persistent':
---> 90     credentials = _GetPersistentCredentials()
     91   data.initialize(credentials, (opt_url + '/api' if opt_url else None), opt_url)
     92   # Initialize the dynamically loaded functions on the objects that want them.

/opt/conda/envs/python2/lib/python2.7/site-packages/ee/_helpers.pyc in _GetPersistentCredentials()
     38         None, 'https://accounts.google.com/o/oauth2/token', None)
     39   except IOError:
---> 40     raise EEException('Please authorize access to your Earth Engine account '
     41                       'by running\n\nearthengine authenticate\n\nin your '
     42                       'command line, and then retry.')

EEException: Please authorize access to your Earth Engine account by running

earthengine authenticate

in your command line, and then retry.

The next command is the difficult one !earthengine authenticate

It requires the Google Auth token to be entered which is a text key like: XcFHGKHIHjkyrfJ

but entering the text in the next cell does not produce anything. In a computer Anaconda installation, these commands go in the python command window. No idea how to enter an input in a notebook

Opening the following address in a web browser:

    https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fearthengine+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id=517222506229-vsmmajv00ul0bs7p89v5m89qs8eb9359.apps.googleusercontent.com

Please authorize access to your Earth Engine account, and paste the generated code below. If the web browser does not start, please manually browse the URL above.

Please enter authorization code: ^C
Traceback (most recent call last):
  File "/opt/conda/envs/python2/bin/earthengine", line 11, in <module>
    sys.exit(main())
  File "/opt/conda/envs/python2/lib/python2.7/site-packages/ee/cli/eecli.py", line 64, in main
    dispatcher.run(args, config)
  File "/opt/conda/envs/python2/lib/python2.7/site-packages/ee/cli/commands.py", line 252, in run
    self.command_dict[vars(args)[self.dest]].run(args, config)
  File "/opt/conda/envs/python2/lib/python2.7/site-packages/ee/cli/commands.py", line 306, in run
    auth_code = input('Please enter authorization code: ').strip()
diviningwater commented 6 years ago

Nevermind it, I solved it.