23. May 2015

Flask OAuthlib Multiple Scope Values for calling Google API

Google provides myriad of APIs for invoking operations on Google App Platform. It’s possible to integrate this calls with custom app using OAuth.

One option is to write app based on Flask (Python Microframework) with OAuth support provided by Flask-OAuthlib.

There is simple example of web app in Lepture’s repo.

The key practice in OAuth world is to get user’s consent to access API on her/his behalf. Often implemented by simple consent screen.


You need to perform two steps to display consent screen:

  • enable API in Developer Console
  • define scope in your application

The second step is straightdorward:

google = oauth.remote_app(
        'scope': 'https://www.googleapis.com/auth/userinfo.email'

It works perfectly. The only problem is that this solution provides access just to one API.

The question is: How to request access to multiple scopes?

You can find many hints about OAtuh for other frameworks, that you should separate scopes by comma. That won’t work.

Correct solution is to use white space as delimiter of scopes (as suggested for HTML forms).

google = oauth.remote_app(
        'scope': 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/calendar.readonly https://www.googleapis.com/auth/tasks'

4. November 2012

Unable to build CouchDB-XO_Auth – solution

CouchDB-XO_Auth is using make and rebar to build extension for CouchDB.

If you’re using debian package for CouchDB, then you’ll probably see following error after typing make:

==> meck (get-deps)
==> CouchDB-XO_Auth (get-deps)
==> meck (compile)
==> CouchDB-XO_Auth (compile)
src/xo_auth_fb.erl:4: can't find include lib "couch/include/couch_db.hrl"
src/xo_auth.erl:11: can't find include lib "couch/include/couch_db.hrl"

The problem is in rebar configuration. It trying to locate CouchDB Erlang files inĀ /usr/local/lib/couchdb/erlang/lib/.

Default location of these files for Debian is: /usr/lib/couchdb/erlang/lib/
Solution: fix path rebar.config.

It should look like this:

%%-*- mode: erlang -*-
{deps, [
 {meck, "0.7.1", {git, "https://github.com/eproxus/meck.git", {tag, "0.7.1"}}}

Windows version how-to (manual steps):

git clone https://github.com/ocastalabs/CouchDB-XO_Auth.git
cd CouchDB-XO_Auth
mkdir deps
cd deps
git clone https://github.com/eproxus/meck.git
cd meck
git branch 0.7.1
cd ..
cd ..
escript rebar compile