Complete the code to import the Flask-OAuthlib client.
from flask_oauthlib.client import [1]
The Flask-OAuthlib client is imported using OAuth.
Complete the code to create an OAuth object in a Flask app.
oauth = [1](app)You create an OAuth object by calling OAuth(app) passing the Flask app.
Fix the error in the OAuth remote app registration code.
google = oauth.remote_app(
'google',
consumer_key='[1]',
consumer_secret='YOUR_SECRET',
request_token_params={'scope': 'email'},
base_url='https://www.googleapis.com/oauth2/v1/',
request_token_url=None,
access_token_method='POST',
access_token_url='https://accounts.google.com/o/oauth2/token',
authorize_url='https://accounts.google.com/o/oauth2/auth'
)The consumer_key should be your Google client ID, often stored in a variable like GOOGLE_CLIENT_ID.
Fill both blanks to complete the OAuth token getter function.
@google.tokengetter def get_google_oauth_token(): return [1].get('access_token'), [2]
The tokengetter returns the access token stored in the Flask session and None for the token secret.
Fill all three blanks to complete the OAuth login route using Flask.
@app.route('/login') def login(): return [1].authorize(callback=[2]('authorized', _external=True)) @app.route('/login/authorized') def authorized(): resp = [3].authorized_response() if resp is None or resp.get('access_token') is None: return 'Access denied.' session['access_token'] = resp['access_token'] return 'You are logged in!'
The login route calls google.authorize with a callback URL generated by url_for. The authorized route uses google.authorized_response() to get the token.