from flask import Flask, redirect, url_for, session, request, jsonify, abort
from flask_oauthlib.client import OAuth


def create_client(app):
    oauth = OAuth(app)

    dev = oauth.remote_app(
        'dev',
        consumer_key='dev',
        consumer_secret='dev',
        request_token_params={'scope': 'email'},
        base_url='http://127.0.0.1:5000/api/',
        request_token_url=None,
        access_token_method='GET',
        access_token_url='http://127.0.0.1:5000/oauth/token',
        authorize_url='http://127.0.0.1:5000/oauth/authorize'
    )

    @app.route('/')
    def index():
        if 'dev_token' in session:
            ret = dev.get('email')
            return jsonify(ret.data)
        return redirect(url_for('login'))

    @app.route('/login')
    def login():
        return dev.authorize(callback=url_for('authorized', _external=True))

    @app.route('/logout')
    def logout():
        session.pop('dev_token', None)
        return redirect(url_for('index'))

    @app.route('/authorized')
    @dev.authorized_handler
    def authorized(resp):
        if resp is None:
            return 'Access denied: error=%s' % (
                request.args['error']
            )
        if isinstance(resp, dict) and 'access_token' in resp:
            session['dev_token'] = (resp['access_token'], '')
            return jsonify(resp)
        return str(resp)

    @app.route('/address')
    def address():
        ret = dev.get('address/hangzhou')
        if ret.status not in (200, 201):
            return abort(ret.status)
        return ret.raw_data

    @app.route('/method/<name>')
    def method(name):
        func = getattr(dev, name)
        ret = func('method')
        return ret.raw_data

    @dev.tokengetter
    def get_oauth_token():
        return session.get('dev_token')

    return dev


if __name__ == '__main__':
    import os
    os.environ['DEBUG'] = 'true'
    # DEBUG=1 python oauth2_client.py
    app = Flask(__name__)
    app.debug = True
    app.secret_key = 'development'
    create_client(app)
    app.run(host='localhost', port=8000)

@@ -164,19 +164,22 @@
 p)%0A%0A    
-dev
+remote
  = oauth
@@ -645,27 +645,30 @@
       ret = 
-dev
+remote
 .get('email'
@@ -806,19 +806,22 @@
  return 
-dev
+remote
 .authori
@@ -1033,19 +1033,22 @@
 ')%0A    @
-dev
+remote
 .authori
@@ -1454,19 +1454,22 @@
   ret = 
-dev
+remote
 .get('ad
@@ -1670,19 +1670,22 @@
 getattr(
-dev
+remote
 , name)%0A
@@ -1747,19 +1747,22 @@
 a%0A%0A    @
-dev
+remote
 .tokenge
@@ -1845,19 +1845,22 @@
  return 
-dev
+remote
 %0A%0A%0Aif __

Rename for oauth2 client test